Ask Your Question
1

Volume Automatically Getting Rounded?

asked 2021-11-12 01:42:32 +0200

asdfsa gravatar image

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 flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
2

answered 2021-11-12 12:09:54 +0200

rburing gravatar image

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)
edit flag offensive delete link more

Comments

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?

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

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

rburing gravatar imagerburing ( 2021-11-16 16:41:57 +0200 )edit
0

answered 2021-11-12 12:04:39 +0200

FrédéricC gravatar image

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
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2021-11-12 01:42:32 +0200

Seen: 207 times

Last updated: Nov 12 '21