Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
1

Volume Automatically Getting Rounded?

asked 3 years ago

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?

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
2

answered 3 years ago

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)
Preview: (hide)
link

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 π, 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 ( 3 years ago )

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

rburing gravatar imagerburing ( 3 years ago )
0

answered 3 years ago

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
Preview: (hide)
link

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: 3 years ago

Seen: 335 times

Last updated: Nov 12 '21