Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sage.{geometry,rings}: More # optional tags in doctests #35136

Merged
merged 9 commits into from
Mar 26, 2023
45 changes: 45 additions & 0 deletions src/sage/features/sagemath.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,28 @@ def __init__(self):
[PythonModule('sage.groups.perm_gps.permgroup')])


class sage__libs__pari(JoinFeature):
r"""
A :class:`sage.features.Feature` describing the presence of :mod:`sage.libs.pari`.

EXAMPLES::

sage: from sage.features.sagemath import sage__libs__pari
sage: sage__libs__pari().is_present() # optional - sage.libs.pari
FeatureTestResult('sage.libs.pari', True)
"""
def __init__(self):
r"""
TESTS::

sage: from sage.features.sagemath import sage__libs__pari
sage: isinstance(sage__libs__pari(), sage__libs__pari)
True
"""
JoinFeature.__init__(self, 'sage.libs.pari',
[PythonModule('sage.libs.pari.convert_sage')])


class sage__plot(JoinFeature):
r"""
A :class:`~sage.features.Feature` describing the presence of :mod:`sage.plot`.
Expand Down Expand Up @@ -209,6 +231,27 @@ def __init__(self):
PythonModule.__init__(self, 'sage.rings.real_double')


class sage__rings__real_mpfr(PythonModule):
r"""
A :class:`~sage.features.Feature` describing the presence of :mod:`sage.rings.real_mpfr`.

EXAMPLES::

sage: from sage.features.sagemath import sage__rings__real_mpfr
sage: sage__rings__real_mpfr().is_present() # optional - sage.rings.real_mpfr
FeatureTestResult('sage.rings.real_mpfr', True)
"""
def __init__(self):
r"""
TESTS::

sage: from sage.features.sagemath import sage__rings__real_mpfr
sage: isinstance(sage__rings__real_mpfr(), sage__rings__real_mpfr)
True
"""
PythonModule.__init__(self, 'sage.rings.real_mpfr')


class sage__symbolic(JoinFeature):
r"""
A :class:`~sage.features.Feature` describing the presence of :mod:`sage.symbolic`.
Expand Down Expand Up @@ -259,8 +302,10 @@ def all_features():
sage__geometry__polyhedron(),
sage__graphs(),
sage__groups(),
sage__libs__pari(),
sage__plot(),
sage__rings__number_field(),
sage__rings__padics(),
sage__rings__real_double(),
sage__rings__real_mpfr(),
sage__symbolic()]
16 changes: 8 additions & 8 deletions src/sage/geometry/cone_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ def rearrangement(p, ambient_dim=None, lattice=None):
sage: ambient_dim = ZZ.random_element(2,10).abs()
sage: p = ZZ.random_element(1, ambient_dim)
sage: K = cones.rearrangement(p, ambient_dim)
sage: P = SymmetricGroup(ambient_dim).random_element().matrix()
sage: all( K.contains(P*r) for r in K )
sage: P = SymmetricGroup(ambient_dim).random_element().matrix() # optional - sage.groups
sage: all(K.contains(P*r) for r in K) # optional - sage.groups
True

The smallest ``p`` components of every element of the rearrangement
Expand Down Expand Up @@ -529,11 +529,11 @@ def schur(ambient_dim=None, lattice=None):

sage: P = cones.schur(5)
sage: Q = cones.nonnegative_orthant(5)
sage: G = ( g.change_ring(QQbar).normalized() for g in P )
sage: H = ( h.change_ring(QQbar).normalized() for h in Q )
sage: actual = max(arccos(u.inner_product(v)) for u in G for v in H)
sage: expected = 3*pi/4
sage: abs(actual - expected).n() < 1e-12
sage: G = ( g.change_ring(QQbar).normalized() for g in P ) # optional - sage.rings.number_fields
sage: H = ( h.change_ring(QQbar).normalized() for h in Q ) # optional - sage.rings.number_fields
sage: actual = max(arccos(u.inner_product(v)) for u in G for v in H) # optional - sage.rings.number_fields
sage: expected = 3*pi/4 # optional - sage.rings.number_fields
sage: abs(actual - expected).n() < 1e-12 # optional - sage.rings.number_fields
True

The dual of the Schur cone is the "downward monotonic cone"
Expand Down Expand Up @@ -566,7 +566,7 @@ def schur(ambient_dim=None, lattice=None):
True
sage: x = V.random_element()
sage: y = V.random_element()
sage: majorized_by(x,y) == ( (y-x) in S )
sage: majorized_by(x,y) == ( (y-x) in S ) # optional - sage.rings.number_fields
True

If a ``lattice`` was given, it is actually used::
Expand Down
10 changes: 5 additions & 5 deletions src/sage/geometry/hyperplane_arrangement/affine_subspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
True
sage: c < b
False
sage: A = AffineSubspace([8,38,21,250], VectorSpace(GF(19),4))
sage: A
sage: A = AffineSubspace([8,38,21,250], VectorSpace(GF(19),4)) # optional - sage.libs.pari
sage: A # optional - sage.libs.pari
Affine space p + W where:
p = (8, 0, 2, 3)
W = Vector space of dimension 4 over Finite Field of size 19
Expand Down Expand Up @@ -384,9 +384,9 @@ def intersection(self, other):
[]
sage: A.intersection(C).intersection(B)

sage: D = AffineSubspace([1,2,3], VectorSpace(GF(5),3))
sage: E = AffineSubspace([3,4,5], VectorSpace(GF(5),3))
sage: D.intersection(E)
sage: D = AffineSubspace([1,2,3], VectorSpace(GF(5),3)) # optional - sage.libs.pari
sage: E = AffineSubspace([3,4,5], VectorSpace(GF(5),3)) # optional - sage.libs.pari
sage: D.intersection(E) # optional - sage.libs.pari
Affine space p + W where:
p = (3, 4, 0)
W = Vector space of dimension 3 over Finite Field of size 5
Expand Down
90 changes: 48 additions & 42 deletions src/sage/geometry/hyperplane_arrangement/arrangement.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,30 +60,30 @@
The default base field is `\QQ`, the rational numbers. Finite fields are also
supported::

sage: H.<x,y,z> = HyperplaneArrangements(GF(5))
sage: a = H([(1,2,3), 4], [(5,6,7), 8]); a
sage: H.<x,y,z> = HyperplaneArrangements(GF(5)) # optional - sage.libs.pari
sage: a = H([(1,2,3), 4], [(5,6,7), 8]); a # optional - sage.libs.pari
Arrangement <y + 2*z + 3 | x + 2*y + 3*z + 4>

Number fields are also possible::

sage: x = var('x')
sage: NF.<a> = NumberField(x**4 - 5*x**2 + 5,embedding=1.90)
sage: H.<y,z> = HyperplaneArrangements(NF)
sage: A = H([[(-a**3 + 3*a, -a**2 + 4), 1], [(a**3 - 4*a, -1), 1],
sage: NF.<a> = NumberField(x**4 - 5*x**2 + 5, embedding=1.90) # optional - sage.rings.number_field
sage: H.<y,z> = HyperplaneArrangements(NF) # optional - sage.rings.number_field
sage: A = H([[(-a**3 + 3*a, -a**2 + 4), 1], [(a**3 - 4*a, -1), 1], # optional - sage.rings.number_field
....: [(0, 2*a**2 - 6), 1], [(-a**3 + 4*a, -1), 1],
....: [(a**3 - 3*a, -a**2 + 4), 1]])
sage: A
sage: A # optional - sage.rings.number_field
Arrangement of 5 hyperplanes of dimension 2 and rank 2
sage: A.base_ring()
sage: A.base_ring() # optional - sage.rings.number_field
Number Field in a with defining polynomial x^4 - 5*x^2 + 5 with a = 1.902113032590308?

Notation (iii): a list or tuple of hyperplanes::

sage: H.<x,y,z> = HyperplaneArrangements(GF(5))
sage: k = [x+i for i in range(4)]; k
sage: H.<x,y,z> = HyperplaneArrangements(GF(5)) # optional - sage.libs.pari
sage: k = [x+i for i in range(4)]; k # optional - sage.libs.pari
[Hyperplane x + 0*y + 0*z + 0, Hyperplane x + 0*y + 0*z + 1,
Hyperplane x + 0*y + 0*z + 2, Hyperplane x + 0*y + 0*z + 3]
sage: H(k)
sage: H(k) # optional - sage.libs.pari
Arrangement <x | x + 1 | x + 2 | x + 3>

Notation (iv): using the library of arrangements::
Expand Down Expand Up @@ -264,10 +264,10 @@
sage: a = hyperplane_arrangements.semiorder(3)
sage: a.has_good_reduction(5)
True
sage: b = a.change_ring(GF(5))
sage: b = a.change_ring(GF(5)) # optional - sage.libs.pari
sage: pa = a.intersection_poset()
sage: pb = b.intersection_poset()
sage: pa.is_isomorphic(pb)
sage: pb = b.intersection_poset() # optional - sage.libs.pari
sage: pa.is_isomorphic(pb) # optional - sage.libs.pari
True
sage: a.face_vector()
(0, 12, 30, 19)
Expand Down Expand Up @@ -356,7 +356,6 @@
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing

from sage.geometry.hyperplane_arrangement.hyperplane import AmbientVectorSpace, Hyperplane
from sage.combinat.posets.posets import Poset


class HyperplaneArrangementElement(Element):
Expand Down Expand Up @@ -1129,7 +1128,7 @@ def change_ring(self, base_ring):

sage: H.<x,y> = HyperplaneArrangements(QQ)
sage: A = H([(1,1), 0], [(2,3), -1])
sage: A.change_ring(FiniteField(2))
sage: A.change_ring(FiniteField(2)) # optional - sage.libs.pari
Arrangement <y + 1 | x + y>

TESTS:
Expand Down Expand Up @@ -1165,25 +1164,30 @@ def n_regions(self):

sage: H.<x,y> = HyperplaneArrangements(QQ)
sage: A = H([(1,1), 0], [(2,3), -1], [(4,5), 3])
sage: B = A.change_ring(FiniteField(7))
sage: B.n_regions()
sage: B = A.change_ring(FiniteField(7)) # optional - sage.libs.pari
sage: B.n_regions() # optional - sage.libs.pari
Traceback (most recent call last):
...
TypeError: base field must have characteristic zero

Check that :trac:`30749` is fixed::

sage: R.<y> = QQ[]
sage: v1 = AA.polynomial_root(AA.common_polynomial(y^2 - 3), RIF(RR(1.7320508075688772), RR(1.7320508075688774)))
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))))
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]))
sage: H = HyperplaneArrangements(AA, names='xyz')
sage: x,y,z = H.gens()
sage: A = H(backend="normaliz") # optional - pynormaliz
sage: for v in my_vectors: # optional - pynormaliz
sage: v1 = AA.polynomial_root(AA.common_polynomial(y^2 - 3), # optional - sage.rings.number_field
....: RIF(RR(1.7320508075688772), RR(1.7320508075688774)))
sage: v2 = QQbar.polynomial_root(AA.common_polynomial(y^4 - y^2 + 1), # optional - sage.rings.number_field
....: CIF(RIF(RR(0.8660254037844386), RR(0.86602540378443871)),
....: RIF(-RR(0.50000000000000011), -RR(0.49999999999999994))))
sage: my_vectors = (vector(AA, [-v1, -1, 1]), vector(AA, [0, 2, 1]), vector(AA, [v1, -1, 1]), # optional - sage.rings.number_field
....: 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]))
sage: H = HyperplaneArrangements(AA, names='xyz') # optional - sage.rings.number_field
sage: x,y,z = H.gens() # optional - sage.rings.number_field
sage: A = H(backend="normaliz") # optional - pynormaliz # optional - sage.rings.number_field
sage: for v in my_vectors: # optional - pynormaliz # optional - sage.rings.number_field
....: a, b, c = v
....: A = A.add_hyperplane(a*x + b*y + c*z)
sage: A.n_regions() # optional - pynormaliz
sage: A.n_regions() # optional - pynormaliz # optional - sage.rings.number_field
24
"""
if self.base_ring().characteristic() != 0:
Expand Down Expand Up @@ -1211,8 +1215,8 @@ def n_bounded_regions(self):

sage: H.<x,y> = HyperplaneArrangements(QQ)
sage: A = H([(1,1),0], [(2,3),-1], [(4,5),3])
sage: B = A.change_ring(FiniteField(7))
sage: B.n_bounded_regions()
sage: B = A.change_ring(FiniteField(7)) # optional - sage.libs.pari
sage: B.n_bounded_regions() # optional - sage.libs.pari
Traceback (most recent call last):
...
TypeError: base field must have characteristic zero
Expand Down Expand Up @@ -1243,14 +1247,14 @@ def has_good_reduction(self, p):
EXAMPLES::

sage: a = hyperplane_arrangements.semiorder(3)
sage: a.has_good_reduction(5)
sage: a.has_good_reduction(5) # optional - sage.libs.pari
True
sage: a.has_good_reduction(3)
sage: a.has_good_reduction(3) # optional - sage.libs.pari
False
sage: b = a.change_ring(GF(3))
sage: b = a.change_ring(GF(3)) # optional - sage.libs.pari
sage: a.characteristic_polynomial()
x^3 - 6*x^2 + 12*x
sage: b.characteristic_polynomial() # not equal to that for a
sage: b.characteristic_polynomial() # not equal to that for a # optional - sage.libs.pari
x^3 - 6*x^2 + 10*x
"""
if self.base_ring() != QQ:
Expand Down Expand Up @@ -1495,9 +1499,9 @@ def essentialization(self):
Hyperplane arrangements in 1-dimensional linear space over
Rational Field with coordinate x

sage: H.<x,y> = HyperplaneArrangements(GF(2))
sage: C = H([(1,1),1], [(1,1),0])
sage: C.essentialization()
sage: H.<x,y> = HyperplaneArrangements(GF(2)) # optional - sage.libs.pari
sage: C = H([(1,1),1], [(1,1),0]) # optional - sage.libs.pari
sage: C.essentialization() # optional - sage.libs.pari
Arrangement <y | y + 1>

sage: h = hyperplane_arrangements.semiorder(4)
Expand Down Expand Up @@ -1587,9 +1591,9 @@ def sign_vector(self, p):

TESTS::

sage: H.<x,y> = HyperplaneArrangements(GF(3))
sage: A = H(x, y)
sage: A.sign_vector([1, 2])
sage: H.<x,y> = HyperplaneArrangements(GF(3)) # optional - sage.libs.pari
sage: A = H(x, y) # optional - sage.libs.pari
sage: A.sign_vector([1, 2]) # optional - sage.libs.pari
Traceback (most recent call last):
...
ValueError: characteristic must be zero
Expand Down Expand Up @@ -1992,6 +1996,8 @@ def poset_of_regions(self, B=None, numbered_labels=True):
sage: A.poset_of_regions(B=base_region)
Finite poset containing 14 elements
"""
from sage.combinat.posets.posets import Poset

# We use RX to keep track of indexes and R to keep track of which regions
# we've already hit. This poset is graded, so we can go one set at a time
RX = self.regions()
Expand Down Expand Up @@ -2480,7 +2486,7 @@ def face_semigroup_algebra(self, field=None, names='e'):
sage: (e3 + 2*e4) * (e1 - e7)
e4 - e6

sage: U3 = a.face_semigroup_algebra(field=GF(3)); U3
sage: U3 = a.face_semigroup_algebra(field=GF(3)); U3 # optional - sage.libs.pari
Finite-dimensional algebra of degree 13 over Finite Field of size 3

TESTS:
Expand Down Expand Up @@ -2550,8 +2556,8 @@ def region_containing_point(self, p):
TESTS::

sage: A = H([(1,1),0], [(2,3),-1], [(4,5),3])
sage: B = A.change_ring(FiniteField(7))
sage: B.region_containing_point((1,2))
sage: B = A.change_ring(FiniteField(7)) # optional - sage.libs.pari
sage: B.region_containing_point((1,2)) # optional - sage.libs.pari
Traceback (most recent call last):
...
ValueError: base field must have characteristic zero
Expand Down Expand Up @@ -2991,8 +2997,8 @@ def matroid(self):
intersection lattice::

sage: f = sum([list(M.flats(i)) for i in range(M.rank()+1)], [])
sage: PF = Poset([f, lambda x,y: x < y])
sage: PF.is_isomorphic(A.intersection_poset())
sage: PF = Poset([f, lambda x, y: x < y]) # optional - sage.combinat
sage: PF.is_isomorphic(A.intersection_poset()) # optional - sage.combinat
True
"""
if not self.is_central():
Expand Down
2 changes: 1 addition & 1 deletion src/sage/geometry/linear_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def evaluate(self, point):
9
sage: ex([1,1]) # syntactic sugar
9
sage: ex([pi, e])
sage: ex([pi, e]) # optional - sage.symbolic
2*pi + 3*e + 4
"""
try:
Expand Down
2 changes: 1 addition & 1 deletion src/sage/geometry/polyhedral_complex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
# sage.doctest: optional - sage.graphs
r"""
Finite polyhedral complexes

Expand Down
6 changes: 3 additions & 3 deletions src/sage/geometry/polyhedron/backend_number_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ def _init_from_Vrepresentation(self, vertices, rays, lines,

Check that the coordinates of a vertex get simplified in the Symbolic Ring::

sage: p = Polyhedron(ambient_dim=2, base_ring=SR, backend='number_field')
sage: p = Polyhedron(ambient_dim=2, base_ring=SR, backend='number_field') # optional - sage.symbolic
sage: from sage.geometry.polyhedron.backend_number_field import Polyhedron_number_field
sage: Polyhedron_number_field._init_from_Vrepresentation(p, [(0,1/2),(sqrt(2),0),(4,5/6)], [], []); p
sage: Polyhedron_number_field._init_from_Vrepresentation(p, [(0,1/2),(sqrt(2),0),(4,5/6)], [], []); p # optional - sage.symbolic
A 2-dimensional polyhedron in (Symbolic Ring)^2 defined as the convex hull of 3 vertices
sage: p.vertices()[0][0]
sage: p.vertices()[0][0] # optional - sage.symbolic
0
"""
(vertices, rays, lines), internal_base_ring \
Expand Down
Loading