Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Cleaning up code.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeines committed Aug 22, 2016
1 parent 79794d2 commit 535ae3e
Showing 1 changed file with 66 additions and 66 deletions.
132 changes: 66 additions & 66 deletions src/sage/modules/free_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@

from . import free_module_element
import sage.matrix.matrix_space
from sage.libs.pari.all import pari, pari_gen
from sage.modules.module import Module
import sage.rings.finite_rings.finite_field_constructor as finite_field

Expand All @@ -177,7 +176,7 @@
import sage.rings.field as field
import sage.rings.finite_rings.constructor as finite_field
import sage.rings.integral_domain as integral_domain
>>>>>>> Added a _pseudo_basis_matrix method to modules/free_module.py and

import sage.rings.ring as ring
import sage.rings.integer_ring
import sage.rings.rational_field
Expand Down Expand Up @@ -1292,7 +1291,7 @@ def echelonized_basis_matrix(self):
NotImplementedError
"""
raise NotImplementedError

def matrix(self):
"""
Return the basis matrix of this module, which is the matrix whose
Expand Down Expand Up @@ -5371,11 +5370,11 @@ def __cmp__(self, other):
Free module of degree 1 and rank 1 over Integer Ring
Echelon basis matrix:
[1]
We now generalize this to class number one rings of integers.
::
sage: F.<a> = NumberField(x^2-x-1)
sage: ZF = F.ring_of_integers()
sage: A = matrix(ZF,[[1,0,0,0],[0,-1,0,0],[0,0,1,0],[0,0,0,1]])
Expand All @@ -5384,17 +5383,18 @@ def __cmp__(self, other):
sage: VB = (ZF^4).span(B)
sage: VB == VA
True
Now we check an example with the same _pseudo_hermite_matrix matrices,
Now we check an example with the same _pseudo_hermite_matrix matrices,
but different ideal lists::
sage: C = matrix(ZF,[[3,0,3,0],[0,3,6,9],[0,0,3,0],[12,0,0,3]])
sage: VC = (ZF^4).span(C)
sage: VC == VA
False
And finally and example where they have different _pseudo_hermite_matrix matrices::
And finally and example where they have different
_pseudo_hermite_matrix matrices::
sage: D = matrix(ZF,[[1+a,1,12*a,1],[1+a,1+a,1+a,1+a],[2*a+3,1+a,4*a+5,0],[1,0,1,1]])
sage: VD = (ZF^4).span(D)
sage: VA == VD
Expand All @@ -5411,10 +5411,11 @@ def __cmp__(self, other):
if c: return c
c = cmp(self.base_ring(), other.base_ring())
if c: return c
# We use self.echelonized_basis_matrix() == other.echelonized_basis_matrix()
# We use
# self.echelonized_basis_matrix() == other.echelonized_basis_matrix()
# with the matrix to avoid a circular reference.

if nf_order.is_NumberFieldOrder(self.base_ring()) and self.base_ring() != ZZ:
if nf_order.is_NumberFieldOrder(
self.base_ring()) and self.base_ring() != sage.rings.integer_ring.ZZ:
Mat,Ids = self._pseudo_hermite_matrix()
Omat,OIds = other._pseudo_hermite_matrix()
#if the ideals are the same, compare the matrices
Expand All @@ -5423,7 +5424,8 @@ def __cmp__(self, other):
#otherwise, compare the ideals.
else:
return cmp(Ids,OIds)
return cmp(self.echelonized_basis_matrix(), other.echelonized_basis_matrix())
return cmp(
self.echelonized_basis_matrix(), other.echelonized_basis_matrix())

def _denominator(self, B):
"""
Expand Down Expand Up @@ -5534,36 +5536,36 @@ def ambient_module(self):

def _pseudo_hermite_matrix(self,ideal_list = None):
r"""
This returns the pseudo basis as a matrix in hermite form and a list of ideals.
It is here for now, but could be used more generally, e.g., for non-PIDs, more specifically,
for non class number one rings of integers.
This returns the pseudo basis as a matrix in hermite form and a list
of ideals. It is here for now, but could be used more generally, e.g.,
for non-PIDs, more specifically, for non class number one rings of
integers.
INPUT:
- `self` -- a free module over a PID, specifically a class number one ring of integers.
- `ideal_list` -- a list of ideals used to generate the pseudo basis.
OUTPUT:
A pseudo basis matrix in Hermite normal form and the list of pseodo basis ideals.
We start with an example of free modules that are equal, but due to extra units in the
number field ring of integers, Echelon form cannot tell them apart.
A pseudo basis matrix in Hermite normal form and the list of pseodo
basis ideals.
We start with an example of free modules that are equal, but due to
extra units in the number field ring of integers, Echelon form cannot
tell them apart.
::
sage: F.<a> = NumberField(x^2-x-1)
sage: ZF = F.ring_of_integers()
sage: A = matrix(ZF,[[1,0,0,0],[0,-1,0,0],[0,0,1,0],[0,0,0,1]])
sage: B = identity_matrix(ZF,4)
sage: VA = (ZF^4).span(A)
sage: VA._pseudo_hermite_matrix()
(
[1 0 0 0]
[0 1 0 0]
[0 0 1 0]
[1 0 0 0]
[0 1 0 0]
[0 0 1 0]
[0 0 0 1], [Fractional ideal (1), Fractional ideal (1), Fractional ideal (1), Fractional ideal (1)]
)
sage: VA._pseudo_hermite_matrix([F.ideal(1)])
Expand All @@ -5573,51 +5575,51 @@ def _pseudo_hermite_matrix(self,ideal_list = None):
sage: VB = (ZF^4).span(B)
sage: VB._pseudo_hermite_matrix()
(
[1 0 0 0]
[0 1 0 0]
[0 0 1 0]
[1 0 0 0]
[0 1 0 0]
[0 0 1 0]
[0 0 0 1], [Fractional ideal (1), Fractional ideal (1), Fractional ideal (1), Fractional ideal (1)]
)
Now we check an example with non-trivial ideal list returned::
sage: C = matrix(ZF,[[3,0,3,0],[0,3,6,9],[0,0,3,0],[12,0,0,3]])
sage: VC = (ZF^4).span(C)
sage: VC._pseudo_hermite_matrix()
(
[1 0 0 0]
[0 1 0 0]
[0 0 1 0]
[1 0 0 0]
[0 1 0 0]
[0 0 1 0]
[0 0 0 1], [Fractional ideal (3), Fractional ideal (3), Fractional ideal (3), Fractional ideal (3)]
)
An example with a more interesting _pseudo_hermite_matrix matrix::
sage: D = matrix(ZF,[[1+a,1,12*a,1],[1+a,1+a,1+a,1+a],[2*a+3,1+a,4*a+5,0],[1,0,1,1]])
sage: VD = (ZF^4).span(D)
sage: VD._pseudo_hermite_matrix()
(
[ 1 0 0 618/1279*a + 551/1279]
[ 0 1 0 0]
[ 0 0 1 -50/1279*a - 533/1279]
[ 1 0 0 618/1279*a + 551/1279]
[ 0 1 0 0]
[ 0 0 1 -50/1279*a - 533/1279]
[ 0 0 0 1], [Fractional ideal (1), Fractional ideal (1), Fractional ideal (1), Fractional ideal (-32*a + 15)]
)
An example with a non-trivial ideal_list input::
sage: IC = [F.fractional_ideal(1), F.fractional_ideal(2), F.fractional_ideal(2), F.fractional_ideal(2)]
sage: VA._pseudo_hermite_matrix(ideal_list = IC)
(
[1 0 0 0]
[0 1 0 0]
[0 0 1 0]
[1 0 0 0]
[0 1 0 0]
[0 0 1 0]
[0 0 0 1], [Fractional ideal (1), Fractional ideal (2), Fractional ideal (2), Fractional ideal (2)]
)
We can also handle ideal_lists over ZZ::
sage: M = identity_matrix(ZZ,10)
sage: ID = [ideal(ZZ(p)) for p in prime_range(30)]
sage: ID = [ideal(p) for p in prime_range(30)]
sage: VZ = (ZZ^10).span(M)
sage: VZ._pseudo_hermite_matrix(ID)
[ 2 0 0 0 0 0 0 0 0 0]
Expand All @@ -5634,21 +5636,19 @@ def _pseudo_hermite_matrix(self,ideal_list = None):
sage: VZ._pseudo_hermite_matrix(ID)
Traceback (most recent call last):
...
ValueError: gens and ideal_list must have the same lenghth
ValueError: gens and ideal_list must have the same length
sage: M=matrix([[ZZ(i+j^2) for i in range(10)] for j in range(3,13)])
sage: VZ = (ZZ^10).span(M)
sage: VZ._pseudo_hermite_matrix()
[ 1 0 -1 -2 -3 -4 -5 -6 -7 -8]
[ 0 1 2 3 4 5 6 7 8 9]
"""
import sage.matrix.constructor
ZF = self._base
#do ZZ first
if ZF == ZZ and ideal_list == None:
if ZF is sage.rings.integer_ring.ZZ and ideal_list is None:
return self.basis_matrix().hermite_form()
elif ZF == ZZ:
elif ZF is sage.rings.integer_ring.ZZ:
if len(self.gens()) != len(ideal_list):
raise ValueError("gens and ideal_list must have the same lenghth")
gens = [g*ids.gen() for g,ids in zip(self.gens(),ideal_list)]
Expand All @@ -5658,14 +5658,14 @@ def _pseudo_hermite_matrix(self,ideal_list = None):
#in this case we use Pari for pseudo bases.
assert nf_order.is_NumberFieldOrder(ZF)
F = ZF.number_field()
PF=pari(F)
PF = F._pari_()
BM = self.basis_matrix()
if ideal_list == None:
ideal_list = [F.ideal(1) for id in range(len(self.gens()))]
if ideal_list is None:
ideal_list = [F.ideal(1)] * len(self.gens())
elif len(self.gens()) != len(ideal_list):
raise ValueError("gens and ideal_list must have the same lenghth")
pari_ideal_list = [pari(id) for id in ideal_list]
HM,HI = PF.nfhnf([pari(BM),pari_ideal_list])
pari_ideal_list = [id._pari_() for id in ideal_list]
HM, HI = PF.nfhnf([BM._pari_(), pari_ideal_list])

M = sage.matrix.constructor.matrix([[F(HM[i][j]) for i in range(len(HM))] for j in range(len(HM[0]))])
I = [F.ideal(id) for id in HI]
Expand Down

0 comments on commit 535ae3e

Please sign in to comment.