Exemple #1
0
 def change_base_module(self, other_base):
     """
     change base_module to other_base_module
     (i.e. represent with respect to base_module)
     """
     if self.base == other_base:
         return self
     n = self.number_field.degree
     if isinstance(other_base, list):
         other_base = matrix.FieldSquareMatrix(n,
             [vector.Vector(other_base[i]) for i in range(n)])
     else: # matrix repr
         other_base = other_base.copy()
     tr_base_mat, tr_base_denom = _toIntegerMatrix(
         other_base.inverse(self.base))
     denom = tr_base_denom * self.denominator
     mat_repr, numer = _toIntegerMatrix(
         tr_base_mat * self.mat_repr, 2)
     d = gcd.gcd(denom, numer)
     if d != 1:
         denom = ring.exact_division(denom, d)
         numer = ring.exact_division(numer, d)
     if numer != 1:
         mat_repr = numer * mat_repr
     return self.__class__([mat_repr, denom], self.number_field, other_base)
Exemple #2
0
 def __init__(self, pair_mat_repr, number_field, base=None, ishnf=False):
     """
     pair_mat_repr: generators represented with respect to base_module
                    1: [[deg(number_field))-integral tuple/vector], denominator]
                    2: [integral matrix whose the number of row is deg(number_field), 
                           denominator]
                    3: rational matrix whose the number of row is deg(number_field)
     number_field:  an instance of NumberField
     base:          a base module represented with respect to Z[theta]
                    1: [deg(number_field)-rational tuple/vector], which represents basis
                    2: deg(number_field)-square non-singular rational matrix
     ishnf:         if hnf_repr is already HNF-form, set True
     """
     self.number_field = number_field
     size = self.number_field.degree
     if isinstance(base, bool):
         ishnf = base
         base = None
     if base == None: # power basis
         self.base = matrix.unitMatrix(size, rational.theIntegerRing)
         self.base.toFieldMatrix()
     elif isinstance(base, list): # list repr
         self.base = matrix.FieldSquareMatrix(size, base)
     else: # matrix repr
         if base.row != size:
             raise TypeError("The number of row of base is incorrect.")
         self.base = base.copy()
         self.base.toFieldMatrix()
     if not isinstance(pair_mat_repr, list): #rational matrix repr
         self.mat_repr, self.denominator = _toIntegerMatrix(
             pair_mat_repr)
     else:
         self.denominator = pair_mat_repr[1]
         if isinstance(pair_mat_repr[0], list): # list repr
             column = len(pair_mat_repr[0])
             self.mat_repr = Submodule(
                 size, column, pair_mat_repr[0], ishnf)
         else: # integral matrix repr
             self.mat_repr = Submodule.fromMatrix(
                 pair_mat_repr[0].copy(), ishnf)