Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
reject RDF, but add an example
Browse files Browse the repository at this point in the history
  • Loading branch information
mforets committed Mar 10, 2017
1 parent a563192 commit 9ac8279
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/sage/geometry/polyhedron/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3903,9 +3903,6 @@ def _volume_latte(self, verbose=False, algorithm='triangulate', **kwargs):
- ``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.
Expand Down Expand Up @@ -3955,8 +3952,7 @@ def _volume_latte(self, verbose=False, algorithm='triangulate', **kwargs):
if is_package_installed('latte_int'):
from sage.interfaces.latte import integrate
if self.base_ring() == RDF:
self_QQ = Polyhedron(vertices=[[QQ(vi) for vi in v] for v in self.vertex_generator()])
return integrate(self_QQ.cdd_Hrepresentation(), algorithm=algorithm, cdd=True, verbose=verbose, **kwargs)
raise ValueError("LattE integrale cannot be applied over inexact rings.")
else:
return integrate(self.cdd_Hrepresentation(), algorithm=algorithm, cdd=True, verbose=verbose, **kwargs)

Expand Down Expand Up @@ -4024,6 +4020,8 @@ def volume(self, engine='auto', **kwds):
0
sage: I.volume(engine='lrs') #optional - lrslib
1.0
sage: I.volume(engine='latte') # optional - latte_int
1
"""
if engine == 'lrs':
return self._volume_lrs(**kwds)
Expand Down Expand Up @@ -4065,6 +4063,14 @@ def integrate(self, polynomial, **kwds):
sage: P.integrate(x^2*y^2*z^2) # optional - latte_int
8/27
If the polyhedron has floating point coordinates, an inexact result can
be obtained if we transform to rational coordinates::
sage: P = 1.4142*polytopes.cube()
sage: P_QQ = Polyhedron(vertices = [[QQ(vi) for vi in v] for v in P.vertex_generator()])
sage: RDF(P_QQ.integrate(x^2*y^2*z^2)) # optional - latte_int
6.703841212195228
TESTS::
Testing a three-dimensional integral::
Expand All @@ -4091,15 +4097,16 @@ def integrate(self, polynomial, **kwds):
Testing a polytope with floating point coordinates::
sage: P = Polyhedron(vertices = [[0, 0], [1, 0], [1.1,1.1], [0,1]])
sage: P = Polyhedron(vertices = [[0, 0], [1, 0], [1.1, 1.1], [0, 1]])
sage: P.integrate('[[1,[2,2]]]') # optional - latte_int
384659/2250000
Traceback (most recent call last):
...
TypeError: LattE integrale cannot be applied over inexact rings.
"""
if is_package_installed('latte_int'):
from sage.interfaces.latte import integrate
if self.base_ring() == RDF:
self_QQ = Polyhedron(vertices=[[QQ(vi) for vi in v] for v in self.vertex_generator()])
return integrate(self_QQ.cdd_Hrepresentation(), polynomial, cdd=True)
raise ValueError("LattE integrale cannot be applied over inexact rings.")
else:
return integrate(self.cdd_Hrepresentation(), polynomial, cdd=True)

Expand Down

0 comments on commit 9ac8279

Please sign in to comment.