def test_zzx_primitive():
    assert zzx_primitive([]) == (0, [])
    assert zzx_primitive([1]) == (1, [1])
    assert zzx_primitive([1,1]) == (1, [1,1])
    assert zzx_primitive([2,2]) == (2, [1,1])
    assert zzx_primitive([1,2,1]) == (1, [1,2,1])
    assert zzx_primitive([2,4,2]) == (2, [1,2,1])
Exemple #2
0
def test_zzx_primitive():
    assert zzx_primitive([]) == (0, [])
    assert zzx_primitive([1]) == (1, [1])
    assert zzx_primitive([1, 1]) == (1, [1, 1])
    assert zzx_primitive([2, 2]) == (2, [1, 1])
    assert zzx_primitive([1, 2, 1]) == (1, [1, 2, 1])
    assert zzx_primitive([2, 4, 2]) == (2, [1, 2, 1])
def test_zzX_wang():
    f = zzX_from_poly(W_1)
    p = nextprime(zzX_mignotte_bound(f))

    assert p == 6291469

    V_1, k_1, E_1 = [[1],[]], 1, -14
    V_2, k_2, E_2 = [[1, 0]], 2, 3
    V_3, k_3, E_3 = [[1],[ 1, 0]], 2, -11
    V_4, k_4, E_4 = [[1],[-1, 0]], 1, -17

    V = [V_1, V_2, V_3, V_4]
    K = [k_1, k_2, k_3, k_4]
    E = [E_1, E_2, E_3, E_4]

    V = zip(V, K)

    A = [-14, 3]

    U = zzX_eval_list(f, A)
    cu, u = zzx_primitive(U)

    assert cu == 1 and u == U == \
        [1036728, 915552, 55748, 105621, -17304, -26841, -644]

    assert zzX_wang_non_divisors(E, cu, 4) == [7, 3, 11, 17]
    assert zzx_sqf_p(u) and zzx_degree(u) == zzX_degree(f)

    _, H = zzx_factor_sqf(u)

    h_1 = [44,  42,   1]
    h_2 = [126, -9,  28]
    h_3 = [187,  0, -23]

    assert H == [h_1, h_2, h_3]

    LC_1 = [[-4], [-4,0]]
    LC_2 = [[-1,0,0], []]
    LC_3 = [[1], [], [-1,0,0]]

    LC = [LC_1, LC_2, LC_3]

    assert zzX_wang_lead_coeffs(f, V, cu, E, H, A) == (f, H, LC)

    H_1 = [[44L, 42L, 1L], [126L, -9L, 28L], [187L, 0L, -23L]]
    C_1 = [-70686, -5863, -17826, 2009, 5031, 74]

    H_2 = [[[-4, -12], [-3, 0], [1]], [[-9, 0], [-9], [-2, 0]], [[1, 0, -9], [], [1, -9]]]
    C_2 = [[9, 12, -45, -108, -324], [18, -216, -810, 0], [2, 9, -252, -288, -945], [-30, -414, 0], [2, -54, -3, 81], [12, 0]]

    H_3 = [[[-4, -12], [-3, 0], [1]], [[-9, 0], [-9], [-2, 0]], [[1, 0, -9], [], [1, -9]]]
    C_3 = [[-36, -108, 0], [-27, -36, -108], [-8, -42, 0], [-6, 0, 9], [2, 0]]

    T_1 = [[-3, 0], [-2], [1]]
    T_2 = [[[-1, 0], []], [[-3], []], [[-6]]]
    T_3 = [[[]], [[]], [[-1]]]

    assert zzX_diophantine(H_1, C_1,    [], 5, p) == T_1
    assert zzX_diophantine(H_2, C_2, [-14], 5, p) == T_2
    assert zzX_diophantine(H_3, C_3, [-14], 5, p) == T_3

    factors = zzX_wang_hensel_lifting(f, H, LC, A, p)

    f_1 = zzX_to_poly(factors[0], x, y, z)
    f_2 = zzX_to_poly(factors[1], x, y, z)
    f_3 = zzX_to_poly(factors[2], x, y, z)

    assert f_1 == -(4*(y + z)*x**2 + x*y*z - 1).as_poly(x, y, z)
    assert f_2 == -(y*z**2*x**2 + 3*x*z + 2*y).as_poly(x, y, z)
    assert f_3 ==  ((y**2 - z**2)*x**2 + y - z**2).as_poly(x, y, z)

    assert f_1*f_2*f_3 == W_1
Exemple #4
0
def test_zzX_wang():
    f = zzX_from_poly(W_1)
    p = nextprime(zzX_mignotte_bound(f))

    assert p == 6291469

    V_1, k_1, E_1 = [[1], []], 1, -14
    V_2, k_2, E_2 = [[1, 0]], 2, 3
    V_3, k_3, E_3 = [[1], [1, 0]], 2, -11
    V_4, k_4, E_4 = [[1], [-1, 0]], 1, -17

    V = [V_1, V_2, V_3, V_4]
    K = [k_1, k_2, k_3, k_4]
    E = [E_1, E_2, E_3, E_4]

    V = zip(V, K)

    A = [-14, 3]

    U = zzX_eval_list(f, A)
    cu, u = zzx_primitive(U)

    assert cu == 1 and u == U == \
        [1036728, 915552, 55748, 105621, -17304, -26841, -644]

    assert zzX_wang_non_divisors(E, cu, 4) == [7, 3, 11, 17]
    assert zzx_sqf_p(u) and zzx_degree(u) == zzX_degree(f)

    _, H = zzx_factor_sqf(u)

    h_1 = [44, 42, 1]
    h_2 = [126, -9, 28]
    h_3 = [187, 0, -23]

    assert H == [h_1, h_2, h_3]

    LC_1 = [[-4], [-4, 0]]
    LC_2 = [[-1, 0, 0], []]
    LC_3 = [[1], [], [-1, 0, 0]]

    LC = [LC_1, LC_2, LC_3]

    assert zzX_wang_lead_coeffs(f, V, cu, E, H, A) == (f, H, LC)

    H_1 = [[44L, 42L, 1L], [126L, -9L, 28L], [187L, 0L, -23L]]
    C_1 = [-70686, -5863, -17826, 2009, 5031, 74]

    H_2 = [[[-4, -12], [-3, 0], [1]], [[-9, 0], [-9], [-2, 0]],
           [[1, 0, -9], [], [1, -9]]]
    C_2 = [[9, 12, -45, -108, -324], [18, -216, -810, 0],
           [2, 9, -252, -288, -945], [-30, -414, 0], [2, -54, -3, 81], [12, 0]]

    H_3 = [[[-4, -12], [-3, 0], [1]], [[-9, 0], [-9], [-2, 0]],
           [[1, 0, -9], [], [1, -9]]]
    C_3 = [[-36, -108, 0], [-27, -36, -108], [-8, -42, 0], [-6, 0, 9], [2, 0]]

    T_1 = [[-3, 0], [-2], [1]]
    T_2 = [[[-1, 0], []], [[-3], []], [[-6]]]
    T_3 = [[[]], [[]], [[-1]]]

    assert zzX_diophantine(H_1, C_1, [], 5, p) == T_1
    assert zzX_diophantine(H_2, C_2, [-14], 5, p) == T_2
    assert zzX_diophantine(H_3, C_3, [-14], 5, p) == T_3

    factors = zzX_wang_hensel_lifting(f, H, LC, A, p)

    f_1 = zzX_to_poly(factors[0], x, y, z)
    f_2 = zzX_to_poly(factors[1], x, y, z)
    f_3 = zzX_to_poly(factors[2], x, y, z)

    assert f_1 == -(4 * (y + z) * x**2 + x * y * z - 1).as_poly(x, y, z)
    assert f_2 == -(y * z**2 * x**2 + 3 * x * z + 2 * y).as_poly(x, y, z)
    assert f_3 == ((y**2 - z**2) * x**2 + y - z**2).as_poly(x, y, z)

    assert f_1 * f_2 * f_3 == W_1