Interface to LattE integrale programs

sage.interfaces.latte.count(arg, ehrhart_polynomial=False, multivariate_generating_function=False, raw_output=False, verbose=False, **kwds)[source]

Call to the program count from LattE integrale.

INPUT:

  • arg – a cdd or LattE description string

  • ehrhart_polynomial, multivariate_generating_function – to compute Ehrhart polynomial or multivariate generating function instead of just counting points

  • raw_output – if True then return directly the output string from LattE

  • For all other options of the count program, consult the LattE manual

  • name – – (default: 'y') a string

    The variable names of the Laurent polynomial ring of the multivariate_generating_function

  • Factorization_sort (default: False) and Factorization_simplify (default: False) – booleans

    These are passed on to sage.structure.factorization.Factorization when creating the result.

OUTPUT:

Either a string (if raw_output if set to True) or an integer (when counting points), or a polynomial (if ehrhart_polynomial is set to True) or a tuple of Factorization objects Factorization whose factors are Laurent polynomials (if multivariate_generating_function is set to True)

EXAMPLES:

sage: from sage.interfaces.latte import count
sage: P = 2 * polytopes.cube()
>>> from sage.all import *
>>> from sage.interfaces.latte import count
>>> P = Integer(2) * polytopes.cube()

Counting integer points from either the H or V representation:

sage: count(P.cdd_Hrepresentation(), cdd=True)      # optional - latte_int
125
sage: count(P.cdd_Vrepresentation(), cdd=True)      # optional - latte_int
125
>>> from sage.all import *
>>> count(P.cdd_Hrepresentation(), cdd=True)      # optional - latte_int
125
>>> count(P.cdd_Vrepresentation(), cdd=True)      # optional - latte_int
125

Ehrhart polynomial:

sage: count(P.cdd_Hrepresentation(), cdd=True,      # optional - latte_int
....:       ehrhart_polynomial=True)
64*t^3 + 48*t^2 + 12*t + 1
>>> from sage.all import *
>>> count(P.cdd_Hrepresentation(), cdd=True,      # optional - latte_int
...       ehrhart_polynomial=True)
64*t^3 + 48*t^2 + 12*t + 1

Returning a string of the multivariate generating function when raw_output=True. Returning the summands of the multivariate generating function in a tuple of Factorization objects with the same format as sage.geometry.polyhedron.generating_function.generating_function_of_integral_points() does when result_as_tuple=True:

sage: opts = {'cdd': True,
....:         'multivariate_generating_function': True,
....:         'raw_output': True}
sage: cddin = P.cdd_Hrepresentation()
sage: print(count(cddin, **opts))                                       # optional - latte_int
x[0]^2*x[1]^(-2)*x[2]^(-2)/((1-x[1])*(1-x[2])*(1-x[0]^(-1)))
 + x[0]^(-2)*x[1]^(-2)*x[2]^(-2)/((1-x[1])*(1-x[2])*(1-x[0]))
 + x[0]^2*x[1]^(-2)*x[2]^2/((1-x[1])*(1-x[2]^(-1))*(1-x[0]^(-1)))
 + x[0]^(-2)*x[1]^(-2)*x[2]^2/((1-x[1])*(1-x[0])*(1-x[2]^(-1)))
 + x[0]^2*x[1]^2*x[2]^(-2)/((1-x[2])*(1-x[1]^(-1))*(1-x[0]^(-1)))
 + x[0]^(-2)*x[1]^2*x[2]^(-2)/((1-x[2])*(1-x[0])*(1-x[1]^(-1)))
 + x[0]^2*x[1]^2*x[2]^2/((1-x[2]^(-1))*(1-x[1]^(-1))*(1-x[0]^(-1)))
 + x[0]^(-2)*x[1]^2*x[2]^2/((1-x[0])*(1-x[2]^(-1))*(1-x[1]^(-1)))
sage: count(cddin, cdd=True, multivariate_generating_function=True)     # optional - latte_int
((y0^2*y1^-2*y2^-2) * (-y1 + 1)^-1 * (-y2 + 1)^-1 * (1 - y0^-1)^-1,
 (y0^-2*y1^-2*y2^-2) * (-y1 + 1)^-1 * (-y2 + 1)^-1 * (-y0 + 1)^-1,
 (y0^2*y1^-2*y2^2) * (-y1 + 1)^-1 * (1 - y2^-1)^-1 * (1 - y0^-1)^-1,
 (y0^-2*y1^-2*y2^2) * (-y1 + 1)^-1 * (-y0 + 1)^-1 * (1 - y2^-1)^-1,
 (y0^2*y1^2*y2^-2) * (-y2 + 1)^-1 * (1 - y1^-1)^-1 * (1 - y0^-1)^-1,
 (y0^-2*y1^2*y2^-2) * (-y2 + 1)^-1 * (-y0 + 1)^-1 * (1 - y1^-1)^-1,
 y0^2*y1^2*y2^2 * (1 - y2^-1)^-1 * (1 - y1^-1)^-1 * (1 - y0^-1)^-1,
 (y0^-2*y1^2*y2^2) * (-y0 + 1)^-1 * (1 - y2^-1)^-1 * (1 - y1^-1)^-1)
>>> from sage.all import *
>>> opts = {'cdd': True,
...         'multivariate_generating_function': True,
...         'raw_output': True}
>>> cddin = P.cdd_Hrepresentation()
>>> print(count(cddin, **opts))                                       # optional - latte_int
x[0]^2*x[1]^(-2)*x[2]^(-2)/((1-x[1])*(1-x[2])*(1-x[0]^(-1)))
 + x[0]^(-2)*x[1]^(-2)*x[2]^(-2)/((1-x[1])*(1-x[2])*(1-x[0]))
 + x[0]^2*x[1]^(-2)*x[2]^2/((1-x[1])*(1-x[2]^(-1))*(1-x[0]^(-1)))
 + x[0]^(-2)*x[1]^(-2)*x[2]^2/((1-x[1])*(1-x[0])*(1-x[2]^(-1)))
 + x[0]^2*x[1]^2*x[2]^(-2)/((1-x[2])*(1-x[1]^(-1))*(1-x[0]^(-1)))
 + x[0]^(-2)*x[1]^2*x[2]^(-2)/((1-x[2])*(1-x[0])*(1-x[1]^(-1)))
 + x[0]^2*x[1]^2*x[2]^2/((1-x[2]^(-1))*(1-x[1]^(-1))*(1-x[0]^(-1)))
 + x[0]^(-2)*x[1]^2*x[2]^2/((1-x[0])*(1-x[2]^(-1))*(1-x[1]^(-1)))
>>> count(cddin, cdd=True, multivariate_generating_function=True)     # optional - latte_int
((y0^2*y1^-2*y2^-2) * (-y1 + 1)^-1 * (-y2 + 1)^-1 * (1 - y0^-1)^-1,
 (y0^-2*y1^-2*y2^-2) * (-y1 + 1)^-1 * (-y2 + 1)^-1 * (-y0 + 1)^-1,
 (y0^2*y1^-2*y2^2) * (-y1 + 1)^-1 * (1 - y2^-1)^-1 * (1 - y0^-1)^-1,
 (y0^-2*y1^-2*y2^2) * (-y1 + 1)^-1 * (-y0 + 1)^-1 * (1 - y2^-1)^-1,
 (y0^2*y1^2*y2^-2) * (-y2 + 1)^-1 * (1 - y1^-1)^-1 * (1 - y0^-1)^-1,
 (y0^-2*y1^2*y2^-2) * (-y2 + 1)^-1 * (-y0 + 1)^-1 * (1 - y1^-1)^-1,
 y0^2*y1^2*y2^2 * (1 - y2^-1)^-1 * (1 - y1^-1)^-1 * (1 - y0^-1)^-1,
 (y0^-2*y1^2*y2^2) * (-y0 + 1)^-1 * (1 - y2^-1)^-1 * (1 - y1^-1)^-1)
sage.interfaces.latte.integrate(arg, polynomial=None, algorithm='triangulate', raw_output=False, verbose=False, **kwds)[source]

Call to the function integrate from LattE integrale.

INPUT:

  • arg – a cdd or LattE description string

  • polynomial – multivariate polynomial or valid LattE polynomial description string If given, the valuation parameter of LattE is set to integrate, and is set to volume otherwise

  • algorithm – (default: 'triangulate') the integration method; use ‘triangulate’ for polytope triangulation or ‘cone-decompose’ for tangent cone decomposition method

  • raw_output – if True then return directly the output string from LattE

  • verbose – if True then return directly verbose output from LattE

  • For all other options of the integrate program, consult the LattE manual

OUTPUT: either a string (if raw_output if set to True) or a rational

EXAMPLES:

sage: from sage.interfaces.latte import integrate
sage: P = 2 * polytopes.cube()
sage: x, y, z = polygen(QQ, 'x, y, z')
>>> from sage.all import *
>>> from sage.interfaces.latte import integrate
>>> P = Integer(2) * polytopes.cube()
>>> x, y, z = polygen(QQ, 'x, y, z')

Integrating over a polynomial over a polytope in either the H or V representation:

sage: integrate(P.cdd_Hrepresentation(), x^2*y^2*z^2, cdd=True)         # optional - latte_int
4096/27
sage: integrate(P.cdd_Vrepresentation(), x^2*y^2*z^2, cdd=True)         # optional - latte_int
4096/27
>>> from sage.all import *
>>> integrate(P.cdd_Hrepresentation(), x**Integer(2)*y**Integer(2)*z**Integer(2), cdd=True)         # optional - latte_int
4096/27
>>> integrate(P.cdd_Vrepresentation(), x**Integer(2)*y**Integer(2)*z**Integer(2), cdd=True)         # optional - latte_int
4096/27

Computing the volume of a polytope in either the H or V representation:

sage: integrate(P.cdd_Hrepresentation(), cdd=True)                      # optional - latte_int
64
sage: integrate(P.cdd_Vrepresentation(), cdd=True)                      # optional - latte_int
64
>>> from sage.all import *
>>> integrate(P.cdd_Hrepresentation(), cdd=True)                      # optional - latte_int
64
>>> integrate(P.cdd_Vrepresentation(), cdd=True)                      # optional - latte_int
64

Polynomials given as a string in LattE description are also accepted:

sage: integrate(P.cdd_Hrepresentation(), '[[1,[2,2,2]]]', cdd=True)     # optional - latte_int
4096/27
>>> from sage.all import *
>>> integrate(P.cdd_Hrepresentation(), '[[1,[2,2,2]]]', cdd=True)     # optional - latte_int
4096/27
sage.interfaces.latte.str_to_multivariate_generating_function(raw_output_str, name=None, **kwds)[source]

Helper function for count() if multivariate_generating_function is set to True which preprocess the raw output string to a tuple of summands.

sage.interfaces.latte.to_latte_polynomial(polynomial)[source]

Helper function to transform a polynomial to its LattE description.

INPUT:

  • polynomial – a multivariate polynomial

OUTPUT: string that describes the monomials list and exponent vectors