Skip to content

Commit e4e3f36

Browse files
committed
Address reviewer's comments.
1 parent c7931be commit e4e3f36

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

src/sage/matrix/matrix2.pyx

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15978,28 +15978,42 @@ cdef class Matrix(Matrix1):
1597815978
sage: M.elementary_divisors()
1597915979
[1, 1, 4]
1598015980

15981+
This is also true for univariate polynomials over a field::
15982+
15983+
sage: R.<x> = QQ[]
15984+
sage: M = matrix(R,[[x^2-2*x+1, x-1,x^2-1],[0,x+1,1]])
15985+
sage: M.fitting_ideal(0)
15986+
Principal ideal (0) of Univariate Polynomial Ring in x over Rational Field
15987+
sage: M.fitting_ideal(1)
15988+
Principal ideal (x - 1) of Univariate Polynomial Ring in x over Rational Field
15989+
sage: M.fitting_ideal(2)
15990+
Principal ideal (1) of Univariate Polynomial Ring in x over Rational Field
15991+
sage: M.smith_form()[0]
15992+
[ 1 0 0]
15993+
[ 0 x - 1 0]
15994+
1598115995
"""
1598215996
R = self.base_ring()
1598315997
if not R.is_exact():
1598415998
raise NotImplementedError("Fitting ideals over non-exact rings not implemented at present")
1598515999
n = self.ncols()
15986-
rank = n - i
15987-
if rank > self.nrows():
16000+
rank_minors = n - i
16001+
if rank_minors > self.nrows():
1598816002
return R.ideal([R.zero()])
15989-
elif rank <= 0:
16003+
elif rank_minors <= 0:
1599016004
return R.ideal([R.one()])
15991-
elif rank == 1:
16005+
elif rank_minors == 1:
1599216006
return R.ideal(self.coefficients())
1599316007
if R in _Fields:
15994-
if self.rank() >= rank:
16008+
if self.rank() >= rank_minors:
1599516009
return R.ideal([1])
1599616010
else:
1599716011
return R.ideal([0])
1599816012
try:
1599916013
elemdiv = self.elementary_divisors()
16000-
if rank > len(elemdiv):
16014+
if rank_minors > len(elemdiv):
1600116015
return R.ideal([0])
16002-
return R.ideal(prod(elemdiv[:rank]))
16016+
return R.ideal(prod(elemdiv[:rank_minors]))
1600316017
except (TypeError, NotImplementedError, ArithmeticError):
1600416018
pass
1600516019
for (nr,r) in enumerate(self.rows()):
@@ -16017,7 +16031,7 @@ cdef class Matrix(Matrix1):
1601716031
nz = [e for e in enumerate(c) if e[1]]
1601816032
if len(nz) == 0:
1601916033
N = self.delete_columns([nc])
16020-
return N._fitting_ideal(i - 1)
16034+
return N.fitting_ideal(i - 1)
1602116035
elif len(nz) == 1:
1602216036
N = self.delete_columns([nc])
1602316037
F1 = N.fitting_ideal(i-1)
@@ -16029,8 +16043,7 @@ cdef class Matrix(Matrix1):
1602916043
return self._fitting_ideal(i)
1603016044
except NotImplementedError:
1603116045
pass
16032-
else:
16033-
return R.ideal(self.minors(rank))
16046+
return R.ideal(self.minors(rank_minors))
1603416047

1603516048

1603616049

0 commit comments

Comments
 (0)