Skip to content

Commit c55f6ae

Browse files
author
Release Manager
committed
gh-40771: Don't fall back to pari to compute the discriminant of a maximal order. Fixes #40770. This only changes sagemath's behavior in the situation where the order `self` is known to be maximal already. This can be either because pari computed it for us, or because we computed it with `assume_maximal=True`. In the latter case, the existing behavior of sagemath is that we call pari (the `nfdisc` call), which doesn't know that the order is maximal. So it does a full-fledged factorization of the discriminant. Instead, we can compute the discriminant from the trace pairing, which is correct in all cases. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. URL: #40771 Reported by: Emmanuel Thomé Reviewer(s):
2 parents 861e13d + 964a023 commit c55f6ae

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

src/sage/rings/number_field/number_field.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5731,9 +5731,17 @@ def discriminant(self, v=None):
57315731
if v is None:
57325732
try:
57335733
return self.__disc
5734+
except AttributeError:
5735+
pass
5736+
try:
5737+
# use the maximal order if we have it, but do not
5738+
# trigger its computation if we don't.
5739+
OK = self.__maximal_order
57345740
except AttributeError:
57355741
self.__disc = ZZ(self.pari_polynomial().nfdisc())
5736-
return self.__disc
5742+
else:
5743+
self.__disc = ZZ(self.discriminant(OK.basis()))
5744+
return self.__disc
57375745
else:
57385746
return QQ(self.trace_pairing(v).det())
57395747

@@ -8086,6 +8094,17 @@ def maximal_order(self, v=None, assume_maximal='non-maximal-non-unique'):
80868094
400160824478095086350656915693814563600
80878095
sage: O3.is_maximal()
80888096
False
8097+
8098+
If we compute the maximal order via assume_maximal=True, further
8099+
calls to maximal_order() should be fast; see :issue:`40770`::
8100+
8101+
sage: x = polygen(ZZ, 'x')
8102+
sage: f = -10200*x^5 + 3394506606*x^4 + 1499062700037543*x^3 - 399446093061413660294*x^2 - 54234952557577515347321243*x + 2514415152433747751031436303788
8103+
sage: K.<a> = NumberField(f)
8104+
sage: easy = [2,3,5,7,11,83,5443,3548737,108743131120471]
8105+
sage: OK = K.maximal_order(v=easy, assume_maximal=True)
8106+
sage: K.maximal_order() == OK
8107+
True
80898108
"""
80908109
v = self._normalize_prime_list(v)
80918110

@@ -8097,7 +8116,16 @@ def maximal_order(self, v=None, assume_maximal='non-maximal-non-unique'):
80978116
if assume_maximal == "non-maximal-non-unique":
80988117
deprecation(33386, 'maximal_order(v=[primes], assume_maximal="non-maximal-non-unique") has been deprecated since it can silently produce wrong results and does not play nicely with caching. An order that is maximal at some primes should be created with assume_maximal=None instead to make no assumptions about maximality at other primes.')
80998118

8100-
return self._maximal_order(v, assume_maximal=assume_maximal)
8119+
if assume_maximal is True:
8120+
try:
8121+
return self.__maximal_order
8122+
except AttributeError:
8123+
OK = self._maximal_order(v, assume_maximal=assume_maximal)
8124+
self.__maximal_order = OK
8125+
else:
8126+
OK = self._maximal_order(v, assume_maximal=assume_maximal)
8127+
8128+
return OK
81018129

81028130

81038131
class NumberField_absolute(NumberField_generic):

src/sage/rings/number_field/order.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,18 +1734,27 @@ def discriminant(self):
17341734
sage: L.discriminant() / O.discriminant() == L.index_in(O)^2
17351735
True
17361736
1737+
17371738
TESTS::
17381739
17391740
sage: type(K.order(5*a).discriminant())
17401741
<class 'sage.rings.integer.Integer'>
1742+
1743+
This should be fast (:issue:`40770`)::
1744+
1745+
sage: x = polygen(ZZ, 'x')
1746+
sage: f = -10200*x^5 + 3394506606*x^4 + 1499062700037543*x^3 - 399446093061413660294*x^2 - 54234952557577515347321243*x + 2514415152433747751031436303788
1747+
sage: K.<a> = NumberField(f)
1748+
sage: easy = [2,3,5,7,11,83,5443,3548737,108743131120471]
1749+
sage: OK = K.maximal_order(v=easy, assume_maximal=True)
1750+
sage: OK.discriminant()
1751+
-2233837184359702514053503341104978970680899423438448397157179110318387386336251895416563127827690136506493208269682596127007739109465589455
1752+
17411753
"""
17421754
try:
17431755
return self.__discriminant
17441756
except AttributeError:
1745-
if self._is_maximal():
1746-
D = self._K.discriminant()
1747-
else:
1748-
D = ZZ(self._K.discriminant(self.basis()))
1757+
D = ZZ(self._K.discriminant(self.basis()))
17491758
self.__discriminant = D
17501759
return D
17511760

0 commit comments

Comments
 (0)