Example #1
0
 def to_HNFRepresentation(self):
     """
     Transform self to the corresponding ideal as HNF representation
     """
     int_ring = self.number_field.integer_ring()
     n = self.number_field.degree
     polynomial = self.number_field.polynomial
     k = len(self.generator)
     # separate coeff and denom for generators and base
     gen_denom = reduce( gcd.lcm,
                         (self.generator[j].denom for j in range(k)) )
     gen_list = [gen_denom * self.generator[j] for j in range(k)]
     base_int, base_denom = _toIntegerMatrix(int_ring)
     
     base_alg = [BasicAlgNumber([base_int[j], 1], 
     polynomial) for j in range(1, n + 1)]
     repr_mat_list = []
     for gen in gen_list:
         for base in base_alg:
             new_gen = gen * base
             repr_mat_list.append(
                 vector.Vector([new_gen.coeff[j] for j in range(n)]))
     mat_repr = matrix.RingMatrix(n, n * k, repr_mat_list)
     new_mat_repr, numer = _toIntegerMatrix(mat_repr, 2)
     denom = gen_denom * base_denom
     denom_gcd = gcd.gcd(numer, denom)
     if denom_gcd != 1:
         denom = ring.exact_division(denom, denom_gcd)
         numer = ring.exact_division(numer, denom_gcd)
         if numer != 1:
             new_mat_repr = numer * new_mat_repr
     else:
         new_mat_repr = mat_repr
     return Ideal([new_mat_repr, denom], self.number_field)
 def testInit(self):
     b2_1 = Module([ [(5, 10), (-3, 3)], 15 ], self.Q_rt_2)
     self.assertEqual(self.b2, b2_1)
     b2_2 = Module([ matrix.RingMatrix(2, 2, 
          [vect([5, 10]), vect([-3, 3])]), 15 ], self.Q_rt_2)
     self.assertEqual(self.b2, b2_2)
     b2_3 = Module(matrix.RingMatrix(2, 2, 
         [vect([ra(1, 3), ra(2, 3)]), vect([ra(-1, 5), ra(1, 5)])]
         ), self.Q_rt_2)
     self.assertEqual(self.b2, b2_3)
     omega_base_1 = [(1, 0), (ra(-1, 2), ra(1, 2))]
     self.assertEqual(self.b5, 
         Module([ [vect([-3, 0]), vect([0, 6])], 4 ], 
         self.Q_rt_minus_3, omega_base_1))
     omega_base_2 = matrix.RingMatrix(2, 2, 
         [vect([1, 0]), vect([ra(-1, 2), ra(1, 2)])])
     self.assertEqual(self.b5, 
         Module([ [vect([-3, 0]), vect([0, 6])], 4 ], 
         self.Q_rt_minus_3, omega_base_2))