def isom(A,B): # First check that A is a symmetric matrix. if not matrix(A).is_symmetric(): return False # Then check A against the viable database candidates. else: n=len(A[0]) m=len(B[0]) Avec=[] Bvec=[] for i in range(n): for j in range(i,n): if i==j: Avec+=[A[i][j]] else: Avec+=[2*A[i][j]] for i in range(m): for j in range(i,m): if i==j: Bvec+=[B[i][j]] else: Bvec+=[2*B[i][j]] Aquad=QuadraticForm(ZZ,len(A[0]),Avec) # check positive definite if Aquad.is_positive_definite(): Bquad=QuadraticForm(ZZ,len(B[0]),Bvec) return Aquad.is_globally_equivalent_to(Bquad) else: return False
def isom(A, B): # First check that A is a symmetric matrix. if not matrix(A).is_symmetric(): return False # Then check A against the viable database candidates. else: n = len(A[0]) m = len(B[0]) Avec = [] Bvec = [] for i in range(n): for j in range(i, n): if i == j: Avec += [A[i][j]] else: Avec += [2 * A[i][j]] for i in range(m): for j in range(i, m): if i == j: Bvec += [B[i][j]] else: Bvec += [2 * B[i][j]] Aquad = QuadraticForm(ZZ, len(A[0]), Avec) # check positive definite if Aquad.is_positive_definite(): Bquad = QuadraticForm(ZZ, len(B[0]), Bvec) return Aquad.is_globally_equivalent_to(Bquad) else: return False
def assert_jordan_blcs(self, p, mat): p = ZZ(p) if p == 2: blcs = jordan_blocks_2(mat) else: blcs = jordan_blocks_odd(mat, p) q = QuadraticForm(ZZ, ZZ(2) * mat) q1 = _blocks_to_quad_form(blcs.blocks, p) if p == 2: self.assertTrue((q.det() / q1.det()) % 8 == 1) else: self.assertTrue(kronecker_symbol(q.det() / q1.det(), p) == 1) self.assertEqual( q.hasse_invariant__OMeara(p), q1.hasse_invariant__OMeara(p))
def assert_jordan_blocks_method(self, p, mat): p = ZZ(p) if p == 2: blcs = jordan_blocks_2(mat) else: blcs = jordan_blocks_odd(mat, p) q = QuadraticForm(ZZ, 2 * mat) if p == 2: should1 = (q.Gram_det() / blcs.Gram_det()) % 8 else: should1 = kronecker_symbol((q.Gram_det() / blcs.Gram_det()), p) self.assertEqual(should1, 1) self.assertEqual( q.hasse_invariant__OMeara(p), blcs.hasse_invariant__OMeara()) self.assertEqual(q.dim(), blcs.dim()) self.assertEqual(q.content().valuation(p), blcs.content_order())
def QuadraticForm_from_quadric(Q): """ On input a homogeneous polynomial of degree 2 return the Quadratic Form corresponding to it. """ R = Q.parent() assert all([sum(e)==2 for e in Q.exponents()]) M = copy(zero_matrix(R.ngens(),R.ngens())) for i in range(R.ngens()): for j in range(R.ngens()): if i==j: M[i,j]=2*Q.coefficient(R.gen(i)*R.gen(j)) else: M[i,j]=Q.coefficient(R.gen(i)*R.gen(j)) return QuadraticForm(M)