Skip to content

Commit b6b5c2c

Browse files
author
Release Manager
committed
gh-35136: `sage.{geometry,rings}`: More `# optional` tags in doctests <!-- ^^^^^ 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" --> ### 📚 Description <!-- Describe your changes here in detail --> Adding more `# optional` tags in doctests so that doctests can be run with modularized distributions. <!-- Why is this change required? What problem does it solve? --> <!-- If it resolves an open issue, please link to the issue here. For example "Closes #1337" --> ### 📝 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! --> - [x] I have made sure that the title is self-explanatory and the description concisely explains the PR. - [ ] I have linked an issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open pull requests that this PR logically depends on --> <!-- - #xyz: short description why this is a dependency - #abc: ... --> URL: #35136 Reported by: Matthias Köppe Reviewer(s): Jonathan Kliem
2 parents 9e98425 + 02f15b2 commit b6b5c2c

24 files changed

+657
-568
lines changed

src/sage/features/sagemath.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,28 @@ def __init__(self):
122122
[PythonModule('sage.groups.perm_gps.permgroup')])
123123

124124

125+
class sage__libs__pari(JoinFeature):
126+
r"""
127+
A :class:`sage.features.Feature` describing the presence of :mod:`sage.libs.pari`.
128+
129+
EXAMPLES::
130+
131+
sage: from sage.features.sagemath import sage__libs__pari
132+
sage: sage__libs__pari().is_present() # optional - sage.libs.pari
133+
FeatureTestResult('sage.libs.pari', True)
134+
"""
135+
def __init__(self):
136+
r"""
137+
TESTS::
138+
139+
sage: from sage.features.sagemath import sage__libs__pari
140+
sage: isinstance(sage__libs__pari(), sage__libs__pari)
141+
True
142+
"""
143+
JoinFeature.__init__(self, 'sage.libs.pari',
144+
[PythonModule('sage.libs.pari.convert_sage')])
145+
146+
125147
class sage__plot(JoinFeature):
126148
r"""
127149
A :class:`~sage.features.Feature` describing the presence of :mod:`sage.plot`.
@@ -209,6 +231,27 @@ def __init__(self):
209231
PythonModule.__init__(self, 'sage.rings.real_double')
210232

211233

234+
class sage__rings__real_mpfr(PythonModule):
235+
r"""
236+
A :class:`~sage.features.Feature` describing the presence of :mod:`sage.rings.real_mpfr`.
237+
238+
EXAMPLES::
239+
240+
sage: from sage.features.sagemath import sage__rings__real_mpfr
241+
sage: sage__rings__real_mpfr().is_present() # optional - sage.rings.real_mpfr
242+
FeatureTestResult('sage.rings.real_mpfr', True)
243+
"""
244+
def __init__(self):
245+
r"""
246+
TESTS::
247+
248+
sage: from sage.features.sagemath import sage__rings__real_mpfr
249+
sage: isinstance(sage__rings__real_mpfr(), sage__rings__real_mpfr)
250+
True
251+
"""
252+
PythonModule.__init__(self, 'sage.rings.real_mpfr')
253+
254+
212255
class sage__symbolic(JoinFeature):
213256
r"""
214257
A :class:`~sage.features.Feature` describing the presence of :mod:`sage.symbolic`.
@@ -259,8 +302,10 @@ def all_features():
259302
sage__geometry__polyhedron(),
260303
sage__graphs(),
261304
sage__groups(),
305+
sage__libs__pari(),
262306
sage__plot(),
263307
sage__rings__number_field(),
264308
sage__rings__padics(),
265309
sage__rings__real_double(),
310+
sage__rings__real_mpfr(),
266311
sage__symbolic()]

src/sage/geometry/cone_catalog.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ def rearrangement(p, ambient_dim=None, lattice=None):
374374
sage: ambient_dim = ZZ.random_element(2,10).abs()
375375
sage: p = ZZ.random_element(1, ambient_dim)
376376
sage: K = cones.rearrangement(p, ambient_dim)
377-
sage: P = SymmetricGroup(ambient_dim).random_element().matrix()
378-
sage: all( K.contains(P*r) for r in K )
377+
sage: P = SymmetricGroup(ambient_dim).random_element().matrix() # optional - sage.groups
378+
sage: all(K.contains(P*r) for r in K) # optional - sage.groups
379379
True
380380
381381
The smallest ``p`` components of every element of the rearrangement
@@ -529,11 +529,11 @@ def schur(ambient_dim=None, lattice=None):
529529
530530
sage: P = cones.schur(5)
531531
sage: Q = cones.nonnegative_orthant(5)
532-
sage: G = ( g.change_ring(QQbar).normalized() for g in P )
533-
sage: H = ( h.change_ring(QQbar).normalized() for h in Q )
534-
sage: actual = max(arccos(u.inner_product(v)) for u in G for v in H)
535-
sage: expected = 3*pi/4
536-
sage: abs(actual - expected).n() < 1e-12
532+
sage: G = ( g.change_ring(QQbar).normalized() for g in P ) # optional - sage.rings.number_fields
533+
sage: H = ( h.change_ring(QQbar).normalized() for h in Q ) # optional - sage.rings.number_fields
534+
sage: actual = max(arccos(u.inner_product(v)) for u in G for v in H) # optional - sage.rings.number_fields
535+
sage: expected = 3*pi/4 # optional - sage.rings.number_fields
536+
sage: abs(actual - expected).n() < 1e-12 # optional - sage.rings.number_fields
537537
True
538538
539539
The dual of the Schur cone is the "downward monotonic cone"
@@ -566,7 +566,7 @@ def schur(ambient_dim=None, lattice=None):
566566
True
567567
sage: x = V.random_element()
568568
sage: y = V.random_element()
569-
sage: majorized_by(x,y) == ( (y-x) in S )
569+
sage: majorized_by(x,y) == ( (y-x) in S ) # optional - sage.rings.number_fields
570570
True
571571
572572
If a ``lattice`` was given, it is actually used::

src/sage/geometry/hyperplane_arrangement/affine_subspace.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
True
3434
sage: c < b
3535
False
36-
sage: A = AffineSubspace([8,38,21,250], VectorSpace(GF(19),4))
37-
sage: A
36+
sage: A = AffineSubspace([8,38,21,250], VectorSpace(GF(19),4)) # optional - sage.libs.pari
37+
sage: A # optional - sage.libs.pari
3838
Affine space p + W where:
3939
p = (8, 0, 2, 3)
4040
W = Vector space of dimension 4 over Finite Field of size 19
@@ -384,9 +384,9 @@ def intersection(self, other):
384384
[]
385385
sage: A.intersection(C).intersection(B)
386386
387-
sage: D = AffineSubspace([1,2,3], VectorSpace(GF(5),3))
388-
sage: E = AffineSubspace([3,4,5], VectorSpace(GF(5),3))
389-
sage: D.intersection(E)
387+
sage: D = AffineSubspace([1,2,3], VectorSpace(GF(5),3)) # optional - sage.libs.pari
388+
sage: E = AffineSubspace([3,4,5], VectorSpace(GF(5),3)) # optional - sage.libs.pari
389+
sage: D.intersection(E) # optional - sage.libs.pari
390390
Affine space p + W where:
391391
p = (3, 4, 0)
392392
W = Vector space of dimension 3 over Finite Field of size 5

src/sage/geometry/hyperplane_arrangement/arrangement.py

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -60,30 +60,30 @@
6060
The default base field is `\QQ`, the rational numbers. Finite fields are also
6161
supported::
6262
63-
sage: H.<x,y,z> = HyperplaneArrangements(GF(5))
64-
sage: a = H([(1,2,3), 4], [(5,6,7), 8]); a
63+
sage: H.<x,y,z> = HyperplaneArrangements(GF(5)) # optional - sage.libs.pari
64+
sage: a = H([(1,2,3), 4], [(5,6,7), 8]); a # optional - sage.libs.pari
6565
Arrangement <y + 2*z + 3 | x + 2*y + 3*z + 4>
6666
6767
Number fields are also possible::
6868
6969
sage: x = var('x')
70-
sage: NF.<a> = NumberField(x**4 - 5*x**2 + 5,embedding=1.90)
71-
sage: H.<y,z> = HyperplaneArrangements(NF)
72-
sage: A = H([[(-a**3 + 3*a, -a**2 + 4), 1], [(a**3 - 4*a, -1), 1],
70+
sage: NF.<a> = NumberField(x**4 - 5*x**2 + 5, embedding=1.90) # optional - sage.rings.number_field
71+
sage: H.<y,z> = HyperplaneArrangements(NF) # optional - sage.rings.number_field
72+
sage: A = H([[(-a**3 + 3*a, -a**2 + 4), 1], [(a**3 - 4*a, -1), 1], # optional - sage.rings.number_field
7373
....: [(0, 2*a**2 - 6), 1], [(-a**3 + 4*a, -1), 1],
7474
....: [(a**3 - 3*a, -a**2 + 4), 1]])
75-
sage: A
75+
sage: A # optional - sage.rings.number_field
7676
Arrangement of 5 hyperplanes of dimension 2 and rank 2
77-
sage: A.base_ring()
77+
sage: A.base_ring() # optional - sage.rings.number_field
7878
Number Field in a with defining polynomial x^4 - 5*x^2 + 5 with a = 1.902113032590308?
7979
8080
Notation (iii): a list or tuple of hyperplanes::
8181
82-
sage: H.<x,y,z> = HyperplaneArrangements(GF(5))
83-
sage: k = [x+i for i in range(4)]; k
82+
sage: H.<x,y,z> = HyperplaneArrangements(GF(5)) # optional - sage.libs.pari
83+
sage: k = [x+i for i in range(4)]; k # optional - sage.libs.pari
8484
[Hyperplane x + 0*y + 0*z + 0, Hyperplane x + 0*y + 0*z + 1,
8585
Hyperplane x + 0*y + 0*z + 2, Hyperplane x + 0*y + 0*z + 3]
86-
sage: H(k)
86+
sage: H(k) # optional - sage.libs.pari
8787
Arrangement <x | x + 1 | x + 2 | x + 3>
8888
8989
Notation (iv): using the library of arrangements::
@@ -264,10 +264,10 @@
264264
sage: a = hyperplane_arrangements.semiorder(3)
265265
sage: a.has_good_reduction(5)
266266
True
267-
sage: b = a.change_ring(GF(5))
267+
sage: b = a.change_ring(GF(5)) # optional - sage.libs.pari
268268
sage: pa = a.intersection_poset()
269-
sage: pb = b.intersection_poset()
270-
sage: pa.is_isomorphic(pb)
269+
sage: pb = b.intersection_poset() # optional - sage.libs.pari
270+
sage: pa.is_isomorphic(pb) # optional - sage.libs.pari
271271
True
272272
sage: a.face_vector()
273273
(0, 12, 30, 19)
@@ -356,7 +356,6 @@
356356
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
357357

358358
from sage.geometry.hyperplane_arrangement.hyperplane import AmbientVectorSpace, Hyperplane
359-
from sage.combinat.posets.posets import Poset
360359

361360

362361
class HyperplaneArrangementElement(Element):
@@ -1129,7 +1128,7 @@ def change_ring(self, base_ring):
11291128
11301129
sage: H.<x,y> = HyperplaneArrangements(QQ)
11311130
sage: A = H([(1,1), 0], [(2,3), -1])
1132-
sage: A.change_ring(FiniteField(2))
1131+
sage: A.change_ring(FiniteField(2)) # optional - sage.libs.pari
11331132
Arrangement <y + 1 | x + y>
11341133
11351134
TESTS:
@@ -1165,25 +1164,30 @@ def n_regions(self):
11651164
11661165
sage: H.<x,y> = HyperplaneArrangements(QQ)
11671166
sage: A = H([(1,1), 0], [(2,3), -1], [(4,5), 3])
1168-
sage: B = A.change_ring(FiniteField(7))
1169-
sage: B.n_regions()
1167+
sage: B = A.change_ring(FiniteField(7)) # optional - sage.libs.pari
1168+
sage: B.n_regions() # optional - sage.libs.pari
11701169
Traceback (most recent call last):
11711170
...
11721171
TypeError: base field must have characteristic zero
11731172
11741173
Check that :trac:`30749` is fixed::
11751174
11761175
sage: R.<y> = QQ[]
1177-
sage: v1 = AA.polynomial_root(AA.common_polynomial(y^2 - 3), RIF(RR(1.7320508075688772), RR(1.7320508075688774)))
1178-
sage: v2 = QQbar.polynomial_root(AA.common_polynomial(y^4 - y^2 + 1), CIF(RIF(RR(0.8660254037844386), RR(0.86602540378443871)), RIF(-RR(0.50000000000000011), -RR(0.49999999999999994))))
1179-
sage: my_vectors = (vector(AA, [-v1, -1, 1]), vector(AA, [0, 2, 1]), vector(AA,[v1, -1, 1]), vector(AA, [1, 0, 0]), vector(AA, [1/2, AA(-1/2*v2^3 + v2),0]), vector(AA, [-1/2, AA(-1/2*v2^3 + v2), 0]))
1180-
sage: H = HyperplaneArrangements(AA, names='xyz')
1181-
sage: x,y,z = H.gens()
1182-
sage: A = H(backend="normaliz") # optional - pynormaliz
1183-
sage: for v in my_vectors: # optional - pynormaliz
1176+
sage: v1 = AA.polynomial_root(AA.common_polynomial(y^2 - 3), # optional - sage.rings.number_field
1177+
....: RIF(RR(1.7320508075688772), RR(1.7320508075688774)))
1178+
sage: v2 = QQbar.polynomial_root(AA.common_polynomial(y^4 - y^2 + 1), # optional - sage.rings.number_field
1179+
....: CIF(RIF(RR(0.8660254037844386), RR(0.86602540378443871)),
1180+
....: RIF(-RR(0.50000000000000011), -RR(0.49999999999999994))))
1181+
sage: my_vectors = (vector(AA, [-v1, -1, 1]), vector(AA, [0, 2, 1]), vector(AA, [v1, -1, 1]), # optional - sage.rings.number_field
1182+
....: vector(AA, [1, 0, 0]), vector(AA, [1/2, AA(-1/2*v2^3 + v2),0]),
1183+
....: vector(AA, [-1/2, AA(-1/2*v2^3 + v2), 0]))
1184+
sage: H = HyperplaneArrangements(AA, names='xyz') # optional - sage.rings.number_field
1185+
sage: x,y,z = H.gens() # optional - sage.rings.number_field
1186+
sage: A = H(backend="normaliz") # optional - pynormaliz # optional - sage.rings.number_field
1187+
sage: for v in my_vectors: # optional - pynormaliz # optional - sage.rings.number_field
11841188
....: a, b, c = v
11851189
....: A = A.add_hyperplane(a*x + b*y + c*z)
1186-
sage: A.n_regions() # optional - pynormaliz
1190+
sage: A.n_regions() # optional - pynormaliz # optional - sage.rings.number_field
11871191
24
11881192
"""
11891193
if self.base_ring().characteristic() != 0:
@@ -1211,8 +1215,8 @@ def n_bounded_regions(self):
12111215
12121216
sage: H.<x,y> = HyperplaneArrangements(QQ)
12131217
sage: A = H([(1,1),0], [(2,3),-1], [(4,5),3])
1214-
sage: B = A.change_ring(FiniteField(7))
1215-
sage: B.n_bounded_regions()
1218+
sage: B = A.change_ring(FiniteField(7)) # optional - sage.libs.pari
1219+
sage: B.n_bounded_regions() # optional - sage.libs.pari
12161220
Traceback (most recent call last):
12171221
...
12181222
TypeError: base field must have characteristic zero
@@ -1243,14 +1247,14 @@ def has_good_reduction(self, p):
12431247
EXAMPLES::
12441248
12451249
sage: a = hyperplane_arrangements.semiorder(3)
1246-
sage: a.has_good_reduction(5)
1250+
sage: a.has_good_reduction(5) # optional - sage.libs.pari
12471251
True
1248-
sage: a.has_good_reduction(3)
1252+
sage: a.has_good_reduction(3) # optional - sage.libs.pari
12491253
False
1250-
sage: b = a.change_ring(GF(3))
1254+
sage: b = a.change_ring(GF(3)) # optional - sage.libs.pari
12511255
sage: a.characteristic_polynomial()
12521256
x^3 - 6*x^2 + 12*x
1253-
sage: b.characteristic_polynomial() # not equal to that for a
1257+
sage: b.characteristic_polynomial() # not equal to that for a # optional - sage.libs.pari
12541258
x^3 - 6*x^2 + 10*x
12551259
"""
12561260
if self.base_ring() != QQ:
@@ -1495,9 +1499,9 @@ def essentialization(self):
14951499
Hyperplane arrangements in 1-dimensional linear space over
14961500
Rational Field with coordinate x
14971501
1498-
sage: H.<x,y> = HyperplaneArrangements(GF(2))
1499-
sage: C = H([(1,1),1], [(1,1),0])
1500-
sage: C.essentialization()
1502+
sage: H.<x,y> = HyperplaneArrangements(GF(2)) # optional - sage.libs.pari
1503+
sage: C = H([(1,1),1], [(1,1),0]) # optional - sage.libs.pari
1504+
sage: C.essentialization() # optional - sage.libs.pari
15011505
Arrangement <y | y + 1>
15021506
15031507
sage: h = hyperplane_arrangements.semiorder(4)
@@ -1587,9 +1591,9 @@ def sign_vector(self, p):
15871591
15881592
TESTS::
15891593
1590-
sage: H.<x,y> = HyperplaneArrangements(GF(3))
1591-
sage: A = H(x, y)
1592-
sage: A.sign_vector([1, 2])
1594+
sage: H.<x,y> = HyperplaneArrangements(GF(3)) # optional - sage.libs.pari
1595+
sage: A = H(x, y) # optional - sage.libs.pari
1596+
sage: A.sign_vector([1, 2]) # optional - sage.libs.pari
15931597
Traceback (most recent call last):
15941598
...
15951599
ValueError: characteristic must be zero
@@ -1992,6 +1996,8 @@ def poset_of_regions(self, B=None, numbered_labels=True):
19921996
sage: A.poset_of_regions(B=base_region)
19931997
Finite poset containing 14 elements
19941998
"""
1999+
from sage.combinat.posets.posets import Poset
2000+
19952001
# We use RX to keep track of indexes and R to keep track of which regions
19962002
# we've already hit. This poset is graded, so we can go one set at a time
19972003
RX = self.regions()
@@ -2480,7 +2486,7 @@ def face_semigroup_algebra(self, field=None, names='e'):
24802486
sage: (e3 + 2*e4) * (e1 - e7)
24812487
e4 - e6
24822488
2483-
sage: U3 = a.face_semigroup_algebra(field=GF(3)); U3
2489+
sage: U3 = a.face_semigroup_algebra(field=GF(3)); U3 # optional - sage.libs.pari
24842490
Finite-dimensional algebra of degree 13 over Finite Field of size 3
24852491
24862492
TESTS:
@@ -2550,8 +2556,8 @@ def region_containing_point(self, p):
25502556
TESTS::
25512557
25522558
sage: A = H([(1,1),0], [(2,3),-1], [(4,5),3])
2553-
sage: B = A.change_ring(FiniteField(7))
2554-
sage: B.region_containing_point((1,2))
2559+
sage: B = A.change_ring(FiniteField(7)) # optional - sage.libs.pari
2560+
sage: B.region_containing_point((1,2)) # optional - sage.libs.pari
25552561
Traceback (most recent call last):
25562562
...
25572563
ValueError: base field must have characteristic zero
@@ -2991,8 +2997,8 @@ def matroid(self):
29912997
intersection lattice::
29922998
29932999
sage: f = sum([list(M.flats(i)) for i in range(M.rank()+1)], [])
2994-
sage: PF = Poset([f, lambda x,y: x < y])
2995-
sage: PF.is_isomorphic(A.intersection_poset())
3000+
sage: PF = Poset([f, lambda x, y: x < y]) # optional - sage.combinat
3001+
sage: PF.is_isomorphic(A.intersection_poset()) # optional - sage.combinat
29963002
True
29973003
"""
29983004
if not self.is_central():

src/sage/geometry/linear_expression.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def evaluate(self, point):
440440
9
441441
sage: ex([1,1]) # syntactic sugar
442442
9
443-
sage: ex([pi, e])
443+
sage: ex([pi, e]) # optional - sage.symbolic
444444
2*pi + 3*e + 4
445445
"""
446446
try:

src/sage/geometry/polyhedral_complex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- coding: utf-8 -*-
1+
# sage.doctest: optional - sage.graphs
22
r"""
33
Finite polyhedral complexes
44

src/sage/geometry/polyhedron/backend_number_field.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ def _init_from_Vrepresentation(self, vertices, rays, lines,
119119
120120
Check that the coordinates of a vertex get simplified in the Symbolic Ring::
121121
122-
sage: p = Polyhedron(ambient_dim=2, base_ring=SR, backend='number_field')
122+
sage: p = Polyhedron(ambient_dim=2, base_ring=SR, backend='number_field') # optional - sage.symbolic
123123
sage: from sage.geometry.polyhedron.backend_number_field import Polyhedron_number_field
124-
sage: Polyhedron_number_field._init_from_Vrepresentation(p, [(0,1/2),(sqrt(2),0),(4,5/6)], [], []); p
124+
sage: Polyhedron_number_field._init_from_Vrepresentation(p, [(0,1/2),(sqrt(2),0),(4,5/6)], [], []); p # optional - sage.symbolic
125125
A 2-dimensional polyhedron in (Symbolic Ring)^2 defined as the convex hull of 3 vertices
126-
sage: p.vertices()[0][0]
126+
sage: p.vertices()[0][0] # optional - sage.symbolic
127127
0
128128
"""
129129
(vertices, rays, lines), internal_base_ring \

0 commit comments

Comments
 (0)