Example #1
0
polypy_test.start("Polynomial Evaluation")

# polypy.trace_enable("polynomial")
# polypy.trace_enable("factorization")
# polypy.trace_enable("algebraic_number")
# polypy.trace_enable("coefficient")
# polypy.trace_enable("coefficient::sgn")
# polypy.trace_enable("coefficient::roots")
# polypy.trace_enable("coefficient::arith")

sqrt2 = polypy.AlgebraicNumber(x**2 - 2, 1)
sqrt2_4 = polypy.AlgebraicNumber(x**4 - 2, 1)
sqrt3 = polypy.AlgebraicNumber(x**2 - 3, 1)

assignment = polypy.Assignment()
assignment.set_value(x, sqrt2)
assignment.set_value(y, sqrt2_4)
assignment.set_value(z, sqrt3)

# print assignment

p = x + y + z
p_value = p.evaluate(assignment)
check_value(p, assignment, p_value, 4.335471485)

p = x**2
p_value = p.evaluate(assignment)
check_value(p, assignment, p_value, 2)

p = x**2 + y**4
Example #2
0
def lift(poly_map, vars):
    m = polypy.Assignment()
    lift_first_var(poly_map, vars, m)
Example #3
0
# polypy.trace_enable("coefficient::gcd")
# polypy.trace_enable("polynomial")
# polypy.trace_enable("coefficient")
# polypy.trace_enable("coefficient::order")
# polypy.trace_enable("coefficient::reduce")
polypy.trace_enable("coefficient::mgcd")

x0 = polypy.Variable("x0")
x1 = polypy.Variable("x1")
x2 = polypy.Variable("x2")
x3 = polypy.Variable("x3")
x4 = polypy.Variable("x4")

polypy.variable_order.set([x0, x1, x2, x3, x4])

m = polypy.Assignment()
m.set_value(x0, 2)
m.set_value(x1, 3)
m.set_value(x2, 3)
m.set_value(x3, 9)

A = (1 * x3) * x4**4 + ((-2 * x0) * x3 + (2 * x1)) * x4**3 + (
    (1 * x0**2) * x3 +
    (2 * x2 + ((-2 * x0) * x1 - 40))) * x4**2 + (80 * x0) * x4 + (-40 * x0**2)
B = A.derivative()

PSC = A.psc(B)
print "PSC =", PSC
MGCD = A.mgcd(B, m)
print "MGCD =", MGCD