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, 27 Feb 2024 14:12:04 +0100Float-point precision in instantiation of point in Hyperbolic geometry modulehttps://ask.sagemath.org/question/76236/float-point-precision-in-instantiation-of-point-in-hyperbolic-geometry-module/I'm in the middle of debugging some other codebase (working in a Poincare Disk of hyperbolic-geometry) and I figured that the following specific point causing the issue.
Now, I would like to instantiate the point based on the that coordinate.
But the result of printing on console indicates that the last few digits have been rounded...
from sage.geometry.hyperbolic_space.hyperbolic_interface import HyperbolicPlane
# Instantiate HyperbolicPlane
PD = HyperbolicPlane().PD()
p = PD.get_point(CC(0.13816890584139213 + 0.4878012008585488*I))
print(p) # -> Point in PD 0.138168905841392 + 0.487801200858549*I
Could anyone help me instantiate the point on this particular coordinate?Mon, 26 Feb 2024 14:55:35 +0100https://ask.sagemath.org/question/76236/float-point-precision-in-instantiation-of-point-in-hyperbolic-geometry-module/Comment by Rowing0914 for <p>I'm in the middle of debugging some other codebase (working in a Poincare Disk of hyperbolic-geometry) and I figured that the following specific point causing the issue.
Now, I would like to instantiate the point based on the that coordinate.
But the result of printing on console indicates that the last few digits have been rounded...</p>
<pre><code>from sage.geometry.hyperbolic_space.hyperbolic_interface import HyperbolicPlane
# Instantiate HyperbolicPlane
PD = HyperbolicPlane().PD()
p = PD.get_point(CC(0.13816890584139213 + 0.4878012008585488*I))
print(p) # -> Point in PD 0.138168905841392 + 0.487801200858549*I
</code></pre>
<p>Could anyone help me instantiate the point on this particular coordinate?</p>
https://ask.sagemath.org/question/76236/float-point-precision-in-instantiation-of-point-in-hyperbolic-geometry-module/?comment=76238#post-id-76238Here is the link to the above code on Sage Maths Cell server: https://sagecell.sagemath.org/?q=mzkxqjMon, 26 Feb 2024 14:58:31 +0100https://ask.sagemath.org/question/76236/float-point-precision-in-instantiation-of-point-in-hyperbolic-geometry-module/?comment=76238#post-id-76238Answer by Emmanuel Charpentier for <p>I'm in the middle of debugging some other codebase (working in a Poincare Disk of hyperbolic-geometry) and I figured that the following specific point causing the issue.
Now, I would like to instantiate the point based on the that coordinate.
But the result of printing on console indicates that the last few digits have been rounded...</p>
<pre><code>from sage.geometry.hyperbolic_space.hyperbolic_interface import HyperbolicPlane
# Instantiate HyperbolicPlane
PD = HyperbolicPlane().PD()
p = PD.get_point(CC(0.13816890584139213 + 0.4878012008585488*I))
print(p) # -> Point in PD 0.138168905841392 + 0.487801200858549*I
</code></pre>
<p>Could anyone help me instantiate the point on this particular coordinate?</p>
https://ask.sagemath.org/question/76236/float-point-precision-in-instantiation-of-point-in-hyperbolic-geometry-module/?answer=76262#post-id-76262Alternate possibility : `PD.get_point()` *does* accept rational coordinates :
sage: p = PD.get_point(1/7+I/2); p
Point in PD 1/2*I + 1/7
Can you try to determine `p`'s *exact* coordinates (possibly by other means) ? I mean coordinates in `QQbar`.
Using the current data, you can try to convert (a bit awkwardly) from the CC-derived representation :
sage: pprime=PD.get_point((lambda a,b:a+I*b)(*[f(p.coordinates()).exact_rational() for f in (real, imag)])) ; pprime
Point in PD 2196861306417441/4503599627370496*I + 2489029731445931/18014398509481984
HTH,Tue, 27 Feb 2024 14:12:04 +0100https://ask.sagemath.org/question/76236/float-point-precision-in-instantiation-of-point-in-hyperbolic-geometry-module/?answer=76262#post-id-76262Answer by dan_fulea for <p>I'm in the middle of debugging some other codebase (working in a Poincare Disk of hyperbolic-geometry) and I figured that the following specific point causing the issue.
Now, I would like to instantiate the point based on the that coordinate.
But the result of printing on console indicates that the last few digits have been rounded...</p>
<pre><code>from sage.geometry.hyperbolic_space.hyperbolic_interface import HyperbolicPlane
# Instantiate HyperbolicPlane
PD = HyperbolicPlane().PD()
p = PD.get_point(CC(0.13816890584139213 + 0.4878012008585488*I))
print(p) # -> Point in PD 0.138168905841392 + 0.487801200858549*I
</code></pre>
<p>Could anyone help me instantiate the point on this particular coordinate?</p>
https://ask.sagemath.org/question/76236/float-point-precision-in-instantiation-of-point-in-hyperbolic-geometry-module/?answer=76242#post-id-76242Let us see what is exactly `CC`. For this, we compare:
sage: CC(0.13816890584139213)
0.138168905841392
sage: CC
Complex Field with 53 bits of precision
sage: CC(0.1234567890123456789012345678901234567890)
0.123456789012346
The first input corresponds to initializing the real part of the wanted point. Instead of `0.13816890584139213` we have a printed version going only up to `0.138168905841392`. Sometimes the printed version is such a rough information. So what is `CC`. It is an object collecting *inexact* information, only $53$ bits are collected. So from the next test number we have only `0.123456789012346`. If we try to print more...
`print(a.n(200))` runs into a `TypeError: cannot approximate to a precision of 200 bits, use at most 53 bits`...
So let us try from the start with a higher precision:
C = ComplexField(150)
print(f"C is {C}")
PD = HyperbolicPlane().PD()
p = PD.get_point(C(0.138168905841392130000000000) + C(0.4878012008585488000000000)*i) # our C instead of CC
print(p)
And we obtain:
C is Complex Field with 150 bits of precision
Point in PD 0.13816890584139213000000000000000000000000000 + 0.48780120085854880000000000000000000000000000*I
We have the decimals we want...
Mon, 26 Feb 2024 17:05:55 +0100https://ask.sagemath.org/question/76236/float-point-precision-in-instantiation-of-point-in-hyperbolic-geometry-module/?answer=76242#post-id-76242Comment by Rowing0914 for <p>Let us see what is exactly <code>CC</code>. For this, we compare:</p>
<pre><code>sage: CC(0.13816890584139213)
0.138168905841392
sage: CC
Complex Field with 53 bits of precision
sage: CC(0.1234567890123456789012345678901234567890)
0.123456789012346
</code></pre>
<p>The first input corresponds to initializing the real part of the wanted point. Instead of <code>0.13816890584139213</code> we have a printed version going only up to <code>0.138168905841392</code>. Sometimes the printed version is such a rough information. So what is <code>CC</code>. It is an object collecting <em>inexact</em> information, only $53$ bits are collected. So from the next test number we have only <code>0.123456789012346</code>. If we try to print more...
<code>print(a.n(200))</code> runs into a <code>TypeError: cannot approximate to a precision of 200 bits, use at most 53 bits</code>...</p>
<p>So let us try from the start with a higher precision:</p>
<pre><code>C = ComplexField(150)
print(f"C is {C}")
PD = HyperbolicPlane().PD()
p = PD.get_point(C(0.138168905841392130000000000) + C(0.4878012008585488000000000)*i) # our C instead of CC
print(p)
</code></pre>
<p>And we obtain:</p>
<pre><code>C is Complex Field with 150 bits of precision
Point in PD 0.13816890584139213000000000000000000000000000 + 0.48780120085854880000000000000000000000000000*I
</code></pre>
<p>We have the decimals we want...</p>
https://ask.sagemath.org/question/76236/float-point-precision-in-instantiation-of-point-in-hyperbolic-geometry-module/?comment=76246#post-id-76246@dan_fulea Thank you so much for your answer! I confirmed that this works as you described!Mon, 26 Feb 2024 21:58:37 +0100https://ask.sagemath.org/question/76236/float-point-precision-in-instantiation-of-point-in-hyperbolic-geometry-module/?comment=76246#post-id-76246