def test_decomp_7(): # Try working through an AlgebraicField T = Poly(x**3 + x**2 - 2 * x + 8) K = QQ.algebraic_field((T, theta)) p = 2 P = K.primes_above(p) ZK = K.maximal_order() assert len(P) == 3 assert all(Pi.e == Pi.f == 1 for Pi in P) assert prod(Pi**Pi.e for Pi in P) == p * ZK
def test_solve_triangualted(): f_1 = x**2 + y + z - 1 f_2 = x + y**2 + z - 1 f_3 = x + y + z**2 - 1 a, b = -sqrt(2) - 1, sqrt(2) - 1 assert solve_triangulated([f_1, f_2, f_3], x, y, z) == \ [(0, 0, 1), (0, 1, 0), (1, 0, 0)] dom = QQ.algebraic_field(sqrt(2)) assert solve_triangulated([f_1, f_2, f_3], x, y, z, domain=dom) == \ [(a, a, a), (0, 0, 1), (0, 1, 0), (b, b, b), (1, 0, 0)]
def test_PrimeIdeal_reduce_poly(): T = Poly(cyclotomic_poly(7, x)) k = QQ.algebraic_field((T, x)) P = k.primes_above(11) frp = P[0] B = k.integral_basis(fmt='sympy') assert [frp._reduce_poly(b, x) for b in B] == [ 1, x, x**2, -5 * x**2 - 4 * x + 1, -x**2 - x - 5, 4 * x**2 - x - 1 ] Q = k.primes_above(19) frq = Q[0] assert frq.alpha.equiv(0) assert frq._reduce_poly(20 * x**2 + 10) == x**2 - 9 raises(GeneratorsNeeded, lambda: frp._reduce_poly(S(1))) raises(NotImplementedError, lambda: frp._reduce_poly(1))
def test_round_two(): # Poly must be monic, irreducible, and over ZZ: raises(ValueError, lambda: round_two(Poly(3 * x**2 + 1))) raises(ValueError, lambda: round_two(Poly(x**2 - 1))) raises(ValueError, lambda: round_two(Poly(x**2 + QQ(1, 2)))) # Test on many fields: cases = ( # A couple of cyclotomic fields: (cyclotomic_poly(5), DomainMatrix.eye(4, QQ), 125), (cyclotomic_poly(7), DomainMatrix.eye(6, QQ), -16807), # A couple of quadratic fields (one 1 mod 4, one 3 mod 4): (x**2 - 5, DM([[1, (1, 2)], [0, (1, 2)]], QQ), 5), (x**2 - 7, DM([[1, 0], [0, 1]], QQ), 28), # Dedekind's example of a field with 2 as essential disc divisor: (x**3 + x**2 - 2 * x + 8, DM([[1, 0, 0], [0, 1, 0], [0, (1, 2), (1, 2)]], QQ).transpose(), -503), # A bunch of cubics with various forms for F -- all of these require # second or third enlargements. (Five of them require a third, while the rest require just a second.) # F = 2^2 (x**3 + 3 * x**2 - 4 * x + 4, DM([((1, 2), (1, 4), (1, 4)), (0, (1, 2), (1, 2)), (0, 0, 1)], QQ).transpose(), -83), # F = 2^2 * 3 (x**3 + 3 * x**2 + 3 * x - 3, DM([((1, 2), 0, (1, 2)), (0, 1, 0), (0, 0, 1)], QQ).transpose(), -108), # F = 2^3 (x**3 + 5 * x**2 - x + 3, DM([((1, 4), 0, (3, 4)), (0, (1, 2), (1, 2)), (0, 0, 1)], QQ).transpose(), -31), # F = 2^2 * 5 (x**3 + 5 * x**2 - 5 * x - 5, DM([((1, 2), 0, (1, 2)), (0, 1, 0), (0, 0, 1)], QQ).transpose(), 1300), # F = 3^2 (x**3 + 3 * x**2 + 5, DM([((1, 3), (1, 3), (1, 3)), (0, 1, 0), (0, 0, 1)], QQ).transpose(), -135), # F = 3^3 (x**3 + 6 * x**2 + 3 * x - 1, DM([((1, 3), (1, 3), (1, 3)), (0, 1, 0), (0, 0, 1)], QQ).transpose(), 81), # F = 2^2 * 3^2 (x**3 + 6 * x**2 + 4, DM([((1, 3), (2, 3), (1, 3)), (0, 1, 0), (0, 0, (1, 2))], QQ).transpose(), -108), # F = 2^3 * 7 (x**3 + 7 * x**2 + 7 * x - 7, DM([((1, 4), 0, (3, 4)), (0, (1, 2), (1, 2)), (0, 0, 1)], QQ).transpose(), 49), # F = 2^2 * 13 (x**3 + 7 * x**2 - x + 5, DM([((1, 2), 0, (1, 2)), (0, 1, 0), (0, 0, 1)], QQ).transpose(), -2028), # F = 2^4 (x**3 + 7 * x**2 - 5 * x + 5, DM([((1, 4), 0, (3, 4)), (0, (1, 2), (1, 2)), (0, 0, 1)], QQ).transpose(), -140), # F = 5^2 (x**3 + 4 * x**2 - 3 * x + 7, DM([((1, 5), (4, 5), (4, 5)), (0, 1, 0), (0, 0, 1)], QQ).transpose(), -175), # F = 7^2 (x**3 + 8 * x**2 + 5 * x - 1, DM([((1, 7), (6, 7), (2, 7)), (0, 1, 0), (0, 0, 1)], QQ).transpose(), 49), # F = 2 * 5 * 7 (x**3 + 8 * x**2 - 2 * x + 6, DM([(1, 0, 0), (0, 1, 0), (0, 0, 1)], QQ).transpose(), -14700), # F = 2^2 * 3 * 5 (x**3 + 6 * x**2 - 3 * x + 8, DM([(1, 0, 0), (0, (1, 4), (1, 4)), (0, 0, 1)], QQ).transpose(), -675), # F = 2 * 3^2 * 7 (x**3 + 9 * x**2 + 6 * x - 8, DM([(1, 0, 0), (0, (1, 2), (1, 2)), (0, 0, 1)], QQ).transpose(), 3969), # F = 2^2 * 3^2 * 7 (x**3 + 15 * x**2 - 9 * x + 13, DM([((1, 6), (1, 3), (1, 6)), (0, 1, 0), (0, 0, 1)], QQ).transpose(), -5292), ) for f, B_exp, d_exp in cases: K = QQ.algebraic_field((f, theta)) B = K.maximal_order().QQ_matrix d = K.discriminant() assert d == d_exp # The computed basis need not equal the expected one, but their quotient # must be unimodular: assert (B.inv() * B_exp).det()**2 == 1