def dmp_zz_wang_test_points(f, T, ct, A, u, K): """Wang/EEZ: Test evaluation points for suitability. """ if not dmp_eval_tail(dmp_LC(f, K), A, u - 1, K): raise EvaluationFailed('no luck') g = dmp_eval_tail(f, A, u, K) if not dup_sqf_p(g, K): raise EvaluationFailed('no luck') c, h = dup_primitive(g, K) if K.is_negative(dup_LC(h, K)): c, h = -c, dup_neg(h, K) v = u - 1 E = [dmp_eval_tail(t, A, v, K) for t, _ in T] D = dmp_zz_wang_non_divisors(E, c, ct, K) if D is not None: return c, h, E else: raise EvaluationFailed('no luck')
def dmp_zz_wang_test_points(f, T, ct, A, u, K): """Wang/EEZ: Test evaluation points for suitability. """ if not dmp_eval_tail(dmp_LC(f, K), A, u-1, K): raise EvaluationFailed('no luck') g = dmp_eval_tail(f, A, u, K) if not dup_sqf_p(g, K): raise EvaluationFailed('no luck') c, h = dup_primitive(g, K) if K.is_negative(dup_LC(h, K)): c, h = -c, dup_neg(h, K) v = u-1 E = [ dmp_eval_tail(t, A, v, K) for t, _ in T ] D = dmp_zz_wang_non_divisors(E, c, ct, K) if D is not None: return c, h, E else: raise EvaluationFailed('no luck')
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
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