Skip to content

Commit 71361e7

Browse files
committed
add deprecation warning for #34806
1 parent 52a81cb commit 71361e7

File tree

12 files changed

+86
-30
lines changed

12 files changed

+86
-30
lines changed

src/sage/matrix/matrix2.pyx

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ from sage.matrix.matrix_misc import permanental_minor_polynomial
105105
# used to deprecate only adjoint method
106106
from sage.misc.superseded import deprecated_function_alias
107107

108+
# temporary hack to silence the warnings from #34806
109+
from sage.rings.number_field.order import Order as NumberFieldOrder
110+
def ideal_or_fractional(R, *args):
111+
if isinstance(R, NumberFieldOrder):
112+
R = R.number_field()
113+
return R.ideal(*args)
114+
108115
_Fields = Fields()
109116

110117
cdef class Matrix(Matrix1):
@@ -15993,7 +16000,7 @@ cdef class Matrix(Matrix1):
1599316000
try:
1599416001
for i in xrange(1, len(pivs)):
1599516002
y = a[i][pivs[i]]
15996-
I = R.ideal(y)
16003+
I = ideal_or_fractional(R, y)
1599716004
s = a[0][pivs[i]]
1599816005
t = I.small_residue(s)
1599916006
v = R( (s-t) / y)
@@ -17730,9 +17737,9 @@ def _smith_diag(d, transformation=True):
1773017737
else:
1773117738
left = right = None
1773217739
for i in xrange(n):
17733-
I = R.ideal(dp[i,i])
17740+
I = ideal_or_fractional(R, dp[i,i])
1773417741

17735-
if I == R.unit_ideal():
17742+
if I == ideal_or_fractional(R, 1):
1773617743
if dp[i,i] != 1:
1773717744
if transformation:
1773817745
left.add_multiple_of_row(i,i,R(R(1)/(dp[i,i])) - 1)
@@ -17741,12 +17748,12 @@ def _smith_diag(d, transformation=True):
1774117748

1774217749
for j in xrange(i+1,n):
1774317750
if dp[j,j] not in I:
17744-
t = R.ideal([dp[i,i], dp[j,j]]).gens_reduced()
17751+
t = ideal_or_fractional(R, [dp[i,i], dp[j,j]]).gens_reduced()
1774517752
if len(t) > 1:
1774617753
raise ArithmeticError
1774717754
t = t[0]
1774817755
# find lambda, mu such that lambda*d[i,i] + mu*d[j,j] = t
17749-
lamb = R(dp[i,i]/t).inverse_mod( R.ideal(dp[j,j]/t))
17756+
lamb = R(dp[i,i]/t).inverse_mod( ideal_or_fractional(R, dp[j,j]/t))
1775017757
mu = R((t - lamb*dp[i,i]) / dp[j,j])
1775117758

1775217759
newlmat = dp.new_matrix(dp.nrows(), dp.nrows(), 1)
@@ -17821,18 +17828,15 @@ def _generic_clear_column(m):
1782117828
# [e,f]
1782217829
# is invertible over R
1782317830

17824-
if a[0,0] != 0:
17825-
I = R.ideal(a[0, 0]) # need to make sure we change this when a[0,0] changes
17826-
else:
17827-
I = R.zero_ideal()
17831+
I = ideal_or_fractional(R, a[0, 0]) # need to make sure we change this when a[0,0] changes
1782817832
for k in xrange(1, a.nrows()):
1782917833
if a[k,0] not in I:
1783017834
try:
17831-
v = R.ideal(a[0,0], a[k,0]).gens_reduced()
17835+
v = ideal_or_fractional(R, a[0,0], a[k,0]).gens_reduced()
1783217836
except Exception as msg:
1783317837
raise ArithmeticError("%s\nCan't create ideal on %s and %s" % (msg, a[0,0], a[k,0]))
1783417838
if len(v) > 1:
17835-
raise ArithmeticError("Ideal %s not principal" % R.ideal(a[0,0], a[k,0]))
17839+
raise ArithmeticError("Ideal %s not principal" % ideal_or_fractional(R, a[0,0], a[k,0]))
1783617840
B = v[0]
1783717841

1783817842
# now we find c,d, using the fact that c * (a_{0,0}/B) - d *
@@ -17841,7 +17845,7 @@ def _generic_clear_column(m):
1784117845
# need to handle carefully the case when a_{k,0}/B is a unit, i.e. a_{k,0} divides
1784217846
# a_{0,0}.
1784317847

17844-
c = R(a[0,0] / B).inverse_mod(R.ideal(a[k,0] / B))
17848+
c = R(a[0,0] / B).inverse_mod(ideal_or_fractional(R, a[k,0] / B))
1784517849
d = R( (c*a[0,0] - B)/(a[k,0]) )
1784617850

1784717851
# sanity check
@@ -17850,7 +17854,7 @@ def _generic_clear_column(m):
1785017854

1785117855
# now we find e,f such that e*d + c*f = 1 in the same way
1785217856
if c != 0:
17853-
e = d.inverse_mod( R.ideal(c) )
17857+
e = d.inverse_mod( ideal_or_fractional(R, c) )
1785417858
f = R((1 - d*e)/c)
1785517859
else:
1785617860
e = R(-a[k,0]/B) # here d is a unit and this is just 1/d
@@ -17866,7 +17870,7 @@ def _generic_clear_column(m):
1786617870
if newlmat.det() != 1:
1786717871
raise ArithmeticError
1786817872
a = newlmat*a
17869-
I = R.ideal(a[0,0])
17873+
I = ideal_or_fractional(R, a[0,0])
1787017874
left_mat = newlmat*left_mat
1787117875
if left_mat * m != a:
1787217876
raise ArithmeticError

src/sage/modular/dirichlet.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,6 +2339,7 @@ class DirichletGroupFactory(UniqueFactory):
23392339
sage: parent(val)
23402340
Gaussian Integers in Cyclotomic Field of order 4 and degree 2
23412341
sage: r4.residue_field(r4.ideal(29).factor()[0][0])(val)
2342+
doctest:warning ... DeprecationWarning: ...
23422343
17
23432344
sage: r4.residue_field(r4.ideal(29).factor()[0][0])(val) * GF(29)(3)
23442345
22

src/sage/rings/number_field/bdd_height.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,6 @@ def bdd_height(K, height_bound, tolerance=1e-2, precision=53):
430430
if B < 1:
431431
return
432432
embeddings = K.places(prec=precision)
433-
O_K = K.ring_of_integers()
434433
r1, r2 = K.signature()
435434
r = r1 + r2 - 1
436435
RF = RealField(precision)
@@ -486,7 +485,7 @@ def log_height_for_generators_approx(alpha, beta, Lambda):
486485
Return a lambda approximation h_K(alpha/beta)
487486
"""
488487
delta = Lambda / (r + 2)
489-
norm_log = delta_approximation(RR(O_K.ideal(alpha, beta).norm()).log(), delta)
488+
norm_log = delta_approximation(RR(K.ideal(alpha, beta).norm()).log(), delta)
490489
log_ga = vector_delta_approximation(log_map(alpha), delta)
491490
log_gb = vector_delta_approximation(log_map(beta), delta)
492491
arch_sum = sum([max(log_ga[k], log_gb[k]) for k in range(r + 1)])

src/sage/rings/number_field/number_field.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12534,7 +12534,7 @@ def map_Zmstar_to_Zm(h):
1253412534
p = u.lift()
1253512535
while not p.is_prime():
1253612536
p += m
12537-
f = R.ideal(p).prime_factors()[0].residue_class_degree()
12537+
f = K.fractional_ideal(p).prime_factors()[0].residue_class_degree()
1253812538
h = g**f
1253912539
if h not in H:
1254012540
Hgens += [h]

src/sage/rings/number_field/number_field_element.pyx

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,8 @@ def _inverse_mod_generic(elt, I):
169169
"""
170170
from sage.matrix.constructor import matrix
171171
R = elt.parent()
172-
try:
173-
I = R.ideal(I)
174-
except ValueError:
172+
I = R.number_field().fractional_ideal(I)
173+
if not I.is_integral():
175174
raise ValueError("inverse is only defined modulo integral ideals")
176175
if I == 0:
177176
raise ValueError("inverse is not defined modulo the zero ideal")
@@ -1987,6 +1986,9 @@ cdef class NumberFieldElement(FieldElement):
19871986
raise ArithmeticError("factorization of 0 is not defined")
19881987

19891988
K = self.parent()
1989+
from .order import is_NumberFieldOrder
1990+
if is_NumberFieldOrder(K):
1991+
K = K.number_field()
19901992
fac = K.ideal(self).factor()
19911993
# Check whether all prime ideals in `fac` are principal
19921994
for P,e in fac:
@@ -1999,6 +2001,29 @@ cdef class NumberFieldElement(FieldElement):
19992001
from sage.structure.all import Factorization
20002002
return Factorization(element_fac, unit=self/element_product)
20012003

2004+
def is_prime(self):
2005+
r"""
2006+
Test whether this number-field element is prime as
2007+
an algebraic integer.
2008+
2009+
Note that the behavior of this method differs from the behavior
2010+
of :meth:`~sage.structure.element.RingElement.is_prime` in a
2011+
general ring, according to which (number) fields would have no
2012+
nonzero prime elements.
2013+
2014+
EXAMPLES::
2015+
2016+
sage: K.<i> = NumberField(x^2+1)
2017+
sage: (1+i).is_prime()
2018+
True
2019+
sage: ((1+i)/2).is_prime()
2020+
False
2021+
"""
2022+
if not self or not self.is_integral():
2023+
return False
2024+
I = self.number_field().fractional_ideal(self)
2025+
return I.is_prime()
2026+
20022027
@coerce_binop
20032028
def gcd(self, other):
20042029
"""
@@ -2068,7 +2093,8 @@ cdef class NumberFieldElement(FieldElement):
20682093
if not is_NumberFieldOrder(R) or not R.is_maximal():
20692094
raise NotImplementedError("gcd() for %r is not implemented" % R)
20702095

2071-
g = R.ideal(self, other).gens_reduced()
2096+
K = R.number_field()
2097+
g = K.fractional_ideal(self, other).gens_reduced()
20722098
if len(g) > 1:
20732099
raise ArithmeticError("ideal (%r, %r) is not principal, gcd is not defined" % (self, other) )
20742100

src/sage/rings/number_field/order.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,14 @@ def ideal(self, *args, **kwds):
491491
"""
492492
if not self.is_maximal():
493493
raise NotImplementedError("ideals of non-maximal orders not yet supported.")
494+
from sage.misc.superseded import deprecation
495+
deprecation(34806, 'In the future, constructing an ideal of the ring of '
496+
'integers of a number field will use an implementation '
497+
'compatible with ideals of other (non-maximal) orders, '
498+
'rather than returning an integral fractional ideal of '
499+
'its containing number field. Use .fractional_ideal(), '
500+
'together with an .is_integral() check if desired, to '
501+
'avoid your code breaking with future changes to Sage.')
494502
I = self.number_field().ideal(*args, **kwds)
495503
if not I.is_integral():
496504
raise ValueError("ideal must be integral; use fractional_ideal to create a non-integral ideal.")

src/sage/rings/padics/padic_valuation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def create_key_and_extra_args_for_number_field_from_ideal(self, R, I, prime):
283283
284284
EXAMPLES::
285285
286-
sage: GaussianIntegers().valuation(GaussianIntegers().ideal(2)) # indirect doctest
286+
sage: GaussianIntegers().valuation(GaussianIntegers().number_field().fractional_ideal(2)) # indirect doctest
287287
2-adic valuation
288288
289289
TESTS:

src/sage/rings/polynomial/polynomial_element.pyx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ from sage.categories.morphism cimport Morphism
135135
from sage.misc.superseded import deprecation_cython as deprecation, deprecated_function_alias
136136
from sage.misc.cachefunc import cached_method
137137

138-
from sage.rings.number_field.order import is_NumberFieldOrder
138+
from sage.rings.number_field.order import is_NumberFieldOrder, Order as NumberFieldOrder
139139
from sage.categories.number_fields import NumberFields
140140

141141

@@ -5105,8 +5105,11 @@ cdef class Polynomial(CommutativeAlgebraElement):
51055105
y = self._parent.quo(self).gen()
51065106
from sage.groups.generic import order_from_multiple
51075107
return n == order_from_multiple(y, n, n_prime_divs, operation="*")
5108+
elif isinstance(R, NumberFieldOrder):
5109+
K = R.number_field()
5110+
return K.fractional_ideal(self.coefficients()) == K.fractional_ideal(1)
51085111
else:
5109-
return R.ideal(self.coefficients())==R.ideal(1)
5112+
return R.ideal(self.coefficients()) == R.ideal(1)
51105113

51115114
def is_constant(self):
51125115
"""

src/sage/rings/quotient_ring.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,13 @@ def QuotientRing(R, I, names=None, **kwds):
290290
from sage.rings.polynomial.polynomial_ring_constructor import BooleanPolynomialRing_constructor as BooleanPolynomialRing
291291
kwds.pop('implementation')
292292
return BooleanPolynomialRing(R.ngens(), names=names, **kwds)
293-
if not isinstance(I, ideal.Ideal_generic) or I.ring() != R:
293+
# workaround to silence warning from #34806
294+
from sage.rings.number_field.order import Order
295+
if isinstance(R, Order):
296+
if not R.is_maximal():
297+
raise NotImplementedError('only implemented for maximal orders')
298+
I = R.number_field().ideal(I)
299+
elif not isinstance(I, ideal.Ideal_generic) or I.ring() != R:
294300
I = R.ideal(I)
295301
if I.is_zero():
296302
return R
@@ -444,7 +450,13 @@ def __init__(self, R, I, names, category=None):
444450
"""
445451
if R not in _Rings:
446452
raise TypeError("The first argument must be a ring, but %s is not"%R)
447-
if I not in R.ideal_monoid():
453+
# workaround to silence warning from #34806
454+
from sage.rings.number_field.order import Order
455+
if isinstance(R, Order):
456+
M = R.number_field().ideal_monoid()
457+
else:
458+
M = R.ideal_monoid()
459+
if I not in M:
448460
raise TypeError("The second argument must be an ideal of the given ring, but %s is not"%I)
449461
self.__R = R
450462
self.__I = I

src/sage/schemes/elliptic_curves/ell_number_field.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,10 +1499,11 @@ def conductor(self):
14991499
# Note: for number fields other than QQ we could initialize
15001500
# N=K.ideal(1) or N=OK.ideal(1), which are the same, but for
15011501
# K == QQ it has to be ZZ.ideal(1).
1502-
OK = self.base_ring().ring_of_integers()
1502+
K = self.base_field()
1503+
N = ZZ.ideal(1) if K is QQ else K.fractional_ideal(1)
15031504
self._conductor = prod([d.prime()**d.conductor_valuation()
15041505
for d in self.local_data()],
1505-
OK.ideal(1))
1506+
N)
15061507
return self._conductor
15071508

15081509
def minimal_discriminant_ideal(self):

0 commit comments

Comments
 (0)