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: Add some # optional, reformat doctests #35586

Merged
merged 7 commits into from
May 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
440 changes: 220 additions & 220 deletions src/sage/geometry/cone.py

Large diffs are not rendered by default.

95 changes: 51 additions & 44 deletions src/sage/geometry/fan.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
# sage.doctest: optional - sage.graphs sage.combinat
r"""
Rational polyhedral fans

Expand Down Expand Up @@ -503,12 +503,12 @@ def Fan(cones, rays=None, lattice=None, check=True, normalize=True,
sage: fan = Fan([c1, c2], allow_arrangement=True)
sage: fan.ngenerating_cones()
7
sage: fan.plot() # optional - sage.plot
sage: fan.plot() # optional - sage.plot
Graphics3d Object

Cones of different dimension::

sage: c1 = Cone([(1,0),(0,1)])
sage: c1 = Cone([(1,0), (0,1)])
sage: c2 = Cone([(2,1)])
sage: c3 = Cone([(-1,-2)])
sage: fan = Fan([c1, c2, c3], allow_arrangement=True)
Expand All @@ -523,7 +523,7 @@ def Fan(cones, rays=None, lattice=None, check=True, normalize=True,
sage: c3 = Cone([[0, 1, 1], [1, 0, 1], [0, -1, 1], [-1, 0, 1]])
sage: c1 = Cone([[0, 0, 1]])
sage: fan1 = Fan([c1, c3], allow_arrangement=True)
sage: fan1.plot() # optional - sage.plot
sage: fan1.plot() # optional - sage.plot
Graphics3d Object

A 3-d cone and two 2-d cones::
Expand Down Expand Up @@ -1617,17 +1617,17 @@ def support_contains(self, *args):
True
sage: f.support_contains((-1,0))
False
sage: f.support_contains(f.lattice().dual()(1,0)) #random output (warning)
sage: f.support_contains(f.lattice().dual()(1,0)) # random output (warning)
False
sage: f.support_contains(f.lattice().dual()(1,0))
False
sage: f.support_contains(1)
False
sage: f.support_contains(0) # 0 converts to the origin in the lattice
True
sage: f.support_contains(1/2, sqrt(3))
sage: f.support_contains(1/2, sqrt(3)) # optional - sage.symbolic
True
sage: f.support_contains(-1/2, sqrt(3))
sage: f.support_contains(-1/2, sqrt(3)) # optional - sage.symbolic
False
"""
if len(args) == 1:
Expand Down Expand Up @@ -1668,10 +1668,10 @@ def cartesian_product(self, other, lattice=None):
EXAMPLES::

sage: K = ToricLattice(1, 'K')
sage: fan1 = Fan([[0],[1]],[(1,),(-1,)], lattice=K)
sage: fan1 = Fan([[0],[1]], [(1,),(-1,)], lattice=K)
sage: L = ToricLattice(2, 'L')
sage: fan2 = Fan(rays=[(1,0),(0,1),(-1,-1)],
....: cones=[[0,1],[1,2],[2,0]], lattice=L)
sage: fan2 = Fan(rays=[(1,0), (0,1), (-1,-1)],
....: cones=[[0,1], [1,2], [2,0]], lattice=L)
sage: fan1.cartesian_product(fan2)
Rational polyhedral fan in 3-d lattice K+L
sage: _.ngenerating_cones()
Expand Down Expand Up @@ -1733,14 +1733,14 @@ def common_refinement(self, other):

Refining a fan with itself gives itself::

sage: F0 = Fan2d([(1,0),(0,1),(-1,0),(0,-1)])
sage: F0 = Fan2d([(1,0), (0,1), (-1,0), (0,-1)])
sage: F0.common_refinement(F0) == F0
True

A more complex example with complete fans::

sage: F1 = Fan([[0],[1]],[(1,),(-1,)])
sage: F2 = Fan2d([(1,0),(1,1),(0,1),(-1,0),(0,-1)])
sage: F1 = Fan([[0],[1]], [(1,),(-1,)])
sage: F2 = Fan2d([(1,0), (1,1), (0,1), (-1,0), (0,-1)])
sage: F3 = F2.cartesian_product(F1)
sage: F4 = F1.cartesian_product(F2)
sage: FF = F3.common_refinement(F4)
Expand All @@ -1753,8 +1753,8 @@ def common_refinement(self, other):

An example with two non-complete fans with the same support::

sage: F5 = Fan2d([(1,0),(1,2),(0,1)])
sage: F6 = Fan2d([(1,0),(2,1),(0,1)])
sage: F5 = Fan2d([(1,0), (1,2), (0,1)])
sage: F6 = Fan2d([(1,0), (2,1), (0,1)])
sage: F5.common_refinement(F6).ngenerating_cones()
3

Expand Down Expand Up @@ -1997,7 +1997,7 @@ def cone_containing(self, *points):
TESTS::

sage: fan = Fan(cones=[(0,1,2,3), (0,1,4)],
....: rays=[(1,1,1), (1,-1,1), (1,-1,-1), (1,1,-1), (0,0,1)])
....: rays=[(1,1,1), (1,-1,1), (1,-1,-1), (1,1,-1), (0,0,1)])
sage: fan.cone_containing(0).rays()
N(1, 1, 1)
in 3-d lattice N
Expand Down Expand Up @@ -2525,18 +2525,18 @@ def vertex_graph(self):

EXAMPLES::

sage: dP8 = toric_varieties.dP8() # optional - palp sage.graphs
sage: g = dP8.fan().vertex_graph(); g # optional - palp sage.graphs
sage: dP8 = toric_varieties.dP8() # optional - palp sage.graphs
sage: g = dP8.fan().vertex_graph(); g # optional - palp sage.graphs
Graph on 4 vertices
sage: set(dP8.fan(1)) == set(g.vertices(sort=False)) # optional - palp sage.graphs
sage: set(dP8.fan(1)) == set(g.vertices(sort=False)) # optional - palp sage.graphs
True
sage: g.edge_labels() # all edge labels the same since every cone is smooth # optional - palp sage.graphs
[(1, 0), (1, 0), (1, 0), (1, 0)]

sage: g = toric_varieties.Cube_deformation(10).fan().vertex_graph() # optional - sage.graphs
sage: g.automorphism_group().order() # optional - sage.graphs sage.groups
sage: g = toric_varieties.Cube_deformation(10).fan().vertex_graph() # optional - sage.graphs
sage: g.automorphism_group().order() # optional - sage.graphs sage.groups
48
sage: g.automorphism_group(edge_labels=True).order() # optional - sage.graphs sage.groups
sage: g.automorphism_group(edge_labels=True).order() # optional - sage.graphs sage.groups
4
"""
from sage.geometry.cone import classify_cone_2d
Expand Down Expand Up @@ -2697,7 +2697,7 @@ def is_isomorphic(self, other) -> bool:
sage: rays = ((1, 1), (0, 1), (-1, -1), (1, 0))
sage: cones = [(0,1), (1,2), (2,3), (3,0)]
sage: fan1 = Fan(cones, rays)
sage: m = matrix([[-2,3],[1,-1]])
sage: m = matrix([[-2,3], [1,-1]])
sage: fan2 = Fan(cones, [vector(r)*m for r in rays])
sage: fan1.is_isomorphic(fan2)
True
Expand Down Expand Up @@ -2799,7 +2799,7 @@ def isomorphism(self, other):
sage: rays = ((1, 1), (0, 1), (-1, -1), (3, 1))
sage: cones = [(0,1), (1,2), (2,3), (3,0)]
sage: fan1 = Fan(cones, rays)
sage: m = matrix([[-2,3],[1,-1]])
sage: m = matrix([[-2,3], [1,-1]])
sage: fan2 = Fan(cones, [vector(r)*m for r in rays])

sage: fan1.isomorphism(fan2)
Expand Down Expand Up @@ -3190,7 +3190,8 @@ def primitive_collections(self):

EXAMPLES::

sage: fan = Fan([[0,1,3],[3,4],[2,0],[1,2,4]], [(-3, -2, 1), (0, 0, 1), (3, -2, 1), (-1, -1, 1), (1, -1, 1)])
sage: fan = Fan([[0,1,3], [3,4], [2,0], [1,2,4]],
....: [(-3, -2, 1), (0, 0, 1), (3, -2, 1), (-1, -1, 1), (1, -1, 1)])
sage: fan.primitive_collections()
[frozenset({0, 4}),
frozenset({2, 3}),
Expand Down Expand Up @@ -3250,9 +3251,11 @@ def Stanley_Reisner_ideal(self, ring):

EXAMPLES::

sage: fan = Fan([[0,1,3],[3,4],[2,0],[1,2,4]], [(-3, -2, 1), (0, 0, 1), (3, -2, 1), (-1, -1, 1), (1, -1, 1)])
sage: fan.Stanley_Reisner_ideal( PolynomialRing(QQ,5,'A, B, C, D, E') )
Ideal (A*E, C*D, A*B*C, B*D*E) of Multivariate Polynomial Ring in A, B, C, D, E over Rational Field
sage: fan = Fan([[0,1,3], [3,4], [2,0], [1,2,4]],
....: [(-3, -2, 1), (0, 0, 1), (3, -2, 1), (-1, -1, 1), (1, -1, 1)])
sage: fan.Stanley_Reisner_ideal(PolynomialRing(QQ, 5, 'A, B, C, D, E'))
Ideal (A*E, C*D, A*B*C, B*D*E) of
Multivariate Polynomial Ring in A, B, C, D, E over Rational Field
"""
generators_indices = self.primitive_collections()
return ring.ideal([prod([ring.gen(i) for i in sr])
Expand All @@ -3274,9 +3277,11 @@ def linear_equivalence_ideal(self, ring):

EXAMPLES::

sage: fan = Fan([[0,1,3],[3,4],[2,0],[1,2,4]], [(-3, -2, 1), (0, 0, 1), (3, -2, 1), (-1, -1, 1), (1, -1, 1)])
sage: fan.linear_equivalence_ideal( PolynomialRing(QQ,5,'A, B, C, D, E') )
Ideal (-3*A + 3*C - D + E, -2*A - 2*C - D - E, A + B + C + D + E) of Multivariate Polynomial Ring in A, B, C, D, E over Rational Field
sage: fan = Fan([[0,1,3],[3,4],[2,0],[1,2,4]],
....: [(-3, -2, 1), (0, 0, 1), (3, -2, 1), (-1, -1, 1), (1, -1, 1)])
sage: fan.linear_equivalence_ideal(PolynomialRing(QQ, 5, 'A, B, C, D, E'))
Ideal (-3*A + 3*C - D + E, -2*A - 2*C - D - E, A + B + C + D + E) of
Multivariate Polynomial Ring in A, B, C, D, E over Rational Field
"""
gens = []
for d in range(self.dim()):
Expand Down Expand Up @@ -3317,7 +3322,8 @@ def oriented_boundary(self, cone):
sage: fan = toric_varieties.P(3).fan() # optional - palp
sage: cone = fan(2)[0] # optional - palp
sage: bdry = fan.oriented_boundary(cone); bdry # optional - palp
-1-d cone of Rational polyhedral fan in 3-d lattice N + 1-d cone of Rational polyhedral fan in 3-d lattice N
-1-d cone of Rational polyhedral fan in 3-d lattice N
+ 1-d cone of Rational polyhedral fan in 3-d lattice N
sage: bdry[0] # optional - palp
(-1, 1-d cone of Rational polyhedral fan in 3-d lattice N)
sage: bdry[1] # optional - palp
Expand Down Expand Up @@ -3499,22 +3505,23 @@ def complex(self, base_ring=ZZ, extended=False):

EXAMPLES::

sage: fan = toric_varieties.P(3).fan() # optional - palp
sage: K_normal = fan.complex(); K_normal # optional - palp
sage: fan = toric_varieties.P(3).fan() # optional - palp
sage: K_normal = fan.complex(); K_normal # optional - palp
Chain complex with at most 4 nonzero terms over Integer Ring
sage: K_normal.homology() # optional - palp
sage: K_normal.homology() # optional - palp
{0: Z, 1: 0, 2: 0, 3: 0}
sage: K_extended = fan.complex(extended=True); K_extended # optional - palp
sage: K_extended = fan.complex(extended=True); K_extended # optional - palp
Chain complex with at most 5 nonzero terms over Integer Ring
sage: K_extended.homology() # optional - palp
sage: K_extended.homology() # optional - palp
{-1: 0, 0: 0, 1: 0, 2: 0, 3: 0}

Homology computations are much faster over `\QQ` if you do not
care about the torsion coefficients::

sage: toric_varieties.P2_123().fan().complex(extended=True, base_ring=QQ) # optional - palp
sage: toric_varieties.P2_123().fan().complex(extended=True, # optional - palp
....: base_ring=QQ)
Chain complex with at most 4 nonzero terms over Rational Field
sage: _.homology() # optional - palp
sage: _.homology() # optional - palp
{-1: Vector space of dimension 0 over Rational Field,
0: Vector space of dimension 0 over Rational Field,
1: Vector space of dimension 0 over Rational Field,
Expand Down Expand Up @@ -3542,15 +3549,15 @@ def complex(self, base_ring=ZZ, extended=False):
Things get more complicated for non-complete fans::

sage: fan = Fan([Cone([(1,1,1)]),
....: Cone([(1,0,0),(0,1,0)]),
....: Cone([(-1,0,0),(0,-1,0),(0,0,-1)])])
....: Cone([(1,0,0), (0,1,0)]),
....: Cone([(-1,0,0), (0,-1,0), (0,0,-1)])])
sage: fan.complex().homology()
{0: 0, 1: 0, 2: Z x Z, 3: 0}
sage: fan = Fan([Cone([(1,0,0),(0,1,0)]),
....: Cone([(-1,0,0),(0,-1,0),(0,0,-1)])])
sage: fan = Fan([Cone([(1,0,0), (0,1,0)]),
....: Cone([(-1,0,0), (0,-1,0), (0,0,-1)])])
sage: fan.complex().homology()
{0: 0, 1: 0, 2: Z, 3: 0}
sage: fan = Fan([Cone([(-1,0,0),(0,-1,0),(0,0,-1)])])
sage: fan = Fan([Cone([(-1,0,0), (0,-1,0), (0,0,-1)])])
sage: fan.complex().homology()
{0: 0, 1: 0, 2: 0, 3: 0}
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/geometry/fan_isomorphism.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def find_isomorphism(fan1, fan2, check=False):
sage: fan2 = Fan(cones, [vector(r)*m for r in rays])

sage: from sage.geometry.fan_isomorphism import find_isomorphism
sage: find_isomorphism(fan1, fan2, check=True)
sage: find_isomorphism(fan1, fan2, check=True) # optional - sage.graphs
Fan morphism defined by the matrix
[-2 3]
[ 1 -1]
Expand Down
15 changes: 8 additions & 7 deletions src/sage/geometry/fan_morphism.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# sage.doctest: optional - sage.graphs, sage.combinat
r"""
Morphisms between toric lattices compatible with fans

Expand Down Expand Up @@ -360,7 +361,7 @@ def _RISGIS(self):
sage: normal = NormalFan(diamond)
sage: N = face.lattice()
sage: fm = FanMorphism(identity_matrix(2),
....: normal, face, subdivide=True)
....: normal, face, subdivide=True)
sage: fm._RISGIS()
(frozenset({2}),
frozenset({3}),
Expand Down Expand Up @@ -774,7 +775,7 @@ def _support_error(self):
sage: quadrant = Fan([quadrant])
sage: quadrant_bl = quadrant.subdivide([(1,1)])
sage: fm = FanMorphism(identity_matrix(2),
....: quadrant, quadrant_bl, check=False)
....: quadrant, quadrant_bl, check=False)

Now we report that the morphism is invalid::

Expand Down Expand Up @@ -861,8 +862,8 @@ def _validate(self):

TESTS::

sage: trivialfan2 = Fan([],[],lattice=ToricLattice(2))
sage: trivialfan3 = Fan([],[],lattice=ToricLattice(3))
sage: trivialfan2 = Fan([], [], lattice=ToricLattice(2))
sage: trivialfan3 = Fan([], [], lattice=ToricLattice(3))
sage: FanMorphism(zero_matrix(2,3), trivialfan2, trivialfan3)
Fan morphism defined by the matrix
[0 0 0]
Expand Down Expand Up @@ -983,7 +984,7 @@ def image_cone(self, cone):
sage: normal = NormalFan(diamond)
sage: N = face.lattice()
sage: fm = FanMorphism(identity_matrix(2),
....: normal, face, subdivide=True)
....: normal, face, subdivide=True)
sage: fm.image_cone(Cone([(1,0)]))
1-d cone of Rational polyhedral fan in 2-d lattice N
sage: fm.image_cone(Cone([(1,1)]))
Expand Down Expand Up @@ -1855,8 +1856,8 @@ def factor(self):
sage: phi_i.codomain_fan() is phi.codomain_fan() # optional - palp
True

sage: trivialfan2 = Fan([],[],lattice=ToricLattice(2))
sage: trivialfan3 = Fan([],[],lattice=ToricLattice(3))
sage: trivialfan2 = Fan([], [], lattice=ToricLattice(2))
sage: trivialfan3 = Fan([], [], lattice=ToricLattice(3))
sage: f = FanMorphism(zero_matrix(2,3), trivialfan2, trivialfan3)
sage: [phi.matrix().dimensions() for phi in f.factor()]
[(0, 3), (0, 0), (2, 0)]
Expand Down
6 changes: 2 additions & 4 deletions src/sage/geometry/hasse_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,9 @@ def lattice_from_incidences(atom_to_coatoms, coatom_to_atoms,
and we can compute the lattice as ::

sage: from sage.geometry.cone import lattice_from_incidences
sage: L = lattice_from_incidences(
....: atom_to_coatoms, coatom_to_atoms)
sage: L
sage: L = lattice_from_incidences(atom_to_coatoms, coatom_to_atoms); L # optional - sage.graphs
Finite lattice containing 8 elements with distinguished linear extension
sage: for level in L.level_sets(): print(level)
sage: for level in L.level_sets(): print(level) # optional - sage.graphs
[((), (0, 1, 2))]
[((0,), (0, 1)), ((1,), (0, 2)), ((2,), (1, 2))]
[((0, 1), (0,)), ((0, 2), (1,)), ((1, 2), (2,))]
Expand Down
Loading