def test_dmp_quo_ground(): f = dmp_normal([[6],[2],[8]], 1, ZZ) assert dmp_quo_ground(f, ZZ(1), 1, ZZ) == f assert dmp_quo_ground(f, ZZ(2), 1, ZZ) == dmp_normal([[3],[1],[4]], 1, ZZ) assert dmp_normal(dmp_quo_ground(f, ZZ(3), 1, ZZ), 1, ZZ) == dmp_normal([[2],[],[2]], 1, ZZ)
def test_dmp_rr_div(): raises(ZeroDivisionError, lambda: dmp_rr_div([[1,2],[3]], [[]], 1, ZZ)) f = dmp_normal([[1], [], [1,0,0]], 1, ZZ) g = dmp_normal([[1], [-1,0]], 1, ZZ) q = dmp_normal([[1], [1, 0]], 1, ZZ) r = dmp_normal([[2, 0, 0]], 1, ZZ) assert dmp_rr_div(f, g, 1, ZZ) == (q, r) f = dmp_normal([[1], [], [1,0,0]], 1, ZZ) g = dmp_normal([[-1], [1,0]], 1, ZZ) q = dmp_normal([[-1], [-1, 0]], 1, ZZ) r = dmp_normal([[2, 0, 0]], 1, ZZ) assert dmp_rr_div(f, g, 1, ZZ) == (q, r) f = dmp_normal([[1], [], [1,0,0]], 1, ZZ) g = dmp_normal([[2], [-2,0]], 1, ZZ) q, r = [[]], f assert dmp_rr_div(f, g, 1, ZZ) == (q, r)
def test_dmp_ground_extract(): f = dmp_normal([[2930944], [], [2198208], [], [549552], [], [45796]], 1, ZZ) g = dmp_normal([[17585664], [], [8792832], [], [1099104], []], 1, ZZ) F = dmp_normal([[64], [], [48], [], [12], [], [1]], 1, ZZ) G = dmp_normal([[384], [], [192], [], [24], []], 1, ZZ) assert dmp_ground_extract(f, g, 1, ZZ) == (45796, F, G)
def test_dmp_permute(): f = dmp_normal([[1,0,0],[],[1,0],[],[1]], 1, ZZ) g = dmp_normal([[1,0,0,0,0],[1,0,0],[1]], 1, ZZ) assert dmp_permute(f, [0, 1], 1, ZZ) == f assert dmp_permute(g, [0, 1], 1, ZZ) == g assert dmp_permute(f, [1, 0], 1, ZZ) == g assert dmp_permute(g, [1, 0], 1, ZZ) == f
def test_dmp_swap(): f = dmp_normal([[1,0,0],[],[1,0],[],[1]], 1, ZZ) g = dmp_normal([[1,0,0,0,0],[1,0,0],[1]], 1, ZZ) assert dmp_swap(f, 1, 1, 1, ZZ) == f assert dmp_swap(f, 0, 1, 1, ZZ) == g assert dmp_swap(g, 0, 1, 1, ZZ) == f raises(IndexError, "dmp_swap(f, -1, -7, 1, ZZ)")
def test_dmp_diff(): assert dmp_diff([], 1, 0, ZZ) == [] assert dmp_diff([[]], 1, 1, ZZ) == [[]] assert dmp_diff([[[]]], 1, 2, ZZ) == [[[]]] assert dmp_diff([[[1], [2]]], 1, 2, ZZ) == [[[]]] assert dmp_diff([[[1]], [[]]], 1, 2, ZZ) == [[[1]]] assert dmp_diff([[[3]], [[1]], [[]]], 1, 2, ZZ) == [[[6]], [[1]]] assert dmp_diff([1, -1, 0, 0, 2], 1, 0, ZZ) == \ dup_diff([1, -1, 0, 0, 2], 1, ZZ) assert dmp_diff(f_6, 0, 3, ZZ) == f_6 assert dmp_diff(f_6, 1, 3, ZZ) == dmp_diff(f_6, 1, 3, ZZ) assert dmp_diff( f_6, 2, 3, ZZ) == dmp_diff(dmp_diff(f_6, 1, 3, ZZ), 1, 3, ZZ) assert dmp_diff(f_6, 3, 3, ZZ) == dmp_diff( dmp_diff(dmp_diff(f_6, 1, 3, ZZ), 1, 3, ZZ), 1, 3, ZZ) K = FF(23) F_6 = dmp_normal(f_6, 3, K) assert dmp_diff(F_6, 0, 3, K) == F_6 assert dmp_diff(F_6, 1, 3, K) == dmp_diff(F_6, 1, 3, K) assert dmp_diff(F_6, 2, 3, K) == dmp_diff(dmp_diff(F_6, 1, 3, K), 1, 3, K) assert dmp_diff(F_6, 3, 3, K) == dmp_diff( dmp_diff(dmp_diff(F_6, 1, 3, K), 1, 3, K), 1, 3, K)
def test_dmp_normal(): assert dmp_normal([[0], [], [0, 2, 1], [0], [11], []], 1, ZZ) == [ [ZZ(2), ZZ(1)], [], [ZZ(11)], [], ]
def test_dmp_diff(): assert dmp_diff([], 1, 0, ZZ) == [] assert dmp_diff([[]], 1, 1, ZZ) == [[]] assert dmp_diff([[[]]], 1, 2, ZZ) == [[[]]] assert dmp_diff([[[1], [2]]], 1, 2, ZZ) == [[[]]] assert dmp_diff([[[1]], [[]]], 1, 2, ZZ) == [[[1]]] assert dmp_diff([[[3]], [[1]], [[]]], 1, 2, ZZ) == [[[6]], [[1]]] assert dmp_diff([1, -1, 0, 0, 2], 1, 0, ZZ) == \ dup_diff([1, -1, 0, 0, 2], 1, ZZ) assert dmp_diff(f_6, 0, 3, ZZ) == f_6 assert dmp_diff(f_6, 1, 3, ZZ) == [[[[8460]], [[]]], [[[135, 0, 0], [], [], [-135, 0, 0]]], [[[]]], [[[-423]], [[-47]], [[]], [[141], [], [94, 0], []], [[]]]] assert dmp_diff(f_6, 2, 3, ZZ) == dmp_diff(dmp_diff(f_6, 1, 3, ZZ), 1, 3, ZZ) assert dmp_diff(f_6, 3, 3, ZZ) == dmp_diff( dmp_diff(dmp_diff(f_6, 1, 3, ZZ), 1, 3, ZZ), 1, 3, ZZ) K = FF(23) F_6 = dmp_normal(f_6, 3, K) assert dmp_diff(F_6, 0, 3, K) == F_6 assert dmp_diff(F_6, 1, 3, K) == dmp_diff(F_6, 1, 3, K) assert dmp_diff(F_6, 2, 3, K) == dmp_diff(dmp_diff(F_6, 1, 3, K), 1, 3, K) assert dmp_diff(F_6, 3, 3, K) == dmp_diff(dmp_diff(dmp_diff(F_6, 1, 3, K), 1, 3, K), 1, 3, K)
def test_dmp_ff_div(): raises(ZeroDivisionError, lambda: dmp_ff_div([[1,2],[3]], [[]], 1, QQ)) f = dmp_normal([[1], [], [1,0,0]], 1, QQ) g = dmp_normal([[1], [-1,0]], 1, QQ) q = [[QQ(1, 1)], [QQ(1, 1), QQ(0, 1)]] r = [[QQ(2, 1), QQ(0, 1), QQ(0, 1)]] assert dmp_ff_div(f, g, 1, QQ) == (q, r) f = dmp_normal([[1], [], [1,0,0]], 1, QQ) g = dmp_normal([[-1], [1,0]], 1, QQ) q = [[QQ(-1, 1)], [QQ(-1, 1), QQ(0, 1)]] r = [[QQ(2, 1), QQ(0, 1), QQ(0, 1)]] assert dmp_ff_div(f, g, 1, QQ) == (q, r) f = dmp_normal([[1], [], [1,0,0]], 1, QQ) g = dmp_normal([[2], [-2,0]], 1, QQ) q = [[QQ(1, 2)], [QQ(1, 2), QQ(0, 1)]] r = [[QQ(2, 1), QQ(0, 1), QQ(0, 1)]] assert dmp_ff_div(f, g, 1, QQ) == (q, r)
def test_dmp_pdiv(): f = dmp_normal([[1], [], [1,0,0]], 1, ZZ) g = dmp_normal([[1], [-1,0]], 1, ZZ) q = dmp_normal([[1], [1, 0]], 1, ZZ) r = dmp_normal([[2, 0, 0]], 1, ZZ) assert dmp_pdiv(f, g, 1, ZZ) == (q, r) assert dmp_pquo(f, g, 1, ZZ) == q assert dmp_prem(f, g, 1, ZZ) == r raises(ExactQuotientFailed, lambda: dmp_pexquo(f, g, 1, ZZ)) f = dmp_normal([[1], [], [1,0,0]], 1, ZZ) g = dmp_normal([[2], [-2,0]], 1, ZZ) q = dmp_normal([[2], [2, 0]], 1, ZZ) r = dmp_normal([[8, 0, 0]], 1, ZZ) assert dmp_pdiv(f, g, 1, ZZ) == (q, r) assert dmp_pquo(f, g, 1, ZZ) == q assert dmp_prem(f, g, 1, ZZ) == r raises(ExactQuotientFailed, lambda: dmp_pexquo(f, g, 1, ZZ))
def init_normal_DMP(rep, lev, dom): return DMP(dmp_normal(rep, lev, dom), dom, lev)
def test_dmp_subresultants(): assert dmp_resultant([[]], [[]], 1, ZZ) == [] assert dmp_prs_resultant([[]], [[]], 1, ZZ)[0] == [] assert dmp_zz_collins_resultant([[]], [[]], 1, ZZ) == [] assert dmp_qq_collins_resultant([[]], [[]], 1, ZZ) == [] assert dmp_resultant([[ZZ(1)]], [[]], 1, ZZ) == [] assert dmp_resultant([[ZZ(1)]], [[]], 1, ZZ) == [] assert dmp_resultant([[ZZ(1)]], [[]], 1, ZZ) == [] assert dmp_resultant([[]], [[ZZ(1)]], 1, ZZ) == [] assert dmp_prs_resultant([[]], [[ZZ(1)]], 1, ZZ)[0] == [] assert dmp_zz_collins_resultant([[]], [[ZZ(1)]], 1, ZZ) == [] assert dmp_qq_collins_resultant([[]], [[ZZ(1)]], 1, ZZ) == [] f = dmp_normal([[3,0],[],[-1,0,0,-4]], 1, ZZ) g = dmp_normal([[1],[1,0,0,0],[-9]], 1, ZZ) a = dmp_normal([[3,0,0,0,0],[1,0,-27,4]], 1, ZZ) b = dmp_normal([[-3,0,0,-12,1,0,-54,8,729,-216,16]], 1, ZZ) r = dmp_LC(b, ZZ) assert dmp_subresultants(f, g, 1, ZZ) == [f, g, a, b] assert dmp_resultant(f, g, 1, ZZ) == r assert dmp_prs_resultant(f, g, 1, ZZ)[0] == r assert dmp_zz_collins_resultant(f, g, 1, ZZ) == r assert dmp_qq_collins_resultant(f, g, 1, ZZ) == r f = dmp_normal([[-1],[],[],[5]], 1, ZZ) g = dmp_normal([[3,1],[],[]], 1, ZZ) a = dmp_normal([[45,30,5]], 1, ZZ) b = dmp_normal([[675,675,225,25]], 1, ZZ) r = dmp_LC(b, ZZ) assert dmp_subresultants(f, g, 1, ZZ) == [f, g, a] assert dmp_resultant(f, g, 1, ZZ) == r assert dmp_prs_resultant(f, g, 1, ZZ)[0] == r assert dmp_zz_collins_resultant(f, g, 1, ZZ) == r assert dmp_qq_collins_resultant(f, g, 1, ZZ) == r f = [[[[[6]]]], [[[[-3]]], [[[-2]], [[]]]], [[[[1]], [[]]], [[[]]]]] g = [[[[[1]]]], [[[[-1], [-1, 0]]]], [[[[1, 0], []]]]] r = [[[[1]], [[-3], [-3, 0]], [[9, 0], []]], [[[-2], [-2, 0]], [[6], [12, 0], [6, 0, 0]], [[-18, 0], [-18, 0, 0], []]], [[[4, 0], []], [[-12, 0], [-12, 0, 0], []], [[36, 0, 0], [], []]]] assert dmp_zz_collins_resultant(f, g, 4, ZZ) == r f = [[[[[QQ(1,1)]]]], [[[[QQ(-1,2)]]], [[[QQ(-1,3)]], [[]]]], [[[[QQ(1,6)]], [[]]], [[[]]]]] g = [[[[[QQ(1,1)]]]], [[[[QQ(-1,1)], [QQ(-1,1), QQ(0, 1)]]]], [[[[QQ(1,1), QQ(0,1)], []]]]] r = [[[[QQ(1,36)]], [[QQ(-1,12)], [QQ(-1,12), QQ(0,1)]], [[QQ(1,4), QQ(0,1)], []]], [[[QQ(-1,18)], [QQ(-1,18), QQ(0,1)]], [[QQ(1,6)], [QQ(1,3), QQ(0,1)], [QQ(1,6), QQ(0,1), QQ(0,1)]], [[QQ(-1,2), QQ(0,1)], [QQ(-1,2), QQ(0,1), QQ(0,1)], []]], [[[QQ(1,9), QQ(0,1)], []], [[QQ(-1,3), QQ(0,1)], [QQ(-1,3), QQ(0,1), QQ(0,1)], []], [[QQ(1,1), QQ(0,1), QQ(0,1)], [], []]]] assert dmp_qq_collins_resultant(f, g, 4, QQ) == r
def test_dmp_ground_trunc(): assert dmp_ground_trunc(f_0, ZZ(3), 2, ZZ) == \ dmp_normal( [[[1, -1, 0], [-1]], [[]], [[1, -1, 0], [1, -1, 1], [1]]], 2, ZZ)
v = dmp_add_term(u, dmp_ground(K(2), n-2), 0, n, K) f = dmp_sqr(dmp_add_term([dmp_neg(v, n-1, K)], dmp_one(n-1, K), n+1, n, K), n, K) g = dmp_sqr(dmp_add_term([v], dmp_one(n-1, K), n+1, n, K), n, K) v = dmp_add_term(u, dmp_one(n-2, K), 0, n-1, K) h = dmp_sqr(dmp_add_term([v], dmp_one(n-1, K), n+1, n, K), n, K) return dmp_mul(f, h, n, K), dmp_mul(g, h, n, K), h # A few useful polynomials from Wang's paper ('78). f_0 = dmp_normal([ [[1,2,3], [2]], [[3]], [[4,5,6], [1,2,1], [1]] ], 2, ZZ) f_1 = dmp_normal([ [[1, 0], []], [[1, 0, 1], [20, 30], [1, 10, 0]], [[1, 0], [30, 20], [1, 10, 1, 610], [20, 230, 300]], [[1, 10, 0], [30, 320, 200], [600, 6000]] ], 2, ZZ) f_2 = dmp_normal([ [[1], [1, 0], [1, 0, 0], [1, 0, 0, 0]], [[]], [[1], [1, 90], [90, 0]], [[1, -11], [], [1, -11, 0, 0]],
f = dmp_sqr( dmp_add_term([dmp_neg(v, n - 1, K)], dmp_one(n - 1, K), n + 1, n, K), n, K) g = dmp_sqr(dmp_add_term([v], dmp_one(n - 1, K), n + 1, n, K), n, K) v = dmp_add_term(u, dmp_one(n - 2, K), 0, n - 1, K) h = dmp_sqr(dmp_add_term([v], dmp_one(n - 1, K), n + 1, n, K), n, K) return dmp_mul(f, h, n, K), dmp_mul(g, h, n, K), h # A few useful polynomials from Wang's paper ('78). f_0 = dmp_normal([[[1, 2, 3], [2]], [[3]], [[4, 5, 6], [1, 2, 1], [1]]], 2, ZZ) f_1 = dmp_normal([[[1, 0], []], [[1, 0, 1], [20, 30], [1, 10, 0]], [[1, 0], [30, 20], [1, 10, 1, 610], [20, 230, 300]], [[1, 10, 0], [30, 320, 200], [600, 6000]]], 2, ZZ) f_2 = dmp_normal( [[[1], [1, 0], [1, 0, 0], [1, 0, 0, 0]], [[]], [[1], [1, 90], [90, 0]], [[1, -11], [], [1, -11, 0, 0]], [[]], [[1, -11], [90, -990]]], 2, ZZ) f_3 = dmp_normal([[[1], [], []], [[1, 0, 0, 0, 1]], [[1, 0], [], [], [1, 0]], [[1], [1, 0, 0, 0], [], [1, 0, 0, 0, 1, 0], []], [[1, 0, 0, 0, 1], [1, 0, 0, 0, 1, 1, 0, 0], []], [[1, 0], [1, 0, 0, 0, 0], []]], 2, ZZ) f_4 = dmp_normal(
def init_normal_DMF(num, den, lev, dom): return DMF(dmp_normal(num, lev, dom), dmp_normal(den, lev, dom), dom, lev)
def test_dmp_normal(): assert dmp_normal([[0],[],[0,2,1],[0],[11],[]], 1, ZZ) == \ [[ZZ(2),ZZ(1)],[],[ZZ(11)],[]]
def test_dmp_zz_wang(): p = ZZ(nextprime(dmp_zz_mignotte_bound(w_1, 2, ZZ))) assert p == ZZ(6291469) t_1, k_1, e_1 = dmp_normal([[1], []], 1, ZZ), 1, ZZ(-14) t_2, k_2, e_2 = dmp_normal([[1, 0]], 1, ZZ), 2, ZZ(3) t_3, k_3, e_3 = dmp_normal([[1], [1, 0]], 1, ZZ), 2, ZZ(-11) t_4, k_4, e_4 = dmp_normal([[1], [-1, 0]], 1, ZZ), 1, ZZ(-17) T = [t_1, t_2, t_3, t_4] K = [k_1, k_2, k_3, k_4] E = [e_1, e_2, e_3, e_4] T = zip(T, K) A = [ZZ(-14), ZZ(3)] S = dmp_eval_tail(w_1, A, 2, ZZ) cs, s = dup_primitive(S, ZZ) assert cs == 1 and s == S == \ dup_normal([1036728, 915552, 55748, 105621, -17304, -26841, -644], ZZ) assert dmp_zz_wang_non_divisors(E, cs, 4, ZZ) == [7, 3, 11, 17] assert dup_sqf_p(s, ZZ) and dup_degree(s) == dmp_degree(w_1, 2) _, H = dup_zz_factor_sqf(s, ZZ) h_1 = dup_normal([44, 42, 1], ZZ) h_2 = dup_normal([126, -9, 28], ZZ) h_3 = dup_normal([187, 0, -23], ZZ) assert H == [h_1, h_2, h_3] lc_1 = dmp_normal([[-4], [-4, 0]], 1, ZZ) lc_2 = dmp_normal([[-1, 0, 0], []], 1, ZZ) lc_3 = dmp_normal([[1], [], [-1, 0, 0]], 1, ZZ) LC = [lc_1, lc_2, lc_3] assert dmp_zz_wang_lead_coeffs(w_1, T, cs, E, H, A, 2, ZZ) == (w_1, H, LC) H_1 = [ dmp_normal(t, 0, ZZ) for t in [[44L, 42L, 1L], [126L, -9L, 28L], [187L, 0L, -23L]] ] H_2 = [ dmp_normal(t, 1, ZZ) for t in [[[-4, -12], [-3, 0], [1]], [[-9, 0], [-9], [-2, 0]], [[1, 0, -9], [], [1, -9]]] ] H_3 = [ dmp_normal(t, 1, ZZ) for t in [[[-4, -12], [-3, 0], [1]], [[-9, 0], [-9], [-2, 0]], [[1, 0, -9], [], [1, -9]]] ] c_1 = dmp_normal([-70686, -5863, -17826, 2009, 5031, 74], 0, ZZ) c_2 = dmp_normal( [[9, 12, -45, -108, -324], [18, -216, -810, 0], [2, 9, -252, -288, -945], [-30, -414, 0], [2, -54, -3, 81], [12, 0]], 1, ZZ) c_3 = dmp_normal( [[-36, -108, 0], [-27, -36, -108], [-8, -42, 0], [-6, 0, 9], [2, 0]], 1, ZZ) T_1 = [dmp_normal(t, 0, ZZ) for t in [[-3, 0], [-2], [1]]] T_2 = [dmp_normal(t, 1, ZZ) for t in [[[-1, 0], []], [[-3], []], [[-6]]]] T_3 = [dmp_normal(t, 1, ZZ) for t in [[[]], [[]], [[-1]]]] assert dmp_zz_diophantine(H_1, c_1, [], 5, p, 0, ZZ) == T_1 assert dmp_zz_diophantine(H_2, c_2, [ZZ(-14)], 5, p, 1, ZZ) == T_2 assert dmp_zz_diophantine(H_3, c_3, [ZZ(-14)], 5, p, 1, ZZ) == T_3 factors = dmp_zz_wang_hensel_lifting(w_1, H, LC, A, p, 2, ZZ) assert dmp_expand(factors, 2, ZZ) == w_1
dmp_div, dmp_rem, dmp_quo, dmp_exquo, dup_max_norm, dmp_max_norm, dup_l1_norm, dmp_l1_norm, dup_expand, dmp_expand, ) from sympy.polys.polyerrors import ( ExactQuotientFailed, ) from sympy.polys.specialpolys import f_0 from sympy.polys.domains import FF, ZZ, QQ from sympy.utilities.pytest import raises F_0 = dmp_mul_ground(dmp_normal(f_0, 2, QQ), QQ(1,7), 2, QQ) def test_dup_add_term(): f = dup_normal([], ZZ) assert dup_add_term(f, ZZ(0), 0, ZZ) == dup_normal([], ZZ) assert dup_add_term(f, ZZ(1), 0, ZZ) == dup_normal([1], ZZ) assert dup_add_term(f, ZZ(1), 1, ZZ) == dup_normal([1, 0], ZZ) assert dup_add_term(f, ZZ(1), 2, ZZ) == dup_normal([1, 0, 0], ZZ) f = dup_normal([1,1,1], ZZ) assert dup_add_term(f, ZZ(1), 0, ZZ) == dup_normal([1, 1, 2], ZZ) assert dup_add_term(f, ZZ(1), 1, ZZ) == dup_normal([1, 2, 1], ZZ) assert dup_add_term(f, ZZ(1), 2, ZZ) == dup_normal([2, 1, 1], ZZ)
def test_dmp_subresultants(): assert dmp_resultant([[]], [[]], 1, ZZ) == [] assert dmp_prs_resultant([[]], [[]], 1, ZZ)[0] == [] assert dmp_zz_collins_resultant([[]], [[]], 1, ZZ) == [] assert dmp_qq_collins_resultant([[]], [[]], 1, ZZ) == [] assert dmp_resultant([[ZZ(1)]], [[]], 1, ZZ) == [] assert dmp_resultant([[ZZ(1)]], [[]], 1, ZZ) == [] assert dmp_resultant([[ZZ(1)]], [[]], 1, ZZ) == [] assert dmp_resultant([[]], [[ZZ(1)]], 1, ZZ) == [] assert dmp_prs_resultant([[]], [[ZZ(1)]], 1, ZZ)[0] == [] assert dmp_zz_collins_resultant([[]], [[ZZ(1)]], 1, ZZ) == [] assert dmp_qq_collins_resultant([[]], [[ZZ(1)]], 1, ZZ) == [] f = dmp_normal([[3, 0], [], [-1, 0, 0, -4]], 1, ZZ) g = dmp_normal([[1], [1, 0, 0, 0], [-9]], 1, ZZ) a = dmp_normal([[3, 0, 0, 0, 0], [1, 0, -27, 4]], 1, ZZ) b = dmp_normal([[-3, 0, 0, -12, 1, 0, -54, 8, 729, -216, 16]], 1, ZZ) r = dmp_LC(b, ZZ) assert dmp_subresultants(f, g, 1, ZZ) == [f, g, a, b] assert dmp_resultant(f, g, 1, ZZ) == r assert dmp_prs_resultant(f, g, 1, ZZ)[0] == r assert dmp_zz_collins_resultant(f, g, 1, ZZ) == r assert dmp_qq_collins_resultant(f, g, 1, ZZ) == r f = dmp_normal([[-1], [], [], [5]], 1, ZZ) g = dmp_normal([[3, 1], [], []], 1, ZZ) a = dmp_normal([[45, 30, 5]], 1, ZZ) b = dmp_normal([[675, 675, 225, 25]], 1, ZZ) r = dmp_LC(b, ZZ) assert dmp_subresultants(f, g, 1, ZZ) == [f, g, a] assert dmp_resultant(f, g, 1, ZZ) == r assert dmp_prs_resultant(f, g, 1, ZZ)[0] == r assert dmp_zz_collins_resultant(f, g, 1, ZZ) == r assert dmp_qq_collins_resultant(f, g, 1, ZZ) == r f = [[[[[6]]]], [[[[-3]]], [[[-2]], [[]]]], [[[[1]], [[]]], [[[]]]]] g = [[[[[1]]]], [[[[-1], [-1, 0]]]], [[[[1, 0], []]]]] r = [[[[1]], [[-3], [-3, 0]], [[9, 0], []]], [[[-2], [-2, 0]], [[6], [12, 0], [6, 0, 0]], [[-18, 0], [-18, 0, 0], []]], [[[4, 0], []], [[-12, 0], [-12, 0, 0], []], [[36, 0, 0], [], []]]] assert dmp_zz_collins_resultant(f, g, 4, ZZ) == r f = [[[[[QQ(1, 1)]]]], [[[[QQ(-1, 2)]]], [[[QQ(-1, 3)]], [[]]]], [[[[QQ(1, 6)]], [[]]], [[[]]]]] g = [[[[[QQ(1, 1)]]]], [[[[QQ(-1, 1)], [QQ(-1, 1), QQ(0, 1)]]]], [[[[QQ(1, 1), QQ(0, 1)], []]]]] r = [[[[QQ(1, 36)]], [[QQ(-1, 12)], [QQ(-1, 12), QQ(0, 1)]], [[QQ(1, 4), QQ(0, 1)], []]], [[[QQ(-1, 18)], [QQ(-1, 18), QQ(0, 1)]], [[QQ(1, 6)], [QQ(1, 3), QQ(0, 1)], [QQ(1, 6), QQ(0, 1), QQ(0, 1)]], [[QQ(-1, 2), QQ(0, 1)], [QQ(-1, 2), QQ(0, 1), QQ(0, 1)], []]], [[[QQ(1, 9), QQ(0, 1)], []], [[QQ(-1, 3), QQ(0, 1)], [QQ(-1, 3), QQ(0, 1), QQ(0, 1)], []], [[QQ(1, 1), QQ(0, 1), QQ(0, 1)], [], []]]] assert dmp_qq_collins_resultant(f, g, 4, QQ) == r
def test_dmp_zz_wang(): p = ZZ(nextprime(dmp_zz_mignotte_bound(w_1, 2, ZZ))) assert p == ZZ(6291469) t_1, k_1, e_1 = dmp_normal([[1],[]], 1, ZZ), 1, ZZ(-14) t_2, k_2, e_2 = dmp_normal([[1, 0]], 1, ZZ), 2, ZZ(3) t_3, k_3, e_3 = dmp_normal([[1],[ 1, 0]], 1, ZZ), 2, ZZ(-11) t_4, k_4, e_4 = dmp_normal([[1],[-1, 0]], 1, ZZ), 1, ZZ(-17) T = [t_1, t_2, t_3, t_4] K = [k_1, k_2, k_3, k_4] E = [e_1, e_2, e_3, e_4] T = zip(T, K) A = [ZZ(-14), ZZ(3)] S = dmp_eval_tail(w_1, A, 2, ZZ) cs, s = dup_primitive(S, ZZ) assert cs == 1 and s == S == \ dup_normal([1036728, 915552, 55748, 105621, -17304, -26841, -644], ZZ) assert dmp_zz_wang_non_divisors(E, cs, 4, ZZ) == [7, 3, 11, 17] assert dup_sqf_p(s, ZZ) and dup_degree(s) == dmp_degree(w_1, 2) _, H = dup_zz_factor_sqf(s, ZZ) h_1 = dup_normal([44, 42, 1], ZZ) h_2 = dup_normal([126, -9, 28], ZZ) h_3 = dup_normal([187, 0, -23], ZZ) assert H == [h_1, h_2, h_3] lc_1 = dmp_normal([[-4], [-4,0]], 1, ZZ) lc_2 = dmp_normal([[-1,0,0], []], 1, ZZ) lc_3 = dmp_normal([[1], [], [-1,0,0]], 1, ZZ) LC = [lc_1, lc_2, lc_3] assert dmp_zz_wang_lead_coeffs(w_1, T, cs, E, H, A, 2, ZZ) == (w_1, H, LC) H_1 = [ dmp_normal(t, 0, ZZ) for t in [[44L,42L,1L],[126L,-9L,28L],[187L,0L,-23L]] ] H_2 = [ dmp_normal(t, 1, ZZ) for t in [[[-4,-12],[-3,0],[1]],[[-9,0],[-9],[-2,0]],[[1,0,-9],[],[1,-9]]] ] H_3 = [ dmp_normal(t, 1, ZZ) for t in [[[-4,-12],[-3,0],[1]],[[-9,0],[-9],[-2,0]],[[1,0,-9],[],[1,-9]]] ] c_1 = dmp_normal([-70686,-5863,-17826,2009,5031,74], 0, ZZ) c_2 = dmp_normal([[9,12,-45,-108,-324],[18,-216,-810,0],[2,9,-252,-288,-945],[-30,-414,0],[2,-54,-3,81],[12,0]], 1, ZZ) c_3 = dmp_normal([[-36,-108,0],[-27,-36,-108],[-8,-42,0],[-6,0,9],[2,0]], 1, ZZ) T_1 = [ dmp_normal(t, 0, ZZ) for t in [[-3,0],[-2],[1]] ] T_2 = [ dmp_normal(t, 1, ZZ) for t in [[[-1,0],[]],[[-3],[]],[[-6]]] ] T_3 = [ dmp_normal(t, 1, ZZ) for t in [[[]],[[]],[[-1]]] ] assert dmp_zz_diophantine(H_1, c_1, [], 5, p, 0, ZZ) == T_1 assert dmp_zz_diophantine(H_2, c_2, [ZZ(-14)], 5, p, 1, ZZ) == T_2 assert dmp_zz_diophantine(H_3, c_3, [ZZ(-14)], 5, p, 1, ZZ) == T_3 factors = dmp_zz_wang_hensel_lifting(w_1, H, LC, A, p, 2, ZZ) assert dmp_expand(factors, 2, ZZ) == w_1