Example #1
0
def test_benchmark_czichowski():
    skip('This takes too much time (without gmpy)')

    config.setup('GB_METHOD', 'f5b')
    helper_test_benchmark_czichowski()
    config.setup('GB_METHOD', 'buchberger')
    helper_test_benchmark_czichowski()
Example #2
0
def test_gf_irreducible_p():
    assert gf_irred_p_ben_or([7], 11, ZZ) == True
    assert gf_irred_p_ben_or([7,3], 11, ZZ) == True
    assert gf_irred_p_ben_or([7,3,1], 11, ZZ) == False

    assert gf_irred_p_rabin([7], 11, ZZ) == True
    assert gf_irred_p_rabin([7,3], 11, ZZ) == True
    assert gf_irred_p_rabin([7,3,1], 11, ZZ) == False

    config.setup('GF_IRRED_METHOD', 'ben-or')

    assert gf_irreducible_p([7], 11, ZZ) == True
    assert gf_irreducible_p([7,3], 11, ZZ) == True
    assert gf_irreducible_p([7,3,1], 11, ZZ) == False

    config.setup('GF_IRRED_METHOD', 'rabin')

    assert gf_irreducible_p([7], 11, ZZ) == True
    assert gf_irreducible_p([7,3], 11, ZZ) == True
    assert gf_irreducible_p([7,3,1], 11, ZZ) == False

    config.setup('GF_IRRED_METHOD', 'other')
    raises(KeyError, lambda: gf_irreducible_p([7], 11, ZZ))
    config.setup('GF_IRRED_METHOD')

    f = [1, 9,  9, 13, 16, 15,  6,  7,  7,  7, 10]
    g = [1, 7, 16,  7, 15, 13, 13, 11, 16, 10,  9]

    h = gf_mul(f, g, 17, ZZ)

    assert gf_irred_p_ben_or(f, 17, ZZ) == True
    assert gf_irred_p_ben_or(g, 17, ZZ) == True

    assert gf_irred_p_ben_or(h, 17, ZZ) == False

    assert gf_irred_p_rabin(f, 17, ZZ) == True
    assert gf_irred_p_rabin(g, 17, ZZ) == True

    assert gf_irred_p_rabin(h, 17, ZZ) == False
Example #3
0
def test_gf_irreducible_p():
    assert gf_irred_p_ben_or(ZZ.map([7]), 11, ZZ) is True
    assert gf_irred_p_ben_or(ZZ.map([7, 3]), 11, ZZ) is True
    assert gf_irred_p_ben_or(ZZ.map([7, 3, 1]), 11, ZZ) is False

    assert gf_irred_p_rabin(ZZ.map([7]), 11, ZZ) is True
    assert gf_irred_p_rabin(ZZ.map([7, 3]), 11, ZZ) is True
    assert gf_irred_p_rabin(ZZ.map([7, 3, 1]), 11, ZZ) is False

    config.setup("GF_IRRED_METHOD", "ben-or")

    assert gf_irreducible_p(ZZ.map([7]), 11, ZZ) is True
    assert gf_irreducible_p(ZZ.map([7, 3]), 11, ZZ) is True
    assert gf_irreducible_p(ZZ.map([7, 3, 1]), 11, ZZ) is False

    config.setup("GF_IRRED_METHOD", "rabin")

    assert gf_irreducible_p(ZZ.map([7]), 11, ZZ) is True
    assert gf_irreducible_p(ZZ.map([7, 3]), 11, ZZ) is True
    assert gf_irreducible_p(ZZ.map([7, 3, 1]), 11, ZZ) is False

    config.setup("GF_IRRED_METHOD", "other")
    raises(KeyError, lambda: gf_irreducible_p([7], 11, ZZ))
    config.setup("GF_IRRED_METHOD")

    f = ZZ.map([1, 9, 9, 13, 16, 15, 6, 7, 7, 7, 10])
    g = ZZ.map([1, 7, 16, 7, 15, 13, 13, 11, 16, 10, 9])

    h = gf_mul(f, g, 17, ZZ)

    assert gf_irred_p_ben_or(f, 17, ZZ) is True
    assert gf_irred_p_ben_or(g, 17, ZZ) is True

    assert gf_irred_p_ben_or(h, 17, ZZ) is False

    assert gf_irred_p_rabin(f, 17, ZZ) is True
    assert gf_irred_p_rabin(g, 17, ZZ) is True

    assert gf_irred_p_rabin(h, 17, ZZ) is False
Example #4
0
def test_gf_factor():
    assert gf_factor([], 11, ZZ) == (0, [])
    assert gf_factor([1], 11, ZZ) == (1, [])
    assert gf_factor([1,1], 11, ZZ) == (1, [([1, 1], 1)])

    assert gf_factor_sqf([], 11, ZZ) == (0, [])
    assert gf_factor_sqf([1], 11, ZZ) == (1, [])
    assert gf_factor_sqf([1,1], 11, ZZ) == (1, [[1, 1]])

    config.setup('GF_FACTOR_METHOD', 'berlekamp')

    assert gf_factor_sqf([], 11, ZZ) == (0, [])
    assert gf_factor_sqf([1], 11, ZZ) == (1, [])
    assert gf_factor_sqf([1,1], 11, ZZ) == (1, [[1, 1]])

    config.setup('GF_FACTOR_METHOD', 'zassenhaus')

    assert gf_factor_sqf([], 11, ZZ) == (0, [])
    assert gf_factor_sqf([1], 11, ZZ) == (1, [])
    assert gf_factor_sqf([1,1], 11, ZZ) == (1, [[1, 1]])

    config.setup('GF_FACTOR_METHOD', 'shoup')

    assert gf_factor_sqf([], 11, ZZ) == (0, [])
    assert gf_factor_sqf([1], 11, ZZ) == (1, [])
    assert gf_factor_sqf([1,1], 11, ZZ) == (1, [[1, 1]])

    f, p = [1,0,0,1,0], 2

    g = (1, [([1, 0], 1),
             ([1, 1], 1),
             ([1, 1, 1], 1)])

    config.setup('GF_FACTOR_METHOD', 'berlekamp')
    assert gf_factor(f, p, ZZ) == g

    config.setup('GF_FACTOR_METHOD', 'zassenhaus')
    assert gf_factor(f, p, ZZ) == g

    config.setup('GF_FACTOR_METHOD', 'shoup')
    assert gf_factor(f, p, ZZ) == g

    g = (1, [[1, 0],
             [1, 1],
             [1, 1, 1]])

    config.setup('GF_FACTOR_METHOD', 'berlekamp')
    assert gf_factor_sqf(f, p, ZZ) == g

    config.setup('GF_FACTOR_METHOD', 'zassenhaus')
    assert gf_factor_sqf(f, p, ZZ) == g

    config.setup('GF_FACTOR_METHOD', 'shoup')
    assert gf_factor_sqf(f, p, ZZ) == g

    f, p = gf_from_int_poly([1,-3,1,-3,-1,-3,1], 11), 11

    g = (1, [([1, 1], 1),
             ([1, 5, 3], 1),
             ([1, 2, 3, 4], 1)])

    config.setup('GF_FACTOR_METHOD', 'berlekamp')
    assert gf_factor(f, p, ZZ) == g

    config.setup('GF_FACTOR_METHOD', 'zassenhaus')
    assert gf_factor(f, p, ZZ) == g

    config.setup('GF_FACTOR_METHOD', 'shoup')
    assert gf_factor(f, p, ZZ) == g

    f, p = [1, 5, 8, 4], 11

    g = (1, [([1, 1], 1), ([1, 2], 2)])

    config.setup('GF_FACTOR_METHOD', 'berlekamp')
    assert gf_factor(f, p, ZZ) == g

    config.setup('GF_FACTOR_METHOD', 'zassenhaus')
    assert gf_factor(f, p, ZZ) == g

    config.setup('GF_FACTOR_METHOD', 'shoup')
    assert gf_factor(f, p, ZZ) == g

    f, p = [1, 1, 10, 1, 0, 10, 10, 10, 0, 0], 11

    g = (1, [([1, 0], 2), ([1, 9, 5], 1), ([1, 3, 0, 8, 5, 2], 1)])

    config.setup('GF_FACTOR_METHOD', 'berlekamp')
    assert gf_factor(f, p, ZZ) == g

    config.setup('GF_FACTOR_METHOD', 'zassenhaus')
    assert gf_factor(f, p, ZZ) == g

    config.setup('GF_FACTOR_METHOD', 'shoup')
    assert gf_factor(f, p, ZZ) == g

    f, p = gf_from_dict({32: 1, 0: 1}, 11, ZZ), 11

    g = (1, [([1, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 10], 1),
             ([1, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 10], 1)])

    config.setup('GF_FACTOR_METHOD', 'berlekamp')
    assert gf_factor(f, p, ZZ) == g

    config.setup('GF_FACTOR_METHOD', 'zassenhaus')
    assert gf_factor(f, p, ZZ) == g

    config.setup('GF_FACTOR_METHOD', 'shoup')
    assert gf_factor(f, p, ZZ) == g

    f, p = gf_from_dict({32: 8, 0: 5}, 11, ZZ), 11

    g = (8, [([1, 3], 1),
             ([1, 8], 1),
             ([1, 0, 9], 1),
             ([1, 2, 2], 1),
             ([1, 9, 2], 1),
             ([1, 0, 5, 0, 7], 1),
             ([1, 0, 6, 0, 7], 1),
             ([1, 0, 0, 0, 1, 0, 0, 0, 6], 1),
             ([1, 0, 0, 0, 10, 0, 0, 0, 6], 1)])

    config.setup('GF_FACTOR_METHOD', 'berlekamp')
    assert gf_factor(f, p, ZZ) == g

    config.setup('GF_FACTOR_METHOD', 'zassenhaus')
    assert gf_factor(f, p, ZZ) == g

    config.setup('GF_FACTOR_METHOD', 'shoup')
    assert gf_factor(f, p, ZZ) == g

    f, p = gf_from_dict({63: 8, 0: 5}, 11, ZZ), 11

    g = (8, [([1, 7], 1),
             ([1, 4, 5], 1),
             ([1, 6, 8, 2], 1),
             ([1, 9, 9, 2], 1),
             ([1, 0, 0, 9, 0, 0, 4], 1),
             ([1, 2, 0, 8, 4, 6, 4], 1),
             ([1, 2, 3, 8, 0, 6, 4], 1),
             ([1, 2, 6, 0, 8, 4, 4], 1),
             ([1, 3, 3, 1, 6, 8, 4], 1),
             ([1, 5, 6, 0, 8, 6, 4], 1),
             ([1, 6, 2, 7, 9, 8, 4], 1),
             ([1, 10, 4, 7, 10, 7, 4], 1),
             ([1, 10, 10, 1, 4, 9, 4], 1)])

    config.setup('GF_FACTOR_METHOD', 'berlekamp')
    assert gf_factor(f, p, ZZ) == g

    config.setup('GF_FACTOR_METHOD', 'zassenhaus')
    assert gf_factor(f, p, ZZ) == g

    config.setup('GF_FACTOR_METHOD', 'shoup')
    assert gf_factor(f, p, ZZ) == g

    # Gathen polynomials: x**n + x + 1 (mod p > 2**n * pi)

    p = ZZ(nextprime(int((2**15 * pi).evalf())))
    f = gf_from_dict({15: 1, 1: 1, 0: 1}, p, ZZ)

    assert gf_sqf_p(f, p, ZZ) == True

    g = (1, [([1, 22730, 68144], 1),
             ([1, 81553, 77449, 86810, 4724], 1),
             ([1, 86276, 56779, 14859, 31575], 1),
             ([1, 15347, 95022, 84569, 94508, 92335], 1)])

    config.setup('GF_FACTOR_METHOD', 'zassenhaus')
    assert gf_factor(f, p, ZZ) == g

    config.setup('GF_FACTOR_METHOD', 'shoup')
    assert gf_factor(f, p, ZZ) == g

    g = (1, [[1, 22730, 68144],
             [1, 81553, 77449, 86810, 4724],
             [1, 86276, 56779, 14859, 31575],
             [1, 15347, 95022, 84569, 94508, 92335]])

    config.setup('GF_FACTOR_METHOD', 'zassenhaus')
    assert gf_factor_sqf(f, p, ZZ) == g

    config.setup('GF_FACTOR_METHOD', 'shoup')
    assert gf_factor_sqf(f, p, ZZ) == g

    # Shoup polynomials: f = a_0 x**n + a_1 x**(n-1) + ... + a_n
    # (mod p > 2**(n-2) * pi), where a_n = a_{n-1}**2 + 1, a_0 = 1

    p = ZZ(nextprime(int((2**4 * pi).evalf())))
    f = [1, 2, 5, 26, 41, 39, 38]

    assert gf_sqf_p(f, p, ZZ) == True

    g = (1, [([1, 44, 26], 1),
             ([1, 11, 25, 18, 30], 1)])

    config.setup('GF_FACTOR_METHOD', 'zassenhaus')
    assert gf_factor(f, p, ZZ) == g

    config.setup('GF_FACTOR_METHOD', 'shoup')
    assert gf_factor(f, p, ZZ) == g

    g = (1, [[1, 44, 26],
             [1, 11, 25, 18, 30]])

    config.setup('GF_FACTOR_METHOD', 'zassenhaus')
    assert gf_factor_sqf(f, p, ZZ) == g

    config.setup('GF_FACTOR_METHOD', 'shoup')
    assert gf_factor_sqf(f, p, ZZ) == g

    config.setup('GF_FACTOR_METHOD', 'other')
    raises(KeyError, lambda: gf_factor([1,1], 11, ZZ))
    config.setup('GF_FACTOR_METHOD')
Example #5
0
def test_dup_zz_factor():
    R, x = ring("x", ZZ)

    assert R.dup_zz_factor(0) == (0, [])
    assert R.dup_zz_factor(7) == (7, [])
    assert R.dup_zz_factor(-7) == (-7, [])

    assert R.dup_zz_factor_sqf(0) == (0, [])
    assert R.dup_zz_factor_sqf(7) == (7, [])
    assert R.dup_zz_factor_sqf(-7) == (-7, [])

    assert R.dup_zz_factor(2*x + 4) == (2, [(x + 2, 1)])
    assert R.dup_zz_factor_sqf(2*x + 4) == (2, [x + 2])

    f = x**4 + x + 1

    for i in xrange(0, 20):
        assert R.dup_zz_factor(f) == (1, [(f, 1)])

    assert R.dup_zz_factor(x**2 + 2*x + 2) == \
        (1, [(x**2 + 2*x + 2, 1)])

    assert R.dup_zz_factor(18*x**2 + 12*x + 2) == \
        (2, [(3*x + 1, 2)])

    assert R.dup_zz_factor(-9*x**2 + 1) == \
        (-1, [(3*x - 1, 1),
              (3*x + 1, 1)])

    assert R.dup_zz_factor_sqf(-9*x**2 + 1) == \
        (-1, [3*x - 1,
              3*x + 1])

    assert R.dup_zz_factor(x**3 - 6*x**2 + 11*x - 6) == \
        (1, [(x - 3, 1),
             (x - 2, 1),
             (x - 1, 1)])

    assert R.dup_zz_factor_sqf(x**3 - 6*x**2 + 11*x - 6) == \
        (1, [x - 3,
             x - 2,
             x - 1])

    assert R.dup_zz_factor(3*x**3 + 10*x**2 + 13*x + 10) == \
        (1, [(x + 2, 1),
             (3*x**2 + 4*x + 5, 1)])

    assert R.dup_zz_factor_sqf(3*x**3 + 10*x**2 + 13*x + 10) == \
        (1, [x + 2,
             3*x**2 + 4*x + 5])

    assert R.dup_zz_factor(-x**6 + x**2) == \
        (-1, [(x - 1, 1),
              (x + 1, 1),
              (x, 2),
              (x**2 + 1, 1)])

    f = 1080*x**8 + 5184*x**7 + 2099*x**6 + 744*x**5 + 2736*x**4 - 648*x**3 + 129*x**2 - 324

    assert R.dup_zz_factor(f) == \
        (1, [(5*x**4 + 24*x**3 + 9*x**2 + 12, 1),
             (216*x**4 + 31*x**2 - 27, 1)])

    f = -29802322387695312500000000000000000000*x**25 \
      + 2980232238769531250000000000000000*x**20 \
      + 1743435859680175781250000000000*x**15 \
      + 114142894744873046875000000*x**10 \
      - 210106372833251953125*x**5 \
      + 95367431640625

    assert R.dup_zz_factor(f) == \
        (-95367431640625, [(5*x - 1, 1),
                           (100*x**2 + 10*x - 1, 2),
                           (625*x**4 + 125*x**3 + 25*x**2 + 5*x + 1, 1),
                           (10000*x**4 - 3000*x**3 + 400*x**2 - 20*x + 1, 2),
                           (10000*x**4 + 2000*x**3 + 400*x**2 + 30*x + 1, 2)])

    f = x**10 - 1

    config.setup('USE_CYCLOTOMIC_FACTOR', True)
    F_0 = R.dup_zz_factor(f)

    config.setup('USE_CYCLOTOMIC_FACTOR', False)
    F_1 = R.dup_zz_factor(f)

    assert F_0 == F_1 == \
        (1, [(x - 1, 1),
             (x + 1, 1),
             (x**4 - x**3 + x**2 - x + 1, 1),
             (x**4 + x**3 + x**2 + x + 1, 1)])

    config.setup('USE_CYCLOTOMIC_FACTOR')

    f = x**10 + 1

    config.setup('USE_CYCLOTOMIC_FACTOR', True)
    F_0 = R.dup_zz_factor(f)

    config.setup('USE_CYCLOTOMIC_FACTOR', False)
    F_1 = R.dup_zz_factor(f)

    assert F_0 == F_1 == \
        (1, [(x**2 + 1, 1),
             (x**8 - x**6 + x**4 - x**2 + 1, 1)])

    config.setup('USE_CYCLOTOMIC_FACTOR')
Example #6
0
def test_dup_zz_factor():
    R, x = ring("x", ZZ)

    assert R.dup_zz_factor(0) == (0, [])
    assert R.dup_zz_factor(7) == (7, [])
    assert R.dup_zz_factor(-7) == (-7, [])

    assert R.dup_zz_factor_sqf(0) == (0, [])
    assert R.dup_zz_factor_sqf(7) == (7, [])
    assert R.dup_zz_factor_sqf(-7) == (-7, [])

    assert R.dup_zz_factor(2*x + 4) == (2, [(x + 2, 1)])
    assert R.dup_zz_factor_sqf(2*x + 4) == (2, [x + 2])

    f = x**4 + x + 1

    for i in xrange(0, 20):
        assert R.dup_zz_factor(f) == (1, [(f, 1)])

    assert R.dup_zz_factor(x**2 + 2*x + 2) == \
        (1, [(x**2 + 2*x + 2, 1)])

    assert R.dup_zz_factor(18*x**2 + 12*x + 2) == \
        (2, [(3*x + 1, 2)])

    assert R.dup_zz_factor(-9*x**2 + 1) == \
        (-1, [(3*x - 1, 1),
              (3*x + 1, 1)])

    assert R.dup_zz_factor_sqf(-9*x**2 + 1) == \
        (-1, [3*x - 1,
              3*x + 1])

    assert R.dup_zz_factor(x**3 - 6*x**2 + 11*x - 6) == \
        (1, [(x - 3, 1),
             (x - 2, 1),
             (x - 1, 1)])

    assert R.dup_zz_factor_sqf(x**3 - 6*x**2 + 11*x - 6) == \
        (1, [x - 3,
             x - 2,
             x - 1])

    assert R.dup_zz_factor(3*x**3 + 10*x**2 + 13*x + 10) == \
        (1, [(x + 2, 1),
             (3*x**2 + 4*x + 5, 1)])

    assert R.dup_zz_factor_sqf(3*x**3 + 10*x**2 + 13*x + 10) == \
        (1, [x + 2,
             3*x**2 + 4*x + 5])

    assert R.dup_zz_factor(-x**6 + x**2) == \
        (-1, [(x - 1, 1),
              (x + 1, 1),
              (x, 2),
              (x**2 + 1, 1)])

    f = 1080*x**8 + 5184*x**7 + 2099*x**6 + 744*x**5 + 2736*x**4 - 648*x**3 + 129*x**2 - 324

    assert R.dup_zz_factor(f) == \
        (1, [(5*x**4 + 24*x**3 + 9*x**2 + 12, 1),
             (216*x**4 + 31*x**2 - 27, 1)])

    f = -29802322387695312500000000000000000000*x**25 \
      + 2980232238769531250000000000000000*x**20 \
      + 1743435859680175781250000000000*x**15 \
      + 114142894744873046875000000*x**10 \
      - 210106372833251953125*x**5 \
      + 95367431640625

    assert R.dup_zz_factor(f) == \
        (-95367431640625, [(5*x - 1, 1),
                           (100*x**2 + 10*x - 1, 2),
                           (625*x**4 + 125*x**3 + 25*x**2 + 5*x + 1, 1),
                           (10000*x**4 - 3000*x**3 + 400*x**2 - 20*x + 1, 2),
                           (10000*x**4 + 2000*x**3 + 400*x**2 + 30*x + 1, 2)])

    f = x**10 - 1

    config.setup('USE_CYCLOTOMIC_FACTOR', True)
    F_0 = R.dup_zz_factor(f)

    config.setup('USE_CYCLOTOMIC_FACTOR', False)
    F_1 = R.dup_zz_factor(f)

    assert F_0 == F_1 == \
        (1, [(x - 1, 1),
             (x + 1, 1),
             (x**4 - x**3 + x**2 - x + 1, 1),
             (x**4 + x**3 + x**2 + x + 1, 1)])

    config.setup('USE_CYCLOTOMIC_FACTOR')

    f = x**10 + 1

    config.setup('USE_CYCLOTOMIC_FACTOR', True)
    F_0 = R.dup_zz_factor(f)

    config.setup('USE_CYCLOTOMIC_FACTOR', False)
    F_1 = R.dup_zz_factor(f)

    assert F_0 == F_1 == \
        (1, [(x**2 + 1, 1),
             (x**8 - x**6 + x**4 - x**2 + 1, 1)])

    config.setup('USE_CYCLOTOMIC_FACTOR')
Example #7
0
def test_benchmark_cyclic_4():
    config.setup('GB_METHOD', 'f5b')
    helper_test_benchmark_cyclic_4()
    config.setup('GB_METHOD', 'buchberger')
    helper_test_benchmark_cyclic_4()
Example #8
0
def test_benchmark_kastura_4():
    config.setup('GB_METHOD', 'f5b')
    helper_test_benchmark_katsura_4()
    config.setup('GB_METHOD', 'buchberger')
    helper_test_benchmark_katsura_4()
Example #9
0
def test_benchmark_minpoly():
    config.setup('GB_METHOD', 'f5b')
    helper_test_benchmark_minpoly()
    config.setup('GB_METHOD', 'buchberger')
    helper_test_benchmark_minpoly()
Example #10
0
def test_sdp_groebner():
    config.setup('GB_METHOD', 'f5b')
    helper_test_sdp_groebner()
    config.setup('GB_METHOD', 'buchberger')
    helper_test_sdp_groebner()
Example #11
0
def test_dup_zz_factor():
    assert dup_zz_factor([], ZZ) == (0, [])
    assert dup_zz_factor([7], ZZ) == (7, [])
    assert dup_zz_factor([-7], ZZ) == (-7, [])

    assert dup_zz_factor_sqf([], ZZ) == (0, [])
    assert dup_zz_factor_sqf([7], ZZ) == (7, [])
    assert dup_zz_factor_sqf([-7], ZZ) == (-7, [])

    assert dup_zz_factor([2,4], ZZ) == \
        (2, [([1, 2], 1)])
    assert dup_zz_factor_sqf([2,4], ZZ) == \
        (2, [([1, 2], 1)])

    f = [1,0,0,1,1]

    for i in xrange(0, 20):
        assert dup_zz_factor(f, ZZ) == (1, [(f, 1)])

    assert dup_zz_factor([1,2,2], ZZ) == \
        (1, [([1,2,2], 1)])

    assert dup_zz_factor([18,12,2], ZZ) == \
        (2, [([3, 1], 2)])

    assert dup_zz_factor([-9,0,1], ZZ) == \
        (-1, [([3,-1], 1),
              ([3, 1], 1)])

    assert dup_zz_factor_sqf([-9,0,1], ZZ) == \
        (-1, [[3,-1],
              [3, 1]])

    assert dup_zz_factor([1,-6,11,-6], ZZ) == \
        (1, [([1,-3], 1),
             ([1,-2], 1),
             ([1,-1], 1)])

    assert dup_zz_factor_sqf([1,-6,11,-6], ZZ) == \
        (1, [[1,-3],
             [1,-2],
             [1,-1]])

    assert dup_zz_factor([3,10,13,10], ZZ) == \
        (1, [([1,2], 1),
             ([3,4,5], 1)])

    assert dup_zz_factor_sqf([3,10,13,10], ZZ) == \
        (1, [[1,2],
             [3,4,5]])

    assert dup_zz_factor([-1,0,0,0,1,0,0], ZZ) == \
        (-1, [([1,-1], 1),
              ([1, 1], 1),
              ([1, 0], 2),
              ([1, 0, 1], 1)])

    f = [1080, 5184, 2099, 744, 2736, -648, 129, 0, -324]

    assert dup_zz_factor(f, ZZ) == \
        (1, [([5, 24, 9, 0, 12], 1),
             ([216, 0, 31, 0, -27], 1)])

    f = [-29802322387695312500000000000000000000,
          0, 0, 0, 0,
          2980232238769531250000000000000000,
          0, 0, 0, 0,
          1743435859680175781250000000000,
          0, 0, 0, 0,
          114142894744873046875000000,
          0, 0, 0, 0,
          -210106372833251953125,
          0, 0, 0, 0,
          95367431640625]

    assert dup_zz_factor(f, ZZ) == \
        (-95367431640625, [([5, -1], 1),
                           ([100, 10, -1], 2),
                           ([625, 125, 25, 5, 1], 1),
                           ([10000, -3000, 400, -20, 1], 2),
                           ([10000,  2000, 400,  30, 1], 2)])

    f = dup_from_raw_dict({10:1, 0:-1}, ZZ)

    setup('USE_CYCLOTOMIC_FACTOR', True)
    F_0 = dup_zz_factor(f, ZZ)

    setup('USE_CYCLOTOMIC_FACTOR', False)
    F_1 = dup_zz_factor(f, ZZ)

    assert F_0 == F_1 == \
        (1, [([1,-1], 1),
             ([1, 1], 1),
             ([1,-1, 1,-1, 1], 1),
             ([1, 1, 1, 1, 1], 1)])

    setup('USE_CYCLOTOMIC_FACTOR')

    f = dup_from_raw_dict({10:1, 0:1}, ZZ)

    setup('USE_CYCLOTOMIC_FACTOR', True)
    F_0 = dup_zz_factor(f, ZZ)

    setup('USE_CYCLOTOMIC_FACTOR', False)
    F_1 = dup_zz_factor(f, ZZ)

    assert F_0 == F_1 == \
        (1, [([1, 0, 1], 1),
             ([1, 0, -1, 0, 1, 0, -1, 0, 1], 1)])

    setup('USE_CYCLOTOMIC_FACTOR')
Example #12
0
def test_dup_zz_factor():
    assert dup_zz_factor([], ZZ) == (0, [])
    assert dup_zz_factor([7], ZZ) == (7, [])
    assert dup_zz_factor([-7], ZZ) == (-7, [])

    assert dup_zz_factor_sqf([], ZZ) == (0, [])
    assert dup_zz_factor_sqf([7], ZZ) == (7, [])
    assert dup_zz_factor_sqf([-7], ZZ) == (-7, [])

    assert dup_zz_factor([2,4], ZZ) == \
        (2, [([1, 2], 1)])
    assert dup_zz_factor_sqf([2,4], ZZ) == \
        (2, [([1, 2], 1)])

    f = [1,0,0,1,1]

    for i in xrange(0, 20):
        assert dup_zz_factor(f, ZZ) == (1, [(f, 1)])

    assert dup_zz_factor([1,2,2], ZZ) == \
        (1, [([1,2,2], 1)])

    assert dup_zz_factor([18,12,2], ZZ) == \
        (2, [([3, 1], 2)])

    assert dup_zz_factor([-9,0,1], ZZ) == \
        (-1, [([3,-1], 1),
              ([3, 1], 1)])

    assert dup_zz_factor_sqf([-9,0,1], ZZ) == \
        (-1, [[3,-1],
              [3, 1]])

    assert dup_zz_factor([1,-6,11,-6], ZZ) == \
        (1, [([1,-3], 1),
             ([1,-2], 1),
             ([1,-1], 1)])

    assert dup_zz_factor_sqf([1,-6,11,-6], ZZ) == \
        (1, [[1,-3],
             [1,-2],
             [1,-1]])

    assert dup_zz_factor([3,10,13,10], ZZ) == \
        (1, [([1,2], 1),
             ([3,4,5], 1)])

    assert dup_zz_factor_sqf([3,10,13,10], ZZ) == \
        (1, [[1,2],
             [3,4,5]])

    assert dup_zz_factor([-1,0,0,0,1,0,0], ZZ) == \
        (-1, [([1,-1], 1),
              ([1, 1], 1),
              ([1, 0], 2),
              ([1, 0, 1], 1)])

    f = [1080, 5184, 2099, 744, 2736, -648, 129, 0, -324]

    assert dup_zz_factor(f, ZZ) == \
        (1, [([5, 24, 9, 0, 12], 1),
             ([216, 0, 31, 0, -27], 1)])

    f = [-29802322387695312500000000000000000000,
          0, 0, 0, 0,
          2980232238769531250000000000000000,
          0, 0, 0, 0,
          1743435859680175781250000000000,
          0, 0, 0, 0,
          114142894744873046875000000,
          0, 0, 0, 0,
          -210106372833251953125,
          0, 0, 0, 0,
          95367431640625]

    assert dup_zz_factor(f, ZZ) == \
        (-95367431640625, [([5, -1], 1),
                           ([100, 10, -1], 2),
                           ([625, 125, 25, 5, 1], 1),
                           ([10000, -3000, 400, -20, 1], 2),
                           ([10000,  2000, 400,  30, 1], 2)])

    f = dup_from_raw_dict({10:1, 0:-1}, ZZ)

    config.setup('USE_CYCLOTOMIC_FACTOR', True)
    F_0 = dup_zz_factor(f, ZZ)

    config.setup('USE_CYCLOTOMIC_FACTOR', False)
    F_1 = dup_zz_factor(f, ZZ)

    assert F_0 == F_1 == \
        (1, [([1,-1], 1),
             ([1, 1], 1),
             ([1,-1, 1,-1, 1], 1),
             ([1, 1, 1, 1, 1], 1)])

    config.setup('USE_CYCLOTOMIC_FACTOR')

    f = dup_from_raw_dict({10:1, 0:1}, ZZ)

    config.setup('USE_CYCLOTOMIC_FACTOR', True)
    F_0 = dup_zz_factor(f, ZZ)

    config.setup('USE_CYCLOTOMIC_FACTOR', False)
    F_1 = dup_zz_factor(f, ZZ)

    assert F_0 == F_1 == \
        (1, [([1, 0, 1], 1),
             ([1, 0, -1, 0, 1, 0, -1, 0, 1], 1)])

    config.setup('USE_CYCLOTOMIC_FACTOR')
Example #13
0
def test_benchmark_katsura3():
    setup('GB_METHOD', 'f5b')
    helper_test_benchmark_katsura_3()
    setup('GB_METHOD', 'buchberger')
    helper_test_benchmark_katsura_3()
Example #14
0
def test_benchmark_katsura3():
    config.setup('GB_METHOD', 'f5b')
    _test_benchmark_katsura_3()
    config.setup('GB_METHOD', 'buchberger')
    _test_benchmark_katsura_3()
Example #15
0
def test_benchmark_katsura3():
    config.setup('GB_METHOD', 'f5b')
    _test_benchmark_katsura_3()
    config.setup('GB_METHOD', 'buchberger')
    _test_benchmark_katsura_3()
Example #16
0
def test_benchmark_katsura3():
    setup('GB_METHOD', 'f5b')
    helper_test_benchmark_katsura_3()
    setup('GB_METHOD', 'buchberger')
    helper_test_benchmark_katsura_3()