ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 18 Dec 2018 09:59:52 +0100Global Dependency in Polyhedron Volumehttps://ask.sagemath.org/question/44695/global-dependency-in-polyhedron-volume/ Hi all,
I am new to sage and want to use it in one of my python scripts to calculate the volume of higher dimensional polyhedrons. When executing my script I get a "ZeroDivisionError" for some of the polyhedrons. However when run in an individual script they work perfectly fine as long as there is no other calculation beforehand.
Here is an example, the file is called DebugSageVolume.py and I execute it with "sage -python DebugSageVolume.py" under Ubuntu 18.04, SageMath version 8.1
#!/usr/lib/python2.7/dist-packages/sage -python
from sage.all import *
# this works fine
matrix1 = matrix(RR, [[0, 1, 0, 0, 0], [1, -1, 0, 0, 0],
[0, 0, 1, 0, 0], [1, 0, -1, 0, 0],
[0, 0, 0, 1, 0], [1, 0, 0, -1, 0],
[0, 0, 0, 0, 1], [1, 0, 0, 0, -1],
[0.5, -0.5, -0.5, -0.5, -0.5], [-0.5, 0.5, 0.5, 0.5, 0.5]])
poly1 = Polyhedron(ieqs=matrix1)
volume1 = poly1.volume(measure="induced")
print(volume1)
#this results in an error when executed after the above. But when commenting the above this works fine
matrix2 = matrix(RR, [[0, 1, 0, 0, 0], [1, -1, 0, 0, 0],
[0, 0, 1, 0, 0], [1, 0, -1, 0, 0],
[0, 0, 0, 1, 0], [1, 0, 0, -1, 0],
[0, 0, 0, 0, 1], [1, 0, 0, 0, -1],
[0.75, -0.5, -0.5, -0.5, -0.5], [-0.75, 0.5, 0.5, 0.5, 0.5]])
poly2 = Polyhedron(ieqs=matrix2)
volume2 = poly2.volume(measure="induced")
print(volume2)
Any help would be greatly appreciated, thank you.
MichaelMon, 17 Dec 2018 19:10:30 +0100https://ask.sagemath.org/question/44695/global-dependency-in-polyhedron-volume/Answer by FrédéricC for <p>Hi all,</p>
<p>I am new to sage and want to use it in one of my python scripts to calculate the volume of higher dimensional polyhedrons. When executing my script I get a "ZeroDivisionError" for some of the polyhedrons. However when run in an individual script they work perfectly fine as long as there is no other calculation beforehand.</p>
<p>Here is an example, the file is called DebugSageVolume.py and I execute it with "sage -python DebugSageVolume.py" under Ubuntu 18.04, SageMath version 8.1</p>
<pre><code>#!/usr/lib/python2.7/dist-packages/sage -python
from sage.all import *
# this works fine
matrix1 = matrix(RR, [[0, 1, 0, 0, 0], [1, -1, 0, 0, 0],
[0, 0, 1, 0, 0], [1, 0, -1, 0, 0],
[0, 0, 0, 1, 0], [1, 0, 0, -1, 0],
[0, 0, 0, 0, 1], [1, 0, 0, 0, -1],
[0.5, -0.5, -0.5, -0.5, -0.5], [-0.5, 0.5, 0.5, 0.5, 0.5]])
poly1 = Polyhedron(ieqs=matrix1)
volume1 = poly1.volume(measure="induced")
print(volume1)
#this results in an error when executed after the above. But when commenting the above this works fine
matrix2 = matrix(RR, [[0, 1, 0, 0, 0], [1, -1, 0, 0, 0],
[0, 0, 1, 0, 0], [1, 0, -1, 0, 0],
[0, 0, 0, 1, 0], [1, 0, 0, -1, 0],
[0, 0, 0, 0, 1], [1, 0, 0, 0, -1],
[0.75, -0.5, -0.5, -0.5, -0.5], [-0.75, 0.5, 0.5, 0.5, 0.5]])
poly2 = Polyhedron(ieqs=matrix2)
volume2 = poly2.volume(measure="induced")
print(volume2)
</code></pre>
<p>Any help would be greatly appreciated, thank you.
Michael</p>
https://ask.sagemath.org/question/44695/global-dependency-in-polyhedron-volume/?answer=44704#post-id-44704There is a known issue with volume computations when coefficients are in RR. Try if possible to use coefficients in QQ.
See https://trac.sagemath.org/ticket/18214 for the known bug.Tue, 18 Dec 2018 09:59:52 +0100https://ask.sagemath.org/question/44695/global-dependency-in-polyhedron-volume/?answer=44704#post-id-44704