def solve(self): self.left = self.left - self.right print("TESTING self.left " + str(self.left)) if self.left.countOfVariables() == 1: self.right = Polynomial.Polymial() self.right += Polynomial.Monomial(0, "", 1) actEquation = self.left if actEquation.degree() == 1: _tempCalcResult = 0 _tempMon = Polynomial.Monomial(0, actEquation.getVariableSymbol(), 1) print("TESTING symbol " + actEquation.getVariableSymbol()) for mon in actEquation.monomials: if mon.symbol == "" and mon.scalar != 0: self.left -= mon self.right += mon elif mon.symbol == actEquation.getVariableSymbol(): _tempMon = mon if _tempMon.scalar != 0: _tempCalcResult /= _tempMon.scalar self.left -= Polynomial.Monomial(_tempMon.scalar - 1, _tempMon.symbol, 1) print(self.left) self.right += Polynomial.Monomial(_tempCalcResult, "", 1) print(self.right) else: print("Error: monomial with variable not found") return -1
def __helperSolve(p, q, degree): if degree == 0: c = q.getLeadingCoefficient() / p.getLeadingCoefficient() pn = c * p if pn == q: return Pol.Polynomial([c]) else: return None a = p.getLeadingCoefficient() b = q.getLeadingCoefficient() y_lc = b / a mon = Pol.Monomial(degree, y_lc) qn = q + (-mon.differentiate()) + (-p * mon) deg = qn.degree - p.degree if deg < 0: return None #Ansatz: y=a_l *x^l+a_(l-1)*x^(l-1)+...+a_0, l=deg s = __helperSolve(p, qn, deg) #s = __helperSolve(p, qn, degree-1) if s == None: return None else: return s + mon
def getFinalNumeratorEquation(f, g, fieldTower): (a, b, c) = getNumeratorEquation(f, g) k = a.lowestDegree T_pk = Pol.Monomial(k, Rational(1, 1), fieldTower=fieldTower) a = a / T_pk b = b / T_pk c = c / T_pk return (a, b, c)
def parseField0PolyFromStr(poly_raw, var="x"): monomials = poly_raw.split("+") poly = Pol.Polynomial() for mon in monomials: if len(mon) == 0: continue l = mon.split("**") i = complex(0, 1) power = 0 if (len(l) > 1): power = eval(l[1]) elif l[0].endswith(var): power = 1 coeff_raw = l[0].strip(var).strip("*") coeff = 1 if len(coeff_raw) != 0: coeff = eval(coeff_raw) poly += Pol.Monomial(power, coeff) return poly
import Polynomial as Polymonial import Equation as Equation mono_1 = Polymonial.Monomial(2, "x", 1) print(mono_1) mono_2 = Polymonial.Monomial(3, "x", 1) print(mono_2) mono_3 = Polymonial.Monomial(1, "x", 2) print(mono_3) mono_4 = mono_1 + mono_2 print(mono_4) poly_1 = mono_3 + mono_2 print(poly_1) poly_2 = mono_3 + mono_1 print(poly_2) poly_3 = poly_1 + poly_2 print(poly_3) poly_4 = poly_3 - poly_1 print(poly_4) poly_5 = poly_4 + 5 print(poly_5) poly_6 = poly_5 + Polymonial.Monomial(1, "x", 3) print(poly_6) poly_7 = mono_4 + 15 print(poly_7) poly_8 = mono_1 - 23 print(poly_8) #eq_1 = Equation.Equation(poly_7,poly_8) #print(eq_1) #eq_1.solve()