@@ -15978,28 +15978,42 @@ cdef class Matrix(Matrix1):
15978
15978
sage: M.elementary_divisors()
15979
15979
[1, 1, 4]
15980
15980
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
+
15981
15995
"""
15982
15996
R = self.base_ring()
15983
15997
if not R.is_exact():
15984
15998
raise NotImplementedError("Fitting ideals over non-exact rings not implemented at present")
15985
15999
n = self.ncols()
15986
- rank = n - i
15987
- if rank > self.nrows():
16000
+ rank_minors = n - i
16001
+ if rank_minors > self.nrows():
15988
16002
return R.ideal([R.zero()])
15989
- elif rank <= 0:
16003
+ elif rank_minors <= 0:
15990
16004
return R.ideal([R.one()])
15991
- elif rank == 1:
16005
+ elif rank_minors == 1:
15992
16006
return R.ideal(self.coefficients())
15993
16007
if R in _Fields:
15994
- if self.rank() >= rank :
16008
+ if self.rank() >= rank_minors :
15995
16009
return R.ideal([1])
15996
16010
else:
15997
16011
return R.ideal([0])
15998
16012
try:
15999
16013
elemdiv = self.elementary_divisors()
16000
- if rank > len(elemdiv):
16014
+ if rank_minors > len(elemdiv):
16001
16015
return R.ideal([0])
16002
- return R.ideal(prod(elemdiv[:rank ]))
16016
+ return R.ideal(prod(elemdiv[:rank_minors ]))
16003
16017
except (TypeError, NotImplementedError, ArithmeticError):
16004
16018
pass
16005
16019
for (nr,r) in enumerate(self.rows()):
@@ -16017,7 +16031,7 @@ cdef class Matrix(Matrix1):
16017
16031
nz = [e for e in enumerate(c) if e[1]]
16018
16032
if len(nz) == 0:
16019
16033
N = self.delete_columns([nc])
16020
- return N._fitting_ideal (i - 1)
16034
+ return N.fitting_ideal (i - 1)
16021
16035
elif len(nz) == 1:
16022
16036
N = self.delete_columns([nc])
16023
16037
F1 = N.fitting_ideal(i-1)
@@ -16029,8 +16043,7 @@ cdef class Matrix(Matrix1):
16029
16043
return self._fitting_ideal(i)
16030
16044
except NotImplementedError:
16031
16045
pass
16032
- else:
16033
- return R.ideal(self.minors(rank))
16046
+ return R.ideal(self.minors(rank_minors))
16034
16047
16035
16048
16036
16049
0 commit comments