Very long time ago
polytope.py (by William Stein) - basic interface to Polymake.
Polymake: not terribly difficult to build, but took half the time and half the size of the whole Sage to do it - no question about making Polymake a standard package.
Long time ago
lattice_polytope.py (by A.N.) with the original goal to use PALP conveniently and interactively on single polytopes.
PALP is small and easy to build, was included right away.
Used via files/system calls.
{{{id=1|
%time
simplex = LatticePolytope([(1,0), (0,1), (-1,-1)])
simplex
///
CPU time: 0.04 s, Wall time: 0.07 s
}}}
{{{id=3|
%time
simplex.poly_x("p")
///
CPU time: 0.01 s, Wall time: 0.02 s
}}}
{{{id=4|
%time
simplex.points()
///
CPU time: 0.00 s, Wall time: 0.00 s
}}}
{{{id=5|
simplex.nef_x("-N -P -p")
///
}}}
{{{id=6|
simplex.nef_partitions()
///
}}}
{{{id=7|
simplex.plot3d()
///
}}}
{{{id=8|
simplex.polar().plot3d()
///
}}}
{{{id=28|
///
}}}
Still long time ago
polyhedra.py (by Marshal Hampton) - file-based (?) interface to cdd
Allows working with generic polyhedra, i.e. non-integer points, unbounded.
Rewritten by Volker Braun. Rewrite is now gone.
A few years ago
Cones for toric geometry - not special cases of polyhedra.
Toric lattices, fans, fan morphisms. Written and cross-reviewed by Volker Braun and A.N.
Most "polyhedral operations" use library interface to PPL (by Volker Braun).
{{{id=9|
N = ToricLattice(2)
N
///
}}}
{{{id=11|
M = N.dual()
M
///
}}}
{{{id=79|
M.dual()
///
}}}
{{{id=12|
M.plot()
///
}}}
{{{id=13|
sigma0 = Cone([(1/2,0), (0,2)], lattice=N)
sigma0
///
}}}
{{{id=14|
sigma0.rays()
///
}}}
{{{id=15|
sigma0.plot()
///
}}}
{{{id=16|
sigma1 = Cone([(0,1), (-1, -1)])
sigma2 = Cone([(-1,-1), (1, 0)])
Sigma = Fan([sigma0, sigma1, sigma2])
Sigma
///
}}}
{{{id=17|
Sigma.rays()
///
}}}
{{{id=55|
Sigma.cone_lattice().plot()
///
}}}
{{{id=18|
Sigma.plot()
///
}}}
{{{id=19|
Sigma.plot(mode="generators")
///
/home/novoselt/sage-5.12.beta5/local/lib/python2.7/site-packages/sage/geometry/toric_plotter.py:634: DeprecationWarning: use the option 'base_ring' instead of 'field'
See http://trac.sagemath.org/11634 for details.
result += Polyhedron(vertices=vertices, field=RDF).render_solid(
}}}
{{{id=20|
Sigma == FaceFan(simplex)
///
}}}
{{{id=21|
Sigma.is_equivalent(FaceFan(simplex))
///
}}}
{{{id=22|
Sigma.is_isomorphic(FaceFan(simplex))
///
}}}
{{{id=80|
Sigma.isomorphism(FaceFan(simplex))
///
}}}
{{{id=23|
Sigma.is_equivalent(NormalFan(simplex.polar()))
///
}}}
{{{id=67|
fm = FanMorphism(2*identity_matrix(2), Fan([sigma0]), Sigma)
fm
///
}}}
{{{id=24|
NormalFan(lattice_polytope.octahedron(3)).plot(mode="generators")
///
}}}
{{{id=29|
for i in sorted(toric_plotter.options().items()):
print i
///
('font_size', 14)
('generator_color', 'blue')
('generator_thickness', None)
('generator_zorder', -3)
('label_color', 'black')
('label_zorder', -1)
('lattice_filter', None)
('mode', 'round')
('point_color', 'black')
('point_size', None)
('point_zorder', -2)
('radius', None)
('ray_color', 'purple')
('ray_label', 'u')
('ray_thickness', 3)
('ray_zorder', -4)
('show_generators', True)
('show_lattice', None)
('show_rays', True)
('show_walls', True)
('wall_alpha', 0.4)
('wall_color', 'rainbow')
('wall_label', '\\sigma')
('wall_zorder', -5)
('xmax', None)
('xmin', None)
('ymax', None)
('ymin', None)
('zmax', None)
('zmin', None)
}}}
{{{id=30|
toric_plotter.options(wall_alpha=1)
///
}}}
{{{id=31|
Sigma.plot()
///
}}}
{{{id=32|
toric_plotter.reset_options()
///
}}}
{{{id=33|
///
}}}
Recent additions by Volker Braun
New rewrite of generic polyhedra allowing different backends: currently PPL and cddlib.
Triangulations (with and without optional package TOPCOM).
Integral points.
ppl_lattice_polytope.py - not as featurefull as LatticePolytope but much faster.
Future (this week?..)
Clean up LatticePolytope code to make backend change possible.
Unify its interface with Cone and Fan, including plotting.
Toric Geometry
{{{id=26|
P2 = ToricVariety(Sigma)
P2
///
}}}
{{{id=34|
P2.plot()
///
}}}
{{{id=35|
P2.coordinate_ring()
///
}}}
Default ring is $\mathbb{Q}$, assumed ring is $\mathbb{C}$, arbitrary one should work in principle.
{{{id=36|
P2.inject_variables()
///
Defining z0, z1, z2
}}}
{{{id=38|
P2.subscheme(z0 + z1^2)
///
Traceback (most recent call last):
File "", line 1, in
File "_sage_input_43.py", line 10, in
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("UDIuc3Vic2NoZW1lKHowICsgejFeMik="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single')
File "", line 1, in
File "/tmp/tmp6svYg2/___code___.py", line 3, in
exec compile(u'P2.subscheme(z0 + z1**_sage_const_2 )' + '\n', '', 'single')
File "", line 1, in
File "/home/novoselt/sage-5.12.beta5/local/lib/python2.7/site-packages/sage/schemes/toric/variety.py", line 1887, in subscheme
return AlgebraicScheme_subscheme_toric(self, polynomials)
File "/home/novoselt/sage-5.12.beta5/local/lib/python2.7/site-packages/sage/schemes/generic/algebraic_scheme.py", line 2148, in __init__
polynomials)
File "/home/novoselt/sage-5.12.beta5/local/lib/python2.7/site-packages/sage/schemes/generic/algebraic_scheme.py", line 937, in __init__
self.__polys = A._validate(polynomials)
File "/home/novoselt/sage-5.12.beta5/local/lib/python2.7/site-packages/sage/schemes/toric/variety.py", line 944, in _validate
raise ValueError("%s is not homogeneous on %s!" % (p, self))
ValueError: z1^2 + z0 is not homogeneous on 2-d toric variety covered by 3 affine patches!
}}}
{{{id=39|
P2.subscheme(z0 + z1)
///
}}}
{{{id=81|
P2.subscheme([z0, z1, z2]).dimension()
///
}}}
{{{id=40|
A2 = AffineToricVariety(sigma0)
f = A2.hom(fm, P2)
f
///
}}}
{{{id=41|
f.as_polynomial_map()
///
}}}
{{{id=49|
for factor in reversed(f.factor()):
factor.as_polynomial_map()
///
}}}
{{{id=42|
print P2
///
2-d toric variety covered by 3 affine patches
}}}
{{{id=43|
P2 = CPRFanoToricVariety(Delta_polar=simplex)
print P2
///
2-d CPR-Fano toric variety covered by 3 affine patches
}}}
{{{id=44|
P2.plot()
///
}}}
{{{id=45|
P2.fan().rays().column_matrix()
///
}}}
{{{id=46|
simplex.vertices()
///
}}}
{{{id=47|
AH = P2.anticanonical_hypersurface()
AH
///
}}}
{{{id=48|
simplex.polar().point(6)
///
}}}
{{{id=68|
AH.ambient_space() is P2
///
}}}
{{{id=69|
AH.ambient_space().coordinate_ring()
///
}}}
{{{id=51|
P2.anticanonical_hypersurface(monomial_points="all")
///
}}}
{{{id=50|
P2P = CPRFanoToricVariety(Delta=simplex, coordinate_points="all")
P2P.plot(generator_color="red", wall_alpha=0.2, ray_thickness=1, generator_thickness=5)
///
}}}
{{{id=52|
P2P.anticanonical_hypersurface(monomial_points="all")
///
}}}
{{{id=54|
D = 1/2*P2P.divisor(prod(P2P.gens()))
D
///
}}}
{{{id=71|
D.is_Cartier()
///
}}}
{{{id=70|
D.is_QQ_Weil()
///
}}}
{{{id=56|
D.cohomology_class()
///
}}}
{{{id=57|
P = D.polyhedron()
P
///
}}}
{{{id=58|
P.plot()
///
}}}
{{{id=59|
P2.Stanley_Reisner_ideal()
///
}}}
{{{id=75|
R = P2.coordinate_ring()
prod(R.ideal([f for f, m in e.factor()]) for e in P2.Stanley_Reisner_ideal().gens())
///
}}}
{{{id=74|
P1xP1 = toric_varieties.P1xP1()
P1xP1.Stanley_Reisner_ideal()
///
}}}
{{{id=76|
R = P1xP1.coordinate_ring()
prod(R.ideal([f for f, m in e.factor()]) for e in P1xP1.Stanley_Reisner_ideal().gens())
///
}}}
{{{id=77|
P1xP1.fan().primitive_collections()
///
}}}
{{{id=61|
P2P.Stanley_Reisner_ideal()
///
}}}
{{{id=73|
raise RuntimeError("You are out of your RAM!")
R = P2P.coordinate_ring()
prod(R.ideal([f for f, m in e.factor()]) for e in P2P.Stanley_Reisner_ideal().gens())
///
Traceback (most recent call last):
File "", line 1, in
File "_sage_input_75.py", line 10, in
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("cmFpc2UgUnVudGltZUVycm9yKCJZb3UgYXJlIG91dCBvZiB5b3VyIFJBTSEiKQpSID0gUDJQLmNvb3JkaW5hdGVfcmluZygpCnByb2QoUi5pZGVhbChbZiBmb3IgZiwgbSBpbiBlLmZhY3RvcigpXSkgZm9yIGUgaW4gUDJQLlN0YW5sZXlfUmVpc25lcl9pZGVhbCgpLmdlbnMoKSk="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single')
File "", line 1, in
File "/tmp/tmpzzhDXm/___code___.py", line 2, in
raise RuntimeError("You are out of your RAM!")
RuntimeError: You are out of your RAM!
}}}
{{{id=78|
///
}}}