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, 16 Nov 2021 16:41:57 +0100Volume Automatically Getting Rounded?https://ask.sagemath.org/question/59699/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? Fri, 12 Nov 2021 01:42:32 +0100https://ask.sagemath.org/question/59699/volume-automatically-getting-rounded/Answer by rburing for <p>Hi All,</p>
<p>I'm trying to use the volume function, but it keeps on rounding.</p>
<p>Ex: </p>
<p>P = Polyhedron([[0,0], [1,1]])</p>
<p>P.volume(measure = 'induced');</p>
<p>Result: 1.414213562373095?</p>
<p>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? </p>
https://ask.sagemath.org/question/59699/volume-automatically-getting-rounded/?answer=59704#post-id-59704The 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)Fri, 12 Nov 2021 12:09:54 +0100https://ask.sagemath.org/question/59699/volume-automatically-getting-rounded/?answer=59704#post-id-59704Comment by rburing for <p>The result you get is an algebraic real number:</p>
<pre><code>sage: V = P.volume(measure = 'induced'); V
1.414213562373095?
sage: type(V)
<class 'sage.rings.qqbar.AlgebraicReal'>
sage: V.parent()
Algebraic Real Field
</code></pre>
<p>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.)</p>
<p>The number is the root of a polynomial:</p>
<pre><code>sage: V.minpoly()
x^2 - 2
</code></pre>
<p>In some cases (like here) you can express the number using radicals:</p>
<pre><code>sage: V.radical_expression()
sqrt(2)
</code></pre>
https://ask.sagemath.org/question/59699/volume-automatically-getting-rounded/?comment=59769#post-id-59769You can always optimistically try `P.volume(measure='induced').radical_expression()`.Tue, 16 Nov 2021 16:41:57 +0100https://ask.sagemath.org/question/59699/volume-automatically-getting-rounded/?comment=59769#post-id-59769Comment by asdfsa for <p>The result you get is an algebraic real number:</p>
<pre><code>sage: V = P.volume(measure = 'induced'); V
1.414213562373095?
sage: type(V)
<class 'sage.rings.qqbar.AlgebraicReal'>
sage: V.parent()
Algebraic Real Field
</code></pre>
<p>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.)</p>
<p>The number is the root of a polynomial:</p>
<pre><code>sage: V.minpoly()
x^2 - 2
</code></pre>
<p>In some cases (like here) you can express the number using radicals:</p>
<pre><code>sage: V.radical_expression()
sqrt(2)
</code></pre>
https://ask.sagemath.org/question/59699/volume-automatically-getting-rounded/?comment=59735#post-id-59735so 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?Sat, 13 Nov 2021 17:13:41 +0100https://ask.sagemath.org/question/59699/volume-automatically-getting-rounded/?comment=59735#post-id-59735Answer by FrédéricC for <p>Hi All,</p>
<p>I'm trying to use the volume function, but it keeps on rounding.</p>
<p>Ex: </p>
<p>P = Polyhedron([[0,0], [1,1]])</p>
<p>P.volume(measure = 'induced');</p>
<p>Result: 1.414213562373095?</p>
<p>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? </p>
https://ask.sagemath.org/question/59699/volume-automatically-getting-rounded/?answer=59703#post-id-59703The 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
Fri, 12 Nov 2021 12:04:39 +0100https://ask.sagemath.org/question/59699/volume-automatically-getting-rounded/?answer=59703#post-id-59703