def test_poly_gcdex(): f = x**4 - 2*x**3 - 6*x**2 + 12*x + 15 g = x**3 + x**2 - 4*x - 4 assert poly_half_gcdex(f, g, x) == \ (Poly(-x/5+Rational(3,5), x), Poly(x+1, x)) assert poly_half_gcdex(Poly(f, x), Poly(g, x)) == \ (Poly(-x/5+Rational(3,5), x), Poly(x+1, x)) assert poly_gcdex(f, g, x) == \ (Poly(-x/5+Rational(3,5), x), Poly(x**2/5-6*x/5+2, x), Poly(x+1, x)) assert poly_gcdex(Poly(f, x), Poly(g, x)) == \ (Poly(-x/5+Rational(3,5), x), Poly(x**2/5-6*x/5+2, x), Poly(x+1, x)) f = x**4 + 4*x**3 - x + 1 g = x**3 - x + 1 s, t, h = poly_gcdex(f, g, x) S, T, H = poly_gcdex(g, f, x) assert s*f + t*g == h assert S*g + T*f == H assert poly_gcdex(2*x, x**2-16, x) == \ (Poly(x/32, x), Poly(-Rational(1,16), x), Poly(1, x))
def test_poly_gcdex(): f = x**4 - 2*x**3 - 6*x**2 + 12*x + 15 g = x**3 + x**2 - 4*x - 4 assert poly_half_gcdex(f, g, x) == \ (Poly(-x+3, x), Poly(5*x+5, x)) assert poly_half_gcdex(Poly(f, x), Poly(g, x)) == \ (Poly(-x+3, x), Poly(5*x+5, x)) assert poly_gcdex(f, g, x) == \ (Poly(-x+3, x), Poly(x**2-6*x+10, x), Poly(5*x+5, x)) assert poly_gcdex(Poly(f, x), Poly(g, x)) == \ (Poly(-x+3, x), Poly(x**2-6*x+10, x), Poly(5*x+5, x)) f = x**4 + 4*x**3 - x + 1 g = x**3 - x + 1 s, t, h = poly_gcdex(f, g, x) S, T, H = poly_gcdex(g, f, x) assert s*f + t*g == h assert S*g + T*f == H
def test_poly_gcdex(): f = x**4 - 2 * x**3 - 6 * x**2 + 12 * x + 15 g = x**3 + x**2 - 4 * x - 4 assert poly_half_gcdex(f, g, x) == \ (Poly(-x+3, x), Poly(5*x+5, x)) assert poly_half_gcdex(Poly(f, x), Poly(g, x)) == \ (Poly(-x+3, x), Poly(5*x+5, x)) assert poly_gcdex(f, g, x) == \ (Poly(-x+3, x), Poly(x**2-6*x+10, x), Poly(5*x+5, x)) assert poly_gcdex(Poly(f, x), Poly(g, x)) == \ (Poly(-x+3, x), Poly(x**2-6*x+10, x), Poly(5*x+5, x)) f = x**4 + 4 * x**3 - x + 1 g = x**3 - x + 1 s, t, h = poly_gcdex(f, g, x) S, T, H = poly_gcdex(g, f, x) assert s * f + t * g == h assert S * g + T * f == H
def log_to_atan(f, g): """Convert complex logarithms to real arctangents. Given a real field K and polynomials f and g in K[x], with g != 0, returns a sum h of arctangents of polynomials in K[x], such that: df d f + I g -- = -- I log( ------- ) dx dx f - I g """ if f.degree < g.degree: f, g = -g, f p, q = poly_div(f, g) if q.is_zero: return 2*atan(p.as_basic()) else: s, t, h = poly_gcdex(g, -f) A = 2*atan(quo(f*s+g*t, h)) return A + log_to_atan(s, t)