Skip to content

Commit a38d129

Browse files
author
Release Manager
committed
gh-36044: `sage.rings.number_field`: Modularization fixes, doctest cosmetics, `# needs` <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes #1234" use "Introduce new method to calculate 1+1" --> <!-- Describe your changes here in detail --> - Avoiding going through symbolic square roots in `.S_unit_solver` - `# needs sage.symbolic`, `# needs sage.libs.*`, `# needs sage.rings.finite_rings` etc. - Reformatting doctests to fit on the screen - Codestyle fixes in doctests - Block tags for `# optional - magma` - Handle import errors in `NumberField._pushout_` <!-- Why is this change required? What problem does it solve? --> This is - Part of: #29705 - Cherry-picked from: #35095 <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [ ] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #36044 Reported by: Matthias Köppe Reviewer(s): David Coudert, Kwankyu Lee, Matthias Köppe
2 parents 11751dc + f9e0342 commit a38d129

18 files changed

+503
-405
lines changed

src/sage/rings/number_field/S_unit_solver.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -982,11 +982,12 @@ def minimal_vector(A, y, prec=106):
982982
ALLLinv = ALLL.inverse()
983983
ybrace = [ abs(R(a-a.round())) for a in y * ALLLinv if (a-a.round()) != 0]
984984

985+
v = ALLL.rows()[0]
985986
if len(ybrace) == 0:
986-
return (ALLL.rows()[0].norm())**2 / c1
987+
return v.dot_product(v) / c1
987988
else:
988989
sigma = ybrace[len(ybrace)-1]
989-
return ((ALLL.rows()[0].norm())**2 * sigma) / c1
990+
return v.dot_product(v) * sigma / c1
990991

991992

992993
def reduction_step_complex_case(place, B0, list_of_gens, torsion_gen, c13):

src/sage/rings/number_field/galois_group.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ class GaloisGroup_v1(SageObject):
4545
4646
EXAMPLES::
4747
48+
sage: # needs sage.symbolic
4849
sage: from sage.rings.number_field.galois_group import GaloisGroup_v1
4950
sage: K = QQ[2^(1/3)]
50-
sage: G = GaloisGroup_v1(K.absolute_polynomial().galois_group(pari_group=True), K); G
51+
sage: pK = K.absolute_polynomial()
52+
sage: G = GaloisGroup_v1(pK.galois_group(pari_group=True), K); G
5153
...DeprecationWarning: GaloisGroup_v1 is deprecated; please use GaloisGroup_v2
5254
See https://github.com/sagemath/sage/issues/28782 for details.
5355
Galois group PARI group [6, -1, 2, "S3"] of degree 3 of the
@@ -96,6 +98,8 @@ def __eq__(self, other):
9698
sage: G = GaloisGroup_v1(K.absolute_polynomial().galois_group(pari_group=True), K)
9799
...DeprecationWarning: GaloisGroup_v1 is deprecated; please use GaloisGroup_v2
98100
See https://github.com/sagemath/sage/issues/28782 for details.
101+
102+
sage: # needs sage.symbolic
99103
sage: L = QQ[sqrt(2)]
100104
sage: H = GaloisGroup_v1(L.absolute_polynomial().galois_group(pari_group=True), L)
101105
sage: H == G
@@ -125,6 +129,8 @@ def __ne__(self, other):
125129
sage: G = GaloisGroup_v1(K.absolute_polynomial().galois_group(pari_group=True), K)
126130
...DeprecationWarning: GaloisGroup_v1 is deprecated; please use GaloisGroup_v2
127131
See https://github.com/sagemath/sage/issues/28782 for details.
132+
133+
sage: # needs sage.symbolic
128134
sage: L = QQ[sqrt(2)]
129135
sage: H = GaloisGroup_v1(L.absolute_polynomial().galois_group(pari_group=True), L)
130136
sage: H != G

src/sage/rings/number_field/homset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,10 @@ def _element_constructor_(self, x, base_map=None, base_hom=None, check=True):
342342
are only approximate::
343343
344344
sage: K.<a> = QuadraticField(-7)
345-
sage: f = K.hom([CC(sqrt(-7))], check=False)
345+
sage: f = K.hom([CC(sqrt(-7))], check=False) # needs sage.symbolic
346346
sage: x = polygen(K)
347347
sage: L.<b> = K.extension(x^2 - a - 5)
348-
sage: L.Hom(CC)(f(a + 5).sqrt(), f, check=False)
348+
sage: L.Hom(CC)(f(a + 5).sqrt(), f, check=False) # needs sage.symbolic
349349
Relative number field morphism:
350350
From: Number Field in b with defining polynomial x^2 - a - 5 over its base field
351351
To: Complex Field with 53 bits of precision

src/sage/rings/number_field/maps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def _repr_type(self):
7979

8080
def is_injective(self):
8181
r"""
82-
EXAMPLES::
82+
EXAMPLES::
8383
8484
sage: x = polygen(ZZ, 'x')
8585
sage: K.<a> = NumberField(x^4 + 3*x + 1)
@@ -91,7 +91,7 @@ def is_injective(self):
9191

9292
def is_surjective(self):
9393
r"""
94-
EXAMPLES::
94+
EXAMPLES::
9595
9696
sage: x = polygen(ZZ, 'x')
9797
sage: K.<a> = NumberField(x^4 + 3*x + 1)

src/sage/rings/number_field/number_field.py

Lines changed: 306 additions & 260 deletions
Large diffs are not rendered by default.

src/sage/rings/number_field/number_field_base.pyx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# sage.doctest: optional - sage.rings.number_field
1+
# sage.doctest: needs sage.rings.number_field
22
"""
33
Base class for all number fields
44
@@ -135,13 +135,15 @@ cdef class NumberField(Field):
135135
else:
136136
codomain_other = other
137137

138-
from sage.rings.qqbar import AA
139-
if codomain_self is AA and codomain_other is AA:
140-
return AA
141-
142-
from sage.rings.qqbar import QQbar
143-
if codomain_self in (AA, QQbar) and codomain_other in (AA, QQbar):
144-
return QQbar
138+
try:
139+
from sage.rings.qqbar import AA, QQbar
140+
except ImportError:
141+
pass
142+
else:
143+
if codomain_self is AA and codomain_other is AA:
144+
return AA
145+
if codomain_self in (AA, QQbar) and codomain_other in (AA, QQbar):
146+
return QQbar
145147

146148
def ring_of_integers(self, *args, **kwds):
147149
r"""

src/sage/rings/number_field/number_field_element.pyx

Lines changed: 73 additions & 71 deletions
Large diffs are not rendered by default.

src/sage/rings/number_field/number_field_element_base.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ cdef class NumberFieldElement_base(FieldElement):
2121
EXAMPLES::
2222
2323
sage: x = polygen(ZZ, 'x')
24-
sage: k.<a> = NumberField(x^3 + x + 1) # optional - sage.rings.number_field
25-
sage: isinstance(a, sage.rings.number_field.number_field_element_base.NumberFieldElement_base) # optional - sage.rings.number_field
24+
sage: k.<a> = NumberField(x^3 + x + 1) # needs sage.rings.number_field
25+
sage: isinstance(a, sage.rings.number_field.number_field_element_base.NumberFieldElement_base) # needs sage.rings.number_field
2626
True
2727
2828
By design, there is a unique direct subclass::

src/sage/rings/number_field/number_field_element_quadratic.pyx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,9 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute):
295295
EXAMPLES::
296296
297297
sage: K.<a> = QuadraticField(-1)
298-
sage: (1/3 + a/2)._sympy_() # optional - sympy
298+
sage: (1/3 + a/2)._sympy_() # needs sympy
299299
1/3 + I/2
300-
sage: type(_) # optional - sympy
300+
sage: type(_) # needs sympy
301301
<class 'sympy.core.add.Add'>
302302
"""
303303
a = self.parent().gen()
@@ -506,10 +506,10 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute):
506506
507507
Verify embeddings are respected::
508508
509-
sage: cf6c = CyclotomicField(6, embedding=CDF(exp(-pi*I/3))) ; z6c = cf6c.0
510-
sage: cf3(z6c)
509+
sage: cf6c = CyclotomicField(6, embedding=CDF(exp(-pi*I/3))); z6c = cf6c.0 # needs sage.symbolic
510+
sage: cf3(z6c) # needs sage.symbolic
511511
-zeta3
512-
sage: cf6c(z3)
512+
sage: cf6c(z3) # needs sage.symbolic
513513
-zeta6
514514
515515
AUTHOR:
@@ -986,9 +986,10 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute):
986986
sage: (-a-2).sign()
987987
-1
988988
989+
sage: # needs sage.symbolic
989990
sage: x = polygen(ZZ, 'x')
990-
sage: K.<b> = NumberField(x^2 + 2*x + 7, 'b', embedding=CC(-1,-sqrt(6))) # optional - sage.symbolic
991-
sage: b.sign() # optional - sage.symbolic
991+
sage: K.<b> = NumberField(x^2 + 2*x + 7, 'b', embedding=CC(-1,-sqrt(6)))
992+
sage: b.sign()
992993
Traceback (most recent call last):
993994
...
994995
ValueError: a complex number has no sign!
@@ -1822,6 +1823,7 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute):
18221823
0
18231824
sage: (a + 1/2).real()
18241825
1/2
1826+
sage: x = polygen(ZZ, 'x')
18251827
sage: K.<a> = NumberField(x^2 + x + 1)
18261828
sage: a.real()
18271829
-1/2
@@ -1865,7 +1867,7 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute):
18651867
1/2*sqrt3
18661868
sage: a.real()
18671869
-1/2
1868-
sage: SR(a) # optional - sage.symbolic
1870+
sage: SR(a) # needs sage.symbolic
18691871
1/2*I*sqrt(3) - 1/2
18701872
sage: bool(QQbar(I)*QQbar(a.imag()) + QQbar(a.real()) == QQbar(a))
18711873
True
@@ -2214,7 +2216,7 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute):
22142216
22152217
sage: x = polygen(ZZ, 'x')
22162218
sage: K.<a> = NumberField(x^2 + 1, embedding=CDF.gen())
2217-
sage: abs(a+1)
2219+
sage: abs(a+1) # needs sage.symbolic
22182220
sqrt(2)
22192221
"""
22202222
if mpz_sgn(self.D.value) == 1:
@@ -2506,11 +2508,11 @@ cdef class NumberFieldElement_gaussian(NumberFieldElement_quadratic_sqrt):
25062508
r"""
25072509
EXAMPLES::
25082510
2509-
sage: SR(1 + 2*i) # optional - sage.symbolic
2511+
sage: SR(1 + 2*i) # needs sage.symbolic
25102512
2*I + 1
25112513
25122514
sage: K.<mi> = QuadraticField(-1, embedding=CC(0,-1))
2513-
sage: SR(1 + mi) # optional - sage.symbolic
2515+
sage: SR(1 + mi) # needs sage.symbolic
25142516
-I + 1
25152517
"""
25162518
from sage.symbolic.constants import I
@@ -2616,7 +2618,7 @@ cdef class NumberFieldElement_gaussian(NumberFieldElement_quadratic_sqrt):
26162618
26172619
EXAMPLES::
26182620
2619-
sage: I.log() # optional - sage.symbolic
2621+
sage: I.log() # needs sage.symbolic
26202622
1/2*I*pi
26212623
"""
26222624
from sage.symbolic.ring import SR

src/sage/rings/number_field/number_field_ideal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# sage.doctest: optional - sage.libs.pari
1+
# sage.doctest: needs sage.libs.pari sage.rings.number_field
22
"""
33
Number Field Ideals
44

0 commit comments

Comments
 (0)