Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/sage/arith/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1887,11 +1887,8 @@ def __GCD_sequence(v, **kwargs):
"""
if len(v) == 0:
return ZZ.zero()
if hasattr(v, 'universe'):
g = v.universe()(0)
else:
g = ZZ.zero()
for vi in v:
g = v[0]
for vi in v[1:]:
g = vi.gcd(g, **kwargs)
return g

Expand Down
53 changes: 24 additions & 29 deletions src/sage/categories/rings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ def _test_characteristic(self, **options):
from sage.rings.integer import Integer
tester.assertIsInstance(characteristic, Integer)

def ideal(self, *args, **kwds):
def ideal(self, *args, coerce=True, ideal_class=None, **kwds):
"""
Create an ideal of this ring.

Expand Down Expand Up @@ -1096,15 +1096,9 @@ def ideal(self, *args, **kwds):
sage: type(ZZ.ideal((), ideal_class=CustomIdealClass))
<class '...CustomIdealClass'>
"""
if 'coerce' in kwds:
coerce = kwds['coerce']
del kwds['coerce']
else:
coerce = True

from sage.rings.ideal import Ideal_generic
if not args:
gens = [self(0)]
gens = []
else:
gens = args
while isinstance(gens, (list, tuple, GeneratorType)) and len(gens) == 1:
Expand Down Expand Up @@ -1132,29 +1126,30 @@ def ideal(self, *args, **kwds):
elif coerce:
gens = [self(g) for g in gens]

from sage.categories.principal_ideal_domains import PrincipalIdealDomains
if self in PrincipalIdealDomains():
# Use GCD algorithm to obtain a principal ideal
g = gens[0]
if len(gens) == 1:
try:
# note: we set g = gcd(g, g) to "canonicalize" the generator:
# make polynomials monic, etc.
g = g.gcd(g)
except (AttributeError, NotImplementedError, IndexError):
pass
else:
for h in gens[1:]:
g = g.gcd(h)
gens = [g]
if 'ideal_class' in kwds:
C = kwds['ideal_class']
del kwds['ideal_class']
else:
C = self._ideal_class_(len(gens))
# Parent classes may define eagerly_reduce_gens_by_gcd = False to opt out of this
# either because gcd() is expensive, checking whether self is PID is expensive,
# or because ideal_class constructor already have a more efficient gcd()
if getattr(self, 'eagerly_reduce_ideal_gens_by_gcd', True):
from sage.categories.principal_ideal_domains import PrincipalIdealDomains
if self in PrincipalIdealDomains():
from sage.arith.misc import gcd
# Use GCD algorithm to obtain a principal ideal
if len(gens) == 1:
try:
# note: we set g = gcd(g, g) to "canonicalize" the generator:
# make polynomials monic, etc.
g = gens[0]
gens = g.gcd(g),
except (AttributeError, NotImplementedError, IndexError):
pass
else:
gens = gcd(gens),

if ideal_class is None:
ideal_class = self._ideal_class_(len(gens))
if len(gens) == 1 and isinstance(gens[0], (list, tuple)):
gens = gens[0]
return C(self, gens, **kwds)
return ideal_class(self, gens, **kwds)

# Quotient rings
def quotient(self, I, names=None, **kwds):
Expand Down
7 changes: 7 additions & 0 deletions src/sage/rings/ideal.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

from types import GeneratorType

from sage.misc.cachefunc import cached_method
from sage.categories.rings import Rings
from sage.categories.fields import Fields
from sage.structure.element import MonoidElement
Expand Down Expand Up @@ -93,7 +94,7 @@
sage: i = ideal(1,t,t^2)
sage: i
Ideal (1, t, t^2) of Univariate Polynomial Ring in t over Integer Ring
sage: ideal(1/2,t,t^2)

Check failure on line 97 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, new)

Failed example:

Failed example:: Got: Principal ideal (1/2) of Univariate Polynomial Ring in t over Rational Field

Check failure on line 97 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / test-long (src/sage/[p-z]*)

Failed example:

Failed example:: Got: Principal ideal (1/2) of Univariate Polynomial Ring in t over Rational Field

Check failure on line 97 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (macos, Python 3.13, all)

Failed example:

Failed example:: Got: Principal ideal (1/2) of Univariate Polynomial Ring in t over Rational Field

Check failure on line 97 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, all)

Failed example:

Failed example:: Got: Principal ideal (1/2) of Univariate Polynomial Ring in t over Rational Field

Check failure on line 97 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.13, all)

Failed example:

Failed example:: Got: Principal ideal (1/2) of Univariate Polynomial Ring in t over Rational Field

Check failure on line 97 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (macos, Python 3.12, all)

Failed example:

Failed example:: Got: Principal ideal (1/2) of Univariate Polynomial Ring in t over Rational Field

Check failure on line 97 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, all, editable)

Failed example:

Failed example:: Got: Principal ideal (1/2) of Univariate Polynomial Ring in t over Rational Field
Principal ideal (1) of Univariate Polynomial Ring in t over Rational Field

This shows that the issues at :issue:`1104` are resolved::
Expand Down Expand Up @@ -159,13 +160,13 @@
sage: R.<x> = QQ[]
sage: I = R.ideal([x + x^2])
sage: J = R.ideal([2*x + 2*x^2])
sage: J

Check failure on line 163 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, new)

Failed example:

Failed example:: Got: Principal ideal (2*x^2 + 2*x) of Univariate Polynomial Ring in x over Rational Field

Check failure on line 163 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / test-long (src/sage/[p-z]*)

Failed example:

Failed example:: Got: Principal ideal (2*x^2 + 2*x) of Univariate Polynomial Ring in x over Rational Field

Check failure on line 163 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (macos, Python 3.13, all)

Failed example:

Failed example:: Got: Principal ideal (2*x^2 + 2*x) of Univariate Polynomial Ring in x over Rational Field

Check failure on line 163 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, all)

Failed example:

Failed example:: Got: Principal ideal (2*x^2 + 2*x) of Univariate Polynomial Ring in x over Rational Field

Check failure on line 163 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.13, all)

Failed example:

Failed example:: Got: Principal ideal (2*x^2 + 2*x) of Univariate Polynomial Ring in x over Rational Field

Check failure on line 163 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (macos, Python 3.12, all)

Failed example:

Failed example:: Got: Principal ideal (2*x^2 + 2*x) of Univariate Polynomial Ring in x over Rational Field

Check failure on line 163 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, all, editable)

Failed example:

Failed example:: Got: Principal ideal (2*x^2 + 2*x) of Univariate Polynomial Ring in x over Rational Field
Principal ideal (x^2 + x) of Univariate Polynomial Ring in x over Rational Field
sage: S = R.quotient_ring(I) # needs sage.libs.pari
sage: U = R.quotient_ring(J) # needs sage.libs.pari
sage: I == J
True
sage: S == U # needs sage.libs.pari

Check failure on line 169 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, new)

Failed example:

Failed example:: Got: False

Check failure on line 169 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / test-long (src/sage/[p-z]*)

Failed example:

Failed example:: Got: False

Check failure on line 169 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (macos, Python 3.13, all)

Failed example:

Failed example:: Got: False

Check failure on line 169 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, all)

Failed example:

Failed example:: Got: False

Check failure on line 169 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.13, all)

Failed example:

Failed example:: Got: False

Check failure on line 169 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (macos, Python 3.12, all)

Failed example:

Failed example:: Got: False

Check failure on line 169 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, all, editable)

Failed example:

Failed example:: Got: False
True
"""
if len(args) == 0:
Expand Down Expand Up @@ -519,10 +520,10 @@
sage: J = ideal([CC['x'].0 + 1]); J
Principal ideal (x + 1.00000000000000) of Univariate Polynomial Ring in x
over Complex Field with 53 bits of precision
sage: psi(J)

Check failure on line 523 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, new)

Failed example:

Failed example:: Got: Principal ideal (-x + 1.00000000000000) of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision

Check failure on line 523 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / test-long (src/sage/[p-z]*)

Failed example:

Failed example:: Got: Principal ideal (-x + 1.00000000000000) of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision

Check failure on line 523 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (macos, Python 3.13, all)

Failed example:

Failed example:: Got: Principal ideal (-x + 1.00000000000000) of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision

Check failure on line 523 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, all)

Failed example:

Failed example:: Got: Principal ideal (-x + 1.00000000000000) of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision

Check failure on line 523 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.13, all)

Failed example:

Failed example:: Got: Principal ideal (-x + 1.00000000000000) of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision

Check failure on line 523 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (macos, Python 3.12, all)

Failed example:

Failed example:: Got: Principal ideal (-x + 1.00000000000000) of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision

Check failure on line 523 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, all, editable)

Failed example:

Failed example:: Got: Principal ideal (-x + 1.00000000000000) of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision
Principal ideal (x - 1.00000000000000) of Univariate Polynomial Ring in x
over Complex Field with 53 bits of precision
sage: J.apply_morphism(psi)

Check failure on line 526 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, new)

Failed example:

Failed example:: Got: Principal ideal (-x + 1.00000000000000) of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision

Check failure on line 526 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / test-long (src/sage/[p-z]*)

Failed example:

Failed example:: Got: Principal ideal (-x + 1.00000000000000) of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision

Check failure on line 526 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (macos, Python 3.13, all)

Failed example:

Failed example:: Got: Principal ideal (-x + 1.00000000000000) of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision

Check failure on line 526 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, all)

Failed example:

Failed example:: Got: Principal ideal (-x + 1.00000000000000) of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision

Check failure on line 526 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.13, all)

Failed example:

Failed example:: Got: Principal ideal (-x + 1.00000000000000) of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision

Check failure on line 526 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (macos, Python 3.12, all)

Failed example:

Failed example:: Got: Principal ideal (-x + 1.00000000000000) of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision

Check failure on line 526 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, all, editable)

Failed example:

Failed example:: Got: Principal ideal (-x + 1.00000000000000) of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision
Principal ideal (x - 1.00000000000000) of Univariate Polynomial Ring in x
over Complex Field with 53 bits of precision

Expand Down Expand Up @@ -702,6 +703,7 @@
"""
return len(self.__gens)

@cached_method
def gens_reduced(self):
r"""
Same as :meth:`gens()` for this ideal, since there is currently no
Expand All @@ -715,6 +717,11 @@
sage: ZZ.ideal(5).gens_reduced()
(5,)
"""
if not getattr(self.__ring, 'eagerly_reduce_ideal_gens_by_gcd', True):
from sage.categories.principal_ideal_domains import PrincipalIdealDomains
if self.__ring in PrincipalIdealDomains():
from sage.arith.misc import gcd
return gcd(self.gens()),
return self.gens()

def is_maximal(self):
Expand Down Expand Up @@ -1327,7 +1334,7 @@
over Integer Ring
sage: J
Ideal (2, x) of Univariate Polynomial Ring in x over Integer Ring
sage: K

Check failure on line 1337 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, new)

Failed example:

Failed example:: Got: Principal ideal (2) of Univariate Polynomial Ring in x over Rational Field

Check failure on line 1337 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / test-long (src/sage/[p-z]*)

Failed example:

Failed example:: Got: Principal ideal (2) of Univariate Polynomial Ring in x over Rational Field

Check failure on line 1337 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, all)

Failed example:

Failed example:: Got: Principal ideal (2) of Univariate Polynomial Ring in x over Rational Field

Check failure on line 1337 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.13, all)

Failed example:

Failed example:: Got: Principal ideal (2) of Univariate Polynomial Ring in x over Rational Field

Check failure on line 1337 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, all, editable)

Failed example:

Failed example:: Got: Principal ideal (2) of Univariate Polynomial Ring in x over Rational Field
Principal ideal (1) of Univariate Polynomial Ring in x
over Rational Field
sage: I.is_principal()
Expand Down Expand Up @@ -1362,7 +1369,7 @@
sage: J = R.base_extend(QQ).ideal(2,x)
sage: a = I.gen(); a
x
sage: b = J.gen(); b

Check failure on line 1372 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, new)

Failed example:

Failed example:: Got: 2

Check failure on line 1372 in src/sage/rings/ideal.py

View workflow job for this annotation

GitHub Actions / test-long (src/sage/[p-z]*)

Failed example:

Failed example:: Got: 2
1
sage: a.base_ring()
Integer Ring
Expand Down
1 change: 1 addition & 0 deletions src/sage/rings/polynomial/polynomial_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ class PolynomialRing_generic(Ring):
"""
Univariate polynomial ring over a ring.
"""
eagerly_reduce_ideal_gens_by_gcd = False

def __init__(self, base_ring, name=None, sparse=False, implementation=None,
element_class=None, category=None):
Expand Down
Loading