# Volume Automatically Getting Rounded?

Hi All,

I'm trying to use the volume function, but it keeps on rounding.

Ex:

P = Polyhedron([[0,0], [1,1]])

P.volume(measure = 'induced');

Result: 1.414213562373095?

Obviously, the correct volume for this should be sqrt(2) but for some reason, I'm unable to get this exact value? What do I need to change?

edit retag close merge delete

Sort by » oldest newest most voted

The result you get is an algebraic real number:

sage: V = P.volume(measure = 'induced'); V
1.414213562373095?
sage: type(V)
<class 'sage.rings.qqbar.AlgebraicReal'>
sage: V.parent()
Algebraic Real Field


The result is exact, it is just the string representation that contains an approximation with a question mark at the end. (The question mark distinguishes it from an ordinary floating point approximation.)

The number is the root of a polynomial:

sage: V.minpoly()
x^2 - 2


In some cases (like here) you can express the number using radicals:

sage: V.radical_expression()
sqrt(2)

more

so in general, is there a way to get the "radical expression" by default? For example, I am trying to work on a project that will likely include volumes with $\pi$, and it'd be extremely helpful if the volumes came exact and not in a floating-point representation. Is this some setting I could perhaps change?

( 2021-11-13 17:13:41 +0200 )edit

You can always optimistically try P.volume(measure='induced').radical_expression().

( 2021-11-16 16:41:57 +0200 )edit

The answer is exact, only the display is truncated.

sage: P = Polyhedron([[0,0], [1,1]])
sage: v = P.volume(measure='induced'); v
1.414213562373095?
sage: parent(v)
Algebraic Real Field
sage: v.minpoly()
x^2 - 2

more