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

Commit

Permalink
doctest for 'induced_rational'
Browse files Browse the repository at this point in the history
  • Loading branch information
mo271 committed Jul 17, 2017
1 parent 5b68b13 commit 5f452f5
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/sage/geometry/polyhedron/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4376,6 +4376,23 @@ def volume(self, measure='ambient', engine='auto', **kwds):
sage: [polytopes.simplex(d).volume(measure='induced') for d in range(1,5)] == [sqrt(d+1)/factorial(d) for d in range(1,5)]
True
sage: I = Polyhedron([[-3, 0], [0, 9]])
sage: I.volume(measure='induced')
3*sqrt(10)
sage: I.volume(measure='induced_rational')
3
sage: T = Polyhedron([[3, 0, 0], [0, 4, 0], [0, 0, 5]])
sage: T.volume(measure='induced')
1/2*sqrt(769)
sage: T.volume(measure='induced_rational')
1/2
sage: P = Polyhedron(vertices=[(0, 0, 1, 1), (0, 1, 1, 0), (1, 1, 0, 0)])
sage: P.volume(measure='induced')
1
sage: P.volume(measure='induced_rational')
1/2
"""
if measure == 'induced_rational' and engine not in ['auto', 'latte']:
raise TypeError("The induced rational measure can only be computed with the engine set to `auto` or `latte`")
Expand All @@ -4393,19 +4410,18 @@ def volume(self, measure='ambient', engine='auto', **kwds):
pc = triangulation.point_configuration()
return sum([pc.volume(simplex) for simplex in triangulation]) / ZZ(self.dim()).factorial()
elif measure == 'induced':
#if polyhedron is actually full-dimensional, return volume with ambient measuren
# if polyhedron is actually full-dimensional, return volume with ambient measuren
if self.dim() == self.ambient_dim():
return self.volume(measure='ambient', engine=engine, **kwds)
#use an orthogonal transformation, which preserves volume up to a factor provided by the transformation matrix
A,b = self.affine_hull(orthogonal=True, as_affine_map=True)
Adet = (A.matrix().transpose()*A.matrix()).det()
return self.affine_hull(orthogonal=True).volume(measure='ambient', engine=engine, **kwds)/sqrt(Adet)
# use an orthogonal transformation, which preserves volume up to a factor provided by the transformation matrix
A, b = self.affine_hull(orthogonal=True, as_affine_map=True)
Adet = (A.matrix().transpose() * A.matrix()).det()
return self.affine_hull(orthogonal=True).volume(measure='ambient', engine=engine, **kwds) / sqrt(Adet)
elif measure == 'induced_rational':
if self.dim() < self.ambient_dim() and engine != 'latte':
raise TypeError("The induced rational measure can only be computed with the engine set to `auto` or `latte`")
return self._volume_latte(**kwds)


def integrate(self, polynomial, **kwds):
r"""
Return the integral of a polynomial over a polytope.
Expand Down

0 comments on commit 5f452f5

Please sign in to comment.