Skip to content

Commit f875be6

Browse files
author
Release Manager
committed
sagemathgh-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 sagemath#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: sagemath#29705 - Cherry-picked from: sagemath#35095 <!-- If this PR resolves an open issue, please link to it here. For example "Fixes sagemath#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 - sagemath#12345: short description why this is a dependency - sagemath#34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: sagemath#36044 Reported by: Matthias Köppe Reviewer(s): David Coudert, Kwankyu Lee, Matthias Köppe
2 parents d7a3d63 + f9e0342 commit f875be6

18 files changed

+503
-405
lines changed

src/sage/rings/number_field/S_unit_solver.py

+3-2
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

+7-1
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

+2-2
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

+2-2
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

+306-260
Large diffs are not rendered by default.

src/sage/rings/number_field/number_field_base.pyx

+10-8
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

+73-71
Large diffs are not rendered by default.

src/sage/rings/number_field/number_field_element_base.pyx

+2-2
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

+14-12
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

+1-1
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

src/sage/rings/number_field/number_field_ideal_rel.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,8 @@ def ramification_index(self):
738738
sage: K.ideal(2).ramification_index()
739739
Traceback (most recent call last):
740740
...
741-
NotImplementedError: For an ideal in a relative number field you must use relative_ramification_index or absolute_ramification_index as appropriate
741+
NotImplementedError: For an ideal in a relative number field you must use
742+
relative_ramification_index or absolute_ramification_index as appropriate
742743
"""
743744
raise NotImplementedError("For an ideal in a relative number field you must use relative_ramification_index or absolute_ramification_index as appropriate")
744745

src/sage/rings/number_field/number_field_morphisms.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,9 @@ def root_from_approx(f, a):
480480
sage: root_from_approx(x^2 + 1, CC(0))
481481
-1*I
482482
483-
sage: root_from_approx(x^2 - 2, sqrt(2))
483+
sage: root_from_approx(x^2 - 2, sqrt(2)) # needs sage.symbolic
484484
sqrt(2)
485-
sage: root_from_approx(x^2 - 2, sqrt(3))
485+
sage: root_from_approx(x^2 - 2, sqrt(3)) # needs sage.symbolic
486486
Traceback (most recent call last):
487487
...
488488
ValueError: sqrt(3) is not a root of x^2 - 2

src/sage/rings/number_field/number_field_rel.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,7 @@ def _convert_non_number_field_element(self, x):
884884
885885
Examples from :trac:`4727`::
886886
887+
sage: # needs sage.symbolic
887888
sage: K.<j,b> = QQ[sqrt(-1), sqrt(2)]
888889
sage: j
889890
I
@@ -912,7 +913,8 @@ def _convert_non_number_field_element(self, x):
912913
sage: L(L)
913914
Traceback (most recent call last):
914915
...
915-
TypeError: unable to convert Number Field in a0 with defining polynomial x^2 + 1 over its base field to Number Field in a0 with defining polynomial x^2 + 1 over its base field
916+
TypeError: unable to convert Number Field in a0 with defining polynomial x^2 + 1 over its base field
917+
to Number Field in a0 with defining polynomial x^2 + 1 over its base field
916918
sage: L in L
917919
False
918920
@@ -1672,7 +1674,7 @@ def _gen_relative(self):
16721674
sage: k.<a> = NumberField(x^2 + 1); k
16731675
Number Field in a with defining polynomial x^2 + 1
16741676
sage: y = polygen(k)
1675-
sage: m.<b> = k.extension(y^2+3); m
1677+
sage: m.<b> = k.extension(y^2 + 3); m
16761678
Number Field in b with defining polynomial x^2 + 3 over its base field
16771679
sage: c = m.gen(); c # indirect doctest
16781680
b
@@ -2455,20 +2457,20 @@ def order(self, *gens, **kwds):
24552457
24562458
EXAMPLES::
24572459
2458-
sage: P.<a,b,c> = QQ[2^(1/2), 2^(1/3), 3^(1/2)]
2459-
sage: R = P.order([a,b,c]); R
2460+
sage: P.<a,b,c> = QQ[2^(1/2), 2^(1/3), 3^(1/2)] # needs sage.symbolic
2461+
sage: R = P.order([a,b,c]); R # needs sage.symbolic
24602462
Relative Order in Number Field in sqrt2
24612463
with defining polynomial x^2 - 2 over its base field
24622464
24632465
The base ring of an order in a relative extension is still `\ZZ`.::
24642466
2465-
sage: R.base_ring()
2467+
sage: R.base_ring() # needs sage.symbolic
24662468
Integer Ring
24672469
24682470
One must give enough generators to generate a ring of finite index
24692471
in the maximal order::
24702472
2471-
sage: P.order([a, b])
2473+
sage: P.order([a, b]) # needs sage.symbolic
24722474
Traceback (most recent call last):
24732475
...
24742476
ValueError: the rank of the span of gens is wrong

src/sage/rings/number_field/order.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1064,20 +1064,20 @@ def class_number(self, proof=None):
10641064
10651065
EXAMPLES::
10661066
1067-
sage: ZZ[2^(1/3)].class_number()
1067+
sage: ZZ[2^(1/3)].class_number() # needs sage.symbolic
10681068
1
1069-
sage: QQ[sqrt(-23)].maximal_order().class_number()
1069+
sage: QQ[sqrt(-23)].maximal_order().class_number() # needs sage.symbolic
10701070
3
1071-
sage: ZZ[120*sqrt(-23)].class_number()
1071+
sage: ZZ[120*sqrt(-23)].class_number() # needs sage.symbolic
10721072
288
10731073
10741074
Note that non-maximal orders are only supported in quadratic fields::
10751075
1076-
sage: ZZ[120*sqrt(-23)].class_number()
1076+
sage: ZZ[120*sqrt(-23)].class_number() # needs sage.symbolic
10771077
288
1078-
sage: ZZ[100*sqrt(3)].class_number()
1078+
sage: ZZ[100*sqrt(3)].class_number() # needs sage.symbolic
10791079
4
1080-
sage: ZZ[11*2^(1/3)].class_number()
1080+
sage: ZZ[11*2^(1/3)].class_number() # needs sage.symbolic
10811081
Traceback (most recent call last):
10821082
...
10831083
NotImplementedError: computation of class numbers of non-maximal orders
@@ -1554,7 +1554,7 @@ def _element_constructor_(self, x):
15541554
(see :trac:`10017`)::
15551555
15561556
sage: x = polygen(QQ)
1557-
sage: K.<a> = NumberField(x^3-10)
1557+
sage: K.<a> = NumberField(x^3 - 10)
15581558
sage: ZK = K.ring_of_integers()
15591559
sage: ZK.basis()
15601560
[1/3*a^2 + 1/3*a + 1/3, a, a^2]
@@ -1665,7 +1665,7 @@ def _magma_init_(self, magma):
16651665
16661666
OUTPUT:
16671667
1668-
a MagmaElement, the magma version of this absolute order
1668+
a :class:`MagmaElement`, the magma version of this absolute order
16691669
16701670
EXAMPLES::
16711671

0 commit comments

Comments
 (0)