def test_fateman_poly_F_2(): f,g,h = fateman_poly_F_2(1) F,G,H = dmp_fateman_poly_F_2(1, ZZ) assert [ t.rep.rep for t in [f,g,h] ] == [F,G,H] f,g,h = fateman_poly_F_2(3) F,G,H = dmp_fateman_poly_F_2(3, ZZ) assert [ t.rep.rep for t in [f,g,h] ] == [F,G,H]
def test_fateman_poly_F_2(): f, g, h = fateman_poly_F_2(1) F, G, H = dmp_fateman_poly_F_2(1, ZZ) assert [ t.rep.rep for t in [f, g, h] ] == [F, G, H] f, g, h = fateman_poly_F_2(3) F, G, H = dmp_fateman_poly_F_2(3, ZZ) assert [ t.rep.rep for t in [f, g, h] ] == [F, G, H]
def test_dmp_gcd(): R, x, y = ring("x,y", ZZ) f, g = 0, 0 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (0, 0, 0) f, g = 2, 0 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2, 1, 0) f, g = -2, 0 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2, -1, 0) f, g = 0, -2 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2, 0, -1) f, g = 0, 2 * x + 4 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2 * x + 4, 0, 1) f, g = 2 * x + 4, 0 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2 * x + 4, 1, 0) f, g = 2, 2 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2, 1, 1) f, g = -2, 2 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2, -1, 1) f, g = 2, -2 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2, 1, -1) f, g = -2, -2 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2, -1, -1) f, g = x**2 + 2 * x + 1, 1 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd( f, g) == (1, x**2 + 2 * x + 1, 1) f, g = x**2 + 2 * x + 1, 2 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd( f, g) == (1, x**2 + 2 * x + 1, 2) f, g = 2 * x**2 + 4 * x + 2, 2 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd( f, g) == (2, x**2 + 2 * x + 1, 1) f, g = 2, 2 * x**2 + 4 * x + 2 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd( f, g) == (2, 1, x**2 + 2 * x + 1) f, g = 2 * x**2 + 4 * x + 2, x + 1 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd( f, g) == (x + 1, 2 * x + 2, 1) f, g = x + 1, 2 * x**2 + 4 * x + 2 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd( f, g) == (x + 1, 1, 2 * x + 2) R, x, y, z, u = ring("x,y,z,u", ZZ) f, g = u**2 + 2 * u + 1, 2 * u + 2 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (u + 1, u + 1, 2) f, g = z**2 * u**2 + 2 * z**2 * u + z**2 + z * u + z, u**2 + 2 * u + 1 h, cff, cfg = u + 1, z**2 * u + z**2 + z, u + 1 assert R.dmp_zz_heu_gcd(f, g) == (h, cff, cfg) assert R.dmp_rr_prs_gcd(f, g) == (h, cff, cfg) assert R.dmp_zz_heu_gcd(g, f) == (h, cfg, cff) assert R.dmp_rr_prs_gcd(g, f) == (h, cfg, cff) R, x, y, z = ring("x,y,z", ZZ) f, g, h = map(R.from_dense, dmp_fateman_poly_F_1(2, ZZ)) H, cff, cfg = R.dmp_zz_heu_gcd(f, g) assert H == h and R.dmp_mul(H, cff) == f \ and R.dmp_mul(H, cfg) == g H, cff, cfg = R.dmp_rr_prs_gcd(f, g) assert H == h and R.dmp_mul(H, cff) == f \ and R.dmp_mul(H, cfg) == g R, x, y, z, u, v = ring("x,y,z,u,v", ZZ) f, g, h = map(R.from_dense, dmp_fateman_poly_F_1(4, ZZ)) H, cff, cfg = R.dmp_zz_heu_gcd(f, g) assert H == h and R.dmp_mul(H, cff) == f \ and R.dmp_mul(H, cfg) == g R, x, y, z, u, v, a, b = ring("x,y,z,u,v,a,b", ZZ) f, g, h = map(R.from_dense, dmp_fateman_poly_F_1(6, ZZ)) H, cff, cfg = R.dmp_zz_heu_gcd(f, g) assert H == h and R.dmp_mul(H, cff) == f \ and R.dmp_mul(H, cfg) == g R, x, y, z, u, v, a, b, c, d = ring("x,y,z,u,v,a,b,c,d", ZZ) f, g, h = map(R.from_dense, dmp_fateman_poly_F_1(8, ZZ)) H, cff, cfg = R.dmp_zz_heu_gcd(f, g) assert H == h and R.dmp_mul(H, cff) == f \ and R.dmp_mul(H, cfg) == g R, x, y, z = ring("x,y,z", ZZ) f, g, h = map(R.from_dense, dmp_fateman_poly_F_2(2, ZZ)) H, cff, cfg = R.dmp_zz_heu_gcd(f, g) assert H == h and R.dmp_mul(H, cff) == f \ and R.dmp_mul(H, cfg) == g H, cff, cfg = R.dmp_rr_prs_gcd(f, g) assert H == h and R.dmp_mul(H, cff) == f \ and R.dmp_mul(H, cfg) == g f, g, h = map(R.from_dense, dmp_fateman_poly_F_3(2, ZZ)) H, cff, cfg = R.dmp_zz_heu_gcd(f, g) assert H == h and R.dmp_mul(H, cff) == f \ and R.dmp_mul(H, cfg) == g H, cff, cfg = R.dmp_rr_prs_gcd(f, g) assert H == h and R.dmp_mul(H, cff) == f \ and R.dmp_mul(H, cfg) == g R, x, y, z, u, v = ring("x,y,z,u,v", ZZ) f, g, h = map(R.from_dense, dmp_fateman_poly_F_3(4, ZZ)) H, cff, cfg = R.dmp_inner_gcd(f, g) assert H == h and R.dmp_mul(H, cff) == f \ and R.dmp_mul(H, cfg) == g R, x, y = ring("x,y", QQ) f = QQ(1, 2) * x**2 + x + QQ(1, 2) g = QQ(1, 2) * x + QQ(1, 2) h = x + 1 assert R.dmp_qq_heu_gcd(f, g) == (h, g, QQ(1, 2)) assert R.dmp_ff_prs_gcd(f, g) == (h, g, QQ(1, 2)) R, x, y = ring("x,y", RR) f = 2.1 * x * y**2 - 2.2 * x * y + 2.1 * x g = 1.0 * x**3 assert R.dmp_ff_prs_gcd(f, g) == \ (1.0*x, 2.1*y**2 - 2.2*y + 2.1, 1.0*x**2)
def test_dmp_gcd(): assert dmp_zz_heu_gcd([[]], [[]], 1, ZZ) == ([[]], [[]], [[]]) assert dmp_rr_prs_gcd([[]], [[]], 1, ZZ) == ([[]], [[]], [[]]) assert dmp_zz_heu_gcd([[2]], [[]], 1, ZZ) == ([[2]], [[1]], [[]]) assert dmp_rr_prs_gcd([[2]], [[]], 1, ZZ) == ([[2]], [[1]], [[]]) assert dmp_zz_heu_gcd([[-2]], [[]], 1, ZZ) == ([[2]], [[-1]], [[]]) assert dmp_rr_prs_gcd([[-2]], [[]], 1, ZZ) == ([[2]], [[-1]], [[]]) assert dmp_zz_heu_gcd([[]], [[-2]], 1, ZZ) == ([[2]], [[]], [[-1]]) assert dmp_rr_prs_gcd([[]], [[-2]], 1, ZZ) == ([[2]], [[]], [[-1]]) assert dmp_zz_heu_gcd([[]], [[2], [4]], 1, ZZ) == ([[2], [4]], [[]], [[1]]) assert dmp_rr_prs_gcd([[]], [[2], [4]], 1, ZZ) == ([[2], [4]], [[]], [[1]]) assert dmp_zz_heu_gcd([[2], [4]], [[]], 1, ZZ) == ([[2], [4]], [[1]], [[]]) assert dmp_rr_prs_gcd([[2], [4]], [[]], 1, ZZ) == ([[2], [4]], [[1]], [[]]) assert dmp_zz_heu_gcd([[2]], [[2]], 1, ZZ) == ([[2]], [[1]], [[1]]) assert dmp_rr_prs_gcd([[2]], [[2]], 1, ZZ) == ([[2]], [[1]], [[1]]) assert dmp_zz_heu_gcd([[-2]], [[2]], 1, ZZ) == ([[2]], [[-1]], [[1]]) assert dmp_rr_prs_gcd([[-2]], [[2]], 1, ZZ) == ([[2]], [[-1]], [[1]]) assert dmp_zz_heu_gcd([[2]], [[-2]], 1, ZZ) == ([[2]], [[1]], [[-1]]) assert dmp_rr_prs_gcd([[2]], [[-2]], 1, ZZ) == ([[2]], [[1]], [[-1]]) assert dmp_zz_heu_gcd([[-2]], [[-2]], 1, ZZ) == ([[2]], [[-1]], [[-1]]) assert dmp_rr_prs_gcd([[-2]], [[-2]], 1, ZZ) == ([[2]], [[-1]], [[-1]]) assert dmp_zz_heu_gcd([[1], [2], [1]], [[1]], 1, ZZ) == ([[1]], [[1], [2], [1]], [[1]]) assert dmp_rr_prs_gcd([[1], [2], [1]], [[1]], 1, ZZ) == ([[1]], [[1], [2], [1]], [[1]]) assert dmp_zz_heu_gcd([[1], [2], [1]], [[2]], 1, ZZ) == ([[1]], [[1], [2], [1]], [[2]]) assert dmp_rr_prs_gcd([[1], [2], [1]], [[2]], 1, ZZ) == ([[1]], [[1], [2], [1]], [[2]]) assert dmp_zz_heu_gcd([[2], [4], [2]], [[2]], 1, ZZ) == ([[2]], [[1], [2], [1]], [[1]]) assert dmp_rr_prs_gcd([[2], [4], [2]], [[2]], 1, ZZ) == ([[2]], [[1], [2], [1]], [[1]]) assert dmp_zz_heu_gcd([[2]], [[2], [4], [2]], 1, ZZ) == ([[2]], [[1]], [[1], [2], [1]]) assert dmp_rr_prs_gcd([[2]], [[2], [4], [2]], 1, ZZ) == ([[2]], [[1]], [[1], [2], [1]]) assert dmp_zz_heu_gcd([[2], [4], [2]], [[1], [1]], 1, ZZ) == ([[1], [1]], [[2], [2]], [[1]]) assert dmp_rr_prs_gcd([[2], [4], [2]], [[1], [1]], 1, ZZ) == ([[1], [1]], [[2], [2]], [[1]]) assert dmp_zz_heu_gcd([[1], [1]], [[2], [4], [2]], 1, ZZ) == ([[1], [1]], [[1]], [[2], [2]]) assert dmp_rr_prs_gcd([[1], [1]], [[2], [4], [2]], 1, ZZ) == ([[1], [1]], [[1]], [[2], [2]]) assert dmp_zz_heu_gcd([[[[1, 2, 1]]]], [[[[2, 2]]]], 3, ZZ) == ([[[[1, 1]]]], [[[[1, 1]]]], [[[[2]]]]) assert dmp_rr_prs_gcd([[[[1, 2, 1]]]], [[[[2, 2]]]], 3, ZZ) == ([[[[1, 1]]]], [[[[1, 1]]]], [[[[2]]]]) f, g = [[[[1, 2, 1], [1, 1], []]]], [[[[1, 2, 1]]]] h, cff, cfg = [[[[1, 1]]]], [[[[1, 1], [1], []]]], [[[[1, 1]]]] assert dmp_zz_heu_gcd(f, g, 3, ZZ) == (h, cff, cfg) assert dmp_rr_prs_gcd(f, g, 3, ZZ) == (h, cff, cfg) assert dmp_zz_heu_gcd(g, f, 3, ZZ) == (h, cfg, cff) assert dmp_rr_prs_gcd(g, f, 3, ZZ) == (h, cfg, cff) f, g, h = dmp_fateman_poly_F_1(2, ZZ) H, cff, cfg = dmp_zz_heu_gcd(f, g, 2, ZZ) assert H == h and dmp_mul(H, cff, 2, ZZ) == f \ and dmp_mul(H, cfg, 2, ZZ) == g H, cff, cfg = dmp_rr_prs_gcd(f, g, 2, ZZ) assert H == h and dmp_mul(H, cff, 2, ZZ) == f \ and dmp_mul(H, cfg, 2, ZZ) == g f, g, h = dmp_fateman_poly_F_1(4, ZZ) H, cff, cfg = dmp_zz_heu_gcd(f, g, 4, ZZ) assert H == h and dmp_mul(H, cff, 4, ZZ) == f \ and dmp_mul(H, cfg, 4, ZZ) == g f, g, h = dmp_fateman_poly_F_1(6, ZZ) H, cff, cfg = dmp_zz_heu_gcd(f, g, 6, ZZ) assert H == h and dmp_mul(H, cff, 6, ZZ) == f \ and dmp_mul(H, cfg, 6, ZZ) == g f, g, h = dmp_fateman_poly_F_1(8, ZZ) H, cff, cfg = dmp_zz_heu_gcd(f, g, 8, ZZ) assert H == h and dmp_mul(H, cff, 8, ZZ) == f \ and dmp_mul(H, cfg, 8, ZZ) == g f, g, h = dmp_fateman_poly_F_2(2, ZZ) H, cff, cfg = dmp_zz_heu_gcd(f, g, 2, ZZ) assert H == h and dmp_mul(H, cff, 2, ZZ) == f \ and dmp_mul(H, cfg, 2, ZZ) == g H, cff, cfg = dmp_rr_prs_gcd(f, g, 2, ZZ) assert H == h and dmp_mul(H, cff, 2, ZZ) == f \ and dmp_mul(H, cfg, 2, ZZ) == g f, g, h = dmp_fateman_poly_F_3(2, ZZ) H, cff, cfg = dmp_zz_heu_gcd(f, g, 2, ZZ) assert H == h and dmp_mul(H, cff, 2, ZZ) == f \ and dmp_mul(H, cfg, 2, ZZ) == g H, cff, cfg = dmp_rr_prs_gcd(f, g, 2, ZZ) assert H == h and dmp_mul(H, cff, 2, ZZ) == f \ and dmp_mul(H, cfg, 2, ZZ) == g f, g, h = dmp_fateman_poly_F_3(4, ZZ) H, cff, cfg = dmp_inner_gcd(f, g, 4, ZZ) assert H == h and dmp_mul(H, cff, 4, ZZ) == f \ and dmp_mul(H, cfg, 4, ZZ) == g f = [[QQ(1, 2)], [QQ(1)], [QQ(1, 2)]] g = [[QQ(1, 2)], [QQ(1, 2)]] h = [[QQ(1)], [QQ(1)]] assert dmp_qq_heu_gcd(f, g, 1, QQ) == (h, g, [[QQ(1, 2)]]) assert dmp_ff_prs_gcd(f, g, 1, QQ) == (h, g, [[QQ(1, 2)]]) f = [[RR(2.1), RR(-2.2), RR(2.1)], []] g = [[RR(1.0)], [], [], []] assert dmp_ff_prs_gcd(f, g, 1, RR) == \ ([[RR(1.0)], []], [[RR(2.1), RR(-2.2), RR(2.1)]], [[RR(1.0)], [], []])
def test_dmp_gcd(): assert dmp_zz_heu_gcd([[]], [[]], 1, ZZ) == ([[]], [[]], [[]]) assert dmp_rr_prs_gcd([[]], [[]], 1, ZZ) == ([[]], [[]], [[]]) assert dmp_zz_heu_gcd([[2]], [[]], 1, ZZ) == ([[2]], [[1]], [[]]) assert dmp_rr_prs_gcd([[2]], [[]], 1, ZZ) == ([[2]], [[1]], [[]]) assert dmp_zz_heu_gcd([[-2]], [[]], 1, ZZ) == ([[2]], [[-1]], [[]]) assert dmp_rr_prs_gcd([[-2]], [[]], 1, ZZ) == ([[2]], [[-1]], [[]]) assert dmp_zz_heu_gcd([[]], [[-2]], 1, ZZ) == ([[2]], [[]], [[-1]]) assert dmp_rr_prs_gcd([[]], [[-2]], 1, ZZ) == ([[2]], [[]], [[-1]]) assert dmp_zz_heu_gcd([[]], [[2],[4]], 1, ZZ) == ([[2],[4]], [[]], [[1]]) assert dmp_rr_prs_gcd([[]], [[2],[4]], 1, ZZ) == ([[2],[4]], [[]], [[1]]) assert dmp_zz_heu_gcd([[2],[4]], [[]], 1, ZZ) == ([[2],[4]], [[1]], [[]]) assert dmp_rr_prs_gcd([[2],[4]], [[]], 1, ZZ) == ([[2],[4]], [[1]], [[]]) assert dmp_zz_heu_gcd([[2]], [[2]], 1, ZZ) == ([[2]], [[1]], [[1]]) assert dmp_rr_prs_gcd([[2]], [[2]], 1, ZZ) == ([[2]], [[1]], [[1]]) assert dmp_zz_heu_gcd([[-2]], [[2]], 1, ZZ) == ([[2]], [[-1]], [[1]]) assert dmp_rr_prs_gcd([[-2]], [[2]], 1, ZZ) == ([[2]], [[-1]], [[1]]) assert dmp_zz_heu_gcd([[2]], [[-2]], 1, ZZ) == ([[2]], [[1]], [[-1]]) assert dmp_rr_prs_gcd([[2]], [[-2]], 1, ZZ) == ([[2]], [[1]], [[-1]]) assert dmp_zz_heu_gcd([[-2]], [[-2]], 1, ZZ) == ([[2]], [[-1]], [[-1]]) assert dmp_rr_prs_gcd([[-2]], [[-2]], 1, ZZ) == ([[2]], [[-1]], [[-1]]) assert dmp_zz_heu_gcd([[1],[2],[1]], [[1]], 1, ZZ) == ([[1]], [[1], [2], [1]], [[1]]) assert dmp_rr_prs_gcd([[1],[2],[1]], [[1]], 1, ZZ) == ([[1]], [[1], [2], [1]], [[1]]) assert dmp_zz_heu_gcd([[1],[2],[1]], [[2]], 1, ZZ) == ([[1]], [[1], [2], [1]], [[2]]) assert dmp_rr_prs_gcd([[1],[2],[1]], [[2]], 1, ZZ) == ([[1]], [[1], [2], [1]], [[2]]) assert dmp_zz_heu_gcd([[2],[4],[2]], [[2]], 1, ZZ) == ([[2]], [[1], [2], [1]], [[1]]) assert dmp_rr_prs_gcd([[2],[4],[2]], [[2]], 1, ZZ) == ([[2]], [[1], [2], [1]], [[1]]) assert dmp_zz_heu_gcd([[2]], [[2],[4],[2]], 1, ZZ) == ([[2]], [[1]], [[1], [2], [1]]) assert dmp_rr_prs_gcd([[2]], [[2],[4],[2]], 1, ZZ) == ([[2]], [[1]], [[1], [2], [1]]) assert dmp_zz_heu_gcd([[2],[4],[2]], [[1],[1]], 1, ZZ) == ([[1], [1]], [[2], [2]], [[1]]) assert dmp_rr_prs_gcd([[2],[4],[2]], [[1],[1]], 1, ZZ) == ([[1], [1]], [[2], [2]], [[1]]) assert dmp_zz_heu_gcd([[1],[1]], [[2],[4],[2]], 1, ZZ) == ([[1], [1]], [[1]], [[2], [2]]) assert dmp_rr_prs_gcd([[1],[1]], [[2],[4],[2]], 1, ZZ) == ([[1], [1]], [[1]], [[2], [2]]) assert dmp_zz_heu_gcd([[[[1,2,1]]]], [[[[2,2]]]], 3, ZZ) == ([[[[1,1]]]], [[[[1,1]]]], [[[[2]]]]) assert dmp_rr_prs_gcd([[[[1,2,1]]]], [[[[2,2]]]], 3, ZZ) == ([[[[1,1]]]], [[[[1,1]]]], [[[[2]]]]) f, g = [[[[1,2,1],[1,1],[]]]], [[[[1,2,1]]]] h, cff, cfg = [[[[1,1]]]], [[[[1,1],[1],[]]]], [[[[1,1]]]] assert dmp_zz_heu_gcd(f, g, 3, ZZ) == (h, cff, cfg) assert dmp_rr_prs_gcd(f, g, 3, ZZ) == (h, cff, cfg) assert dmp_zz_heu_gcd(g, f, 3, ZZ) == (h, cfg, cff) assert dmp_rr_prs_gcd(g, f, 3, ZZ) == (h, cfg, cff) f, g, h = dmp_fateman_poly_F_1(2, ZZ) H, cff, cfg = dmp_zz_heu_gcd(f, g, 2, ZZ) assert H == h and dmp_mul(H, cff, 2, ZZ) == f \ and dmp_mul(H, cfg, 2, ZZ) == g H, cff, cfg = dmp_rr_prs_gcd(f, g, 2, ZZ) assert H == h and dmp_mul(H, cff, 2, ZZ) == f \ and dmp_mul(H, cfg, 2, ZZ) == g f, g, h = dmp_fateman_poly_F_1(4, ZZ) H, cff, cfg = dmp_zz_heu_gcd(f, g, 4, ZZ) assert H == h and dmp_mul(H, cff, 4, ZZ) == f \ and dmp_mul(H, cfg, 4, ZZ) == g f, g, h = dmp_fateman_poly_F_1(6, ZZ) H, cff, cfg = dmp_zz_heu_gcd(f, g, 6, ZZ) assert H == h and dmp_mul(H, cff, 6, ZZ) == f \ and dmp_mul(H, cfg, 6, ZZ) == g f, g, h = dmp_fateman_poly_F_1(8, ZZ) H, cff, cfg = dmp_zz_heu_gcd(f, g, 8, ZZ) assert H == h and dmp_mul(H, cff, 8, ZZ) == f \ and dmp_mul(H, cfg, 8, ZZ) == g f, g, h = dmp_fateman_poly_F_2(2, ZZ) H, cff, cfg = dmp_zz_heu_gcd(f, g, 2, ZZ) assert H == h and dmp_mul(H, cff, 2, ZZ) == f \ and dmp_mul(H, cfg, 2, ZZ) == g H, cff, cfg = dmp_rr_prs_gcd(f, g, 2, ZZ) assert H == h and dmp_mul(H, cff, 2, ZZ) == f \ and dmp_mul(H, cfg, 2, ZZ) == g f, g, h = dmp_fateman_poly_F_3(2, ZZ) H, cff, cfg = dmp_zz_heu_gcd(f, g, 2, ZZ) assert H == h and dmp_mul(H, cff, 2, ZZ) == f \ and dmp_mul(H, cfg, 2, ZZ) == g H, cff, cfg = dmp_rr_prs_gcd(f, g, 2, ZZ) assert H == h and dmp_mul(H, cff, 2, ZZ) == f \ and dmp_mul(H, cfg, 2, ZZ) == g f, g, h = dmp_fateman_poly_F_3(4, ZZ) H, cff, cfg = dmp_inner_gcd(f, g, 4, ZZ) assert H == h and dmp_mul(H, cff, 4, ZZ) == f \ and dmp_mul(H, cfg, 4, ZZ) == g f = [[QQ(1,2)],[QQ(1)],[QQ(1,2)]] g = [[QQ(1,2)],[QQ(1,2)]] h = [[QQ(1)],[QQ(1)]] assert dmp_qq_heu_gcd(f, g, 1, QQ) == (h, g, [[QQ(1,2)]]) assert dmp_ff_prs_gcd(f, g, 1, QQ) == (h, g, [[QQ(1,2)]])
def test_dmp_gcd(): R, x, y = ring("x,y", ZZ) f, g = 0, 0 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (0, 0, 0) f, g = 2, 0 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2, 1, 0) f, g = -2, 0 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2, -1, 0) f, g = 0, -2 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2, 0, -1) f, g = 0, 2*x + 4 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2*x + 4, 0, 1) f, g = 2*x + 4, 0 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2*x + 4, 1, 0) f, g = 2, 2 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2, 1, 1) f, g = -2, 2 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2, -1, 1) f, g = 2, -2 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2, 1, -1) f, g = -2, -2 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2, -1, -1) f, g = x**2 + 2*x + 1, 1 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (1, x**2 + 2*x + 1, 1) f, g = x**2 + 2*x + 1, 2 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (1, x**2 + 2*x + 1, 2) f, g = 2*x**2 + 4*x + 2, 2 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2, x**2 + 2*x + 1, 1) f, g = 2, 2*x**2 + 4*x + 2 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (2, 1, x**2 + 2*x + 1) f, g = 2*x**2 + 4*x + 2, x + 1 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (x + 1, 2*x + 2, 1) f, g = x + 1, 2*x**2 + 4*x + 2 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (x + 1, 1, 2*x + 2) R, x, y, z, u = ring("x,y,z,u", ZZ) f, g = u**2 + 2*u + 1, 2*u + 2 assert R.dmp_zz_heu_gcd(f, g) == R.dmp_rr_prs_gcd(f, g) == (u + 1, u + 1, 2) f, g = z**2*u**2 + 2*z**2*u + z**2 + z*u + z, u**2 + 2*u + 1 h, cff, cfg = u + 1, z**2*u + z**2 + z, u + 1 assert R.dmp_zz_heu_gcd(f, g) == (h, cff, cfg) assert R.dmp_rr_prs_gcd(f, g) == (h, cff, cfg) assert R.dmp_zz_heu_gcd(g, f) == (h, cfg, cff) assert R.dmp_rr_prs_gcd(g, f) == (h, cfg, cff) R, x, y, z = ring("x,y,z", ZZ) f, g, h = map(R.from_dense, dmp_fateman_poly_F_1(2, ZZ)) H, cff, cfg = R.dmp_zz_heu_gcd(f, g) assert H == h and R.dmp_mul(H, cff) == f \ and R.dmp_mul(H, cfg) == g H, cff, cfg = R.dmp_rr_prs_gcd(f, g) assert H == h and R.dmp_mul(H, cff) == f \ and R.dmp_mul(H, cfg) == g R, x, y, z, u, v = ring("x,y,z,u,v", ZZ) f, g, h = map(R.from_dense, dmp_fateman_poly_F_1(4, ZZ)) H, cff, cfg = R.dmp_zz_heu_gcd(f, g) assert H == h and R.dmp_mul(H, cff) == f \ and R.dmp_mul(H, cfg) == g R, x, y, z, u, v, a, b = ring("x,y,z,u,v,a,b", ZZ) f, g, h = map(R.from_dense, dmp_fateman_poly_F_1(6, ZZ)) H, cff, cfg = R.dmp_zz_heu_gcd(f, g) assert H == h and R.dmp_mul(H, cff) == f \ and R.dmp_mul(H, cfg) == g R, x, y, z, u, v, a, b, c, d = ring("x,y,z,u,v,a,b,c,d", ZZ) f, g, h = map(R.from_dense, dmp_fateman_poly_F_1(8, ZZ)) H, cff, cfg = R.dmp_zz_heu_gcd(f, g) assert H == h and R.dmp_mul(H, cff) == f \ and R.dmp_mul(H, cfg) == g R, x, y, z = ring("x,y,z", ZZ) f, g, h = map(R.from_dense, dmp_fateman_poly_F_2(2, ZZ)) H, cff, cfg = R.dmp_zz_heu_gcd(f, g) assert H == h and R.dmp_mul(H, cff) == f \ and R.dmp_mul(H, cfg) == g H, cff, cfg = R.dmp_rr_prs_gcd(f, g) assert H == h and R.dmp_mul(H, cff) == f \ and R.dmp_mul(H, cfg) == g f, g, h = map(R.from_dense, dmp_fateman_poly_F_3(2, ZZ)) H, cff, cfg = R.dmp_zz_heu_gcd(f, g) assert H == h and R.dmp_mul(H, cff) == f \ and R.dmp_mul(H, cfg) == g H, cff, cfg = R.dmp_rr_prs_gcd(f, g) assert H == h and R.dmp_mul(H, cff) == f \ and R.dmp_mul(H, cfg) == g R, x, y, z, u, v = ring("x,y,z,u,v", ZZ) f, g, h = map(R.from_dense, dmp_fateman_poly_F_3(4, ZZ)) H, cff, cfg = R.dmp_inner_gcd(f, g) assert H == h and R.dmp_mul(H, cff) == f \ and R.dmp_mul(H, cfg) == g R, x, y = ring("x,y", QQ) f = QQ(1,2)*x**2 + x + QQ(1,2) g = QQ(1,2)*x + QQ(1,2) h = x + 1 assert R.dmp_qq_heu_gcd(f, g) == (h, g, QQ(1,2)) assert R.dmp_ff_prs_gcd(f, g) == (h, g, QQ(1,2)) R, x, y = ring("x,y", RR) f = 2.1*x*y**2 - 2.2*x*y + 2.1*x g = 1.0*x**3 assert R.dmp_ff_prs_gcd(f, g) == \ (1.0*x, 2.1*y**2 - 2.2*y + 2.1, 1.0*x**2)