Skip to content

Add Batyrev's construction of toric varieties to toric library #40270

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
139 changes: 139 additions & 0 deletions src/sage/schemes/toric/batyrev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#!/usr/bin/env sage -python
# IMPORTANT: Place this file outside the Sage source tree (e.g., in a separate project folder).
# Run with Sage's Python: `sage -python batyrev.py` or import in a Sage session after cd into the directory.
import sys
if 'sage' not in sys.executable.lower():
sys.exit("Error: run with Sage's Python (e.g. `sage -python batyrev.py`).")
import sys

Check failure on line 7 in src/sage/schemes/toric/batyrev.py

View workflow job for this annotation

GitHub Actions / pyright

"sys" is imported more than once (reportDuplicateImport)
# Ensure running under Sage Python
if 'sage' not in sys.executable.lower():
sys.exit("Error: Please run this script using Sage's Python (e.g. via `./batyrev.py` or `sage -python batyrev.py`).")

r"""
Library for Batyrev's construction of smooth complete toric varieties of Picard rank 3. [Batyrev1991]
TODO: Batyrev's construction for 18 toric Fano 4-folds [Batyrev1999]
TODO: Batyrev's construction for 123 toric Fano 4-folds [Batyrev1999]
"""


from sage.structure.sage_object import SageObject

from sage.matrix.constructor import matrix
from sage.matrix.special import identity_matrix
from sage.geometry.fan import Fan
from sage.geometry.lattice_polytope import LatticePolytope
from sage.geometry.toric_lattice import ToricLattice
from sage.rings.integer_ring import ZZ
from sage.rings.rational_field import QQ
from sage.arith.misc import GCD as gcd
from sage.schemes.toric.variety import (DEFAULT_PREFIX,
ToricVariety,
normalize_names)

# from sage.schemes.toric.fano_variety import CPRFanoToricVariety AL: so far, seems not used in this work



class BatyrevToricFactory(SageObject):

Check failure on line 37 in src/sage/schemes/toric/batyrev.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (E303)

src/sage/schemes/toric/batyrev.py:37:1: E303 Too many blank lines (3)
r"""
The methods of this class construct Batyrev' classification of smooth and complete toric varieties.`
"""

_check = True # AL: what does this do?

def __init__(self):
self.toric_varieties_rays_cones = {}

def _make_ToricVariety(self, name, coordinate_names, base_ring):
r"""
Construct a toric variety and cache the result.

INPUT:

- ``name`` -- string; one of the pre-defined names in the
``toric_varieties_rays_cones`` data structure

- ``coordinate_names`` -- string describing the names of the
homogeneous coordinates of the toric variety

- ``base_ring`` -- a ring (default: `\QQ`); the base ring for
the toric variety

OUTPUT: a :class:`toric variety
<sage.schemes.toric.variety.ToricVariety_field>`.

EXAMPLES::

sage: toric_varieties.A1() # indirect doctest
1-d affine toric variety
"""
rays, cones = self.toric_varieties_rays_cones[name]
if coordinate_names is None:
dict_key = (name, base_ring)
else:
coordinate_names = normalize_names(coordinate_names, len(rays),
DEFAULT_PREFIX)
dict_key = (name, base_ring) + tuple(coordinate_names)
if dict_key not in self.__dict__:
fan = Fan(cones, rays, check=self._check)
self.__dict__[dict_key] = \
ToricVariety(fan,
coordinate_names=coordinate_names,
base_ring=base_ring)
return self.__dict__[dict_key]

def _make_batyrev_matrix(self, P, B, C):
p0, p1, p2, p3, p4 = P
Cprime = [0] + list(C)
R1 = ([1]*p0) + ([1]*p1) + ([-c for c in Cprime]) + ([-(b+1) for b in B]) + ([0]*p4)
R2 = ([0]*p0) + ([1]*p1) + ([1]*p2) + ([0]*p3) + ([-1]*p4)
R3 = ([0]*p0) + ([0]*p1) + ([1]*p2) + ([1]*p3) + ([0]*p4)
R4 = ([0]*p0) + ([-1]*p1) + ([0]*p2) + ([1]*p3) + ([1]*p4)
R5 = ([1]*p0) + ([0]*p1) + ([-c for c in Cprime]) + ([-b for b in B]) + ([1]*p4)
return matrix(ZZ, [R1, R2, R3, R4, R5])

def add_family(self, name, P, B, C):
"""
Register a family by its Batyrev parameters P, B, C.
P = [p0, p1, p2, p3, p4]
B is a list of length p3
C is a list of length p2 - 1
"""
A = self._make_batyrev_matrix(P, B, C)
K = A.right_kernel()
rays = [v for v in K.basis()]
p0, p1, p2, p3, p4 = P
X0 = list(range(p0))
X1 = list(range(p0, p0+p1))
X2 = list(range(p0+p1, p0+p1+p2))
X3 = list(range(p0+p1+p2, p0+p1+p2+p3))
X4 = list(range(p0+p1+p2+p3, p0+p1+p2+p3+p4))
X5 = X0 + X4
primitive_cols = [X0, X1, X2, X3, X5]
d = len(rays[0])
cones = []
from itertools import combinations
for combo in combinations(range(len(rays)), d):
if any(set(pc) <= set(combo) for pc in primitive_cols):
continue
cones.append(list(combo))
self.toric_varieties_rays_cones[name] = (rays, cones)

def make_variety(self, name, P, B, C, coordinate_names=None, base_ring=QQ):
"""
Convenience method: add the family and return its ToricVariety.
"""
self.add_family(name, P, B, C)
return self._make_ToricVariety(name, coordinate_names, base_ring)

# # instantiate and register example families
# btf = BatyrevToricFactory()
# # rank-3 Fano 3-folds examples
# btf.add_family('Batyrev_3_26', [2,1,1,1,1], [-2], [])
# btf.add_family('Batyrev_3_29', [1,1,1,1,1], [2], [])


if __name__ == '__main__':
# simple test
X = btf.make_variety('Test', [2,1,1,1,1], [-2], [])
print('smooth?', X.is_smooth(), 'rho=', X.picard_number(), 'dim=', X.dimension())
1 change: 1 addition & 0 deletions src/sage/schemes/toric/meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
py.install_sources(
'__init__.py',
'all.py',
'batyrev.py',
'chow_group.py',
'divisor.py',
'fano_variety.py',
Expand Down
Loading