def test_Module_submodule_from_gens(): T = Poly(cyclotomic_poly(5, x)) A = PowerBasis(T) gens = [2 * A(0), 2 * A(1), 6 * A(0), 6 * A(1)] B = A.submodule_from_gens(gens) # Because the 3rd and 4th generators do not add anything new, we expect # the cols of the matrix of B to just reproduce the first two gens: M = gens[0].column().hstack(gens[1].column()) assert B.matrix == M # At least one generator must be provided: raises(ValueError, lambda: A.submodule_from_gens([])) # All generators must belong to A: raises(ValueError, lambda: A.submodule_from_gens([3 * A(0), B(0)]))
def test_Submodule_add(): T = Poly(cyclotomic_poly(5, x)) A = PowerBasis(T) B = A.submodule_from_matrix(DomainMatrix([ [4, 0, 0, 0], [0, 4, 0, 0], ], (2, 4), ZZ).transpose(), denom=6) C = A.submodule_from_matrix(DomainMatrix([ [0, 10, 0, 0], [0, 0, 7, 0], ], (2, 4), ZZ).transpose(), denom=15) D = A.submodule_from_matrix(DomainMatrix([ [20, 0, 0, 0], [0, 20, 0, 0], [0, 0, 14, 0], ], (3, 4), ZZ).transpose(), denom=30) assert B + C == D U = Poly(cyclotomic_poly(7, x)) Z = PowerBasis(U) Y = Z.submodule_from_gens([Z(0), Z(1)]) raises(TypeError, lambda: B + Y)
def test_ModuleElement_mod(): T = Poly(cyclotomic_poly(5, x)) A = PowerBasis(T) e = A(to_col([1, 15, 8, 0]), denom=2) assert e % 7 == A(to_col([1, 1, 8, 0]), denom=2) assert e % QQ(1, 2) == A.zero() assert e % QQ(1, 3) == A(to_col([1, 1, 0, 0]), denom=6) B = A.submodule_from_gens([A(0), 5 * A(1), 3 * A(2), A(3)]) assert e % B == A(to_col([1, 5, 2, 0]), denom=2) C = B.whole_submodule() raises(TypeError, lambda: e % C)