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.Wed, 30 Jan 2019 10:52:34 +0100How to create a coercion on hyperbolic models?https://ask.sagemath.org/question/45228/how-to-create-a-coercion-on-hyperbolic-models/I want to put some text on my plots of the poincare disc model. I tried to do something like that,
word = text('my word',(real_part(P),imag_part(P)), color='black')
and gives me the following error,
TypeError: cannot coerce arguments: no canonical coercion from
Hyperbolic plane in the Poincare Disk Model to Symbolic Ring
Furthermore, this only works if my complex number P comes from the ring of complex numbers, not for a hyperbolic point. I need to configure some coercion. As substracting imaginary and real parts of a number in the poincare disk model. get_point method only work in one direction.
I am generating list of points like this.
Point in PD 0.150615998712507 - 0.101793686778004*I
and I want to add text in that coordinates, but I cannot find a way to coerce and get for example the complex number 0.1506 - 0.1017*I (even such exaggerate approximation will work in a plot)
Surely I am missing a method. Can you help me with this?
Thanks in advance
Tue, 29 Jan 2019 12:46:03 +0100https://ask.sagemath.org/question/45228/how-to-create-a-coercion-on-hyperbolic-models/Answer by tmonteil for <p>I want to put some text on my plots of the poincare disc model. I tried to do something like that,</p>
<pre><code>word = text('my word',(real_part(P),imag_part(P)), color='black')
</code></pre>
<p>and gives me the following error,</p>
<pre><code>TypeError: cannot coerce arguments: no canonical coercion from
Hyperbolic plane in the Poincare Disk Model to Symbolic Ring
</code></pre>
<p>Furthermore, this only works if my complex number P comes from the ring of complex numbers, not for a hyperbolic point. I need to configure some coercion. As substracting imaginary and real parts of a number in the poincare disk model. get_point method only work in one direction.</p>
<p>I am generating list of points like this.</p>
<pre><code>Point in PD 0.150615998712507 - 0.101793686778004*I
</code></pre>
<p>and I want to add text in that coordinates, but I cannot find a way to coerce and get for example the complex number 0.1506 - 0.1017*I (even such exaggerate approximation will work in a plot)</p>
<p>Surely I am missing a method. Can you help me with this?</p>
<p>Thanks in advance</p>
https://ask.sagemath.org/question/45228/how-to-create-a-coercion-on-hyperbolic-models/?answer=45229#post-id-45229First, you really need to provide the explicit construction of th objects, so that we can try to reproduce.
Without more information, let me assume that the `P` you speak about is of this form:
sage: H = HyperbolicPlane().PD()
sage: P = H.random_element()
sage: P
Point in PD 0.457058290632951 - 0.778395192442617*I
Indeed:
sage: real_part(P)
TypeError: cannot coerce arguments: no canonical coercion from Hyperbolic plane in the Poincare Disk Model to Symbolic Ring
To find a method related to some object, a very nice way is to use *tab-completion*, that is you type:
sage: P.<TAB>
Where `<TAB>` stands for the tab-key (which looks like two arrows on your keyboard).
There, you will find:
sage: P.coordinates()
0.457058290632951 - 0.778395192442617*I
sage: parent(P.coordinates())
Symbolic Ring
Which looks good, given the previous error message, and indeed, the following works:
sage: C = P.coordinates()
sage: word = text('my word',(real_part(C),imag_part(C)), color='black')
sage: word
Launched png viewer for Graphics object consisting of 1 graphics primitive
Tue, 29 Jan 2019 17:34:22 +0100https://ask.sagemath.org/question/45228/how-to-create-a-coercion-on-hyperbolic-models/?answer=45229#post-id-45229Comment by Gaston Burrull for <p>First, you really need to provide the explicit construction of th objects, so that we can try to reproduce.</p>
<p>Without more information, let me assume that the <code>P</code> you speak about is of this form:</p>
<pre><code>sage: H = HyperbolicPlane().PD()
sage: P = H.random_element()
sage: P
Point in PD 0.457058290632951 - 0.778395192442617*I
</code></pre>
<p>Indeed:</p>
<pre><code>sage: real_part(P)
TypeError: cannot coerce arguments: no canonical coercion from Hyperbolic plane in the Poincare Disk Model to Symbolic Ring
</code></pre>
<p>To find a method related to some object, a very nice way is to use <em>tab-completion</em>, that is you type:</p>
<pre><code>sage: P.<TAB>
</code></pre>
<p>Where <code><TAB></code> stands for the tab-key (which looks like two arrows on your keyboard).</p>
<p>There, you will find:</p>
<pre><code>sage: P.coordinates()
0.457058290632951 - 0.778395192442617*I
sage: parent(P.coordinates())
Symbolic Ring
</code></pre>
<p>Which looks good, given the previous error message, and indeed, the following works:</p>
<pre><code>sage: C = P.coordinates()
sage: word = text('my word',(real_part(C),imag_part(C)), color='black')
sage: word
Launched png viewer for Graphics object consisting of 1 graphics primitive
</code></pre>
https://ask.sagemath.org/question/45228/how-to-create-a-coercion-on-hyperbolic-models/?comment=45232#post-id-45232What an amazing trick! I had no idea of the existence of the <TAB> function!Wed, 30 Jan 2019 02:29:15 +0100https://ask.sagemath.org/question/45228/how-to-create-a-coercion-on-hyperbolic-models/?comment=45232#post-id-45232Comment by tmonteil for <p>First, you really need to provide the explicit construction of th objects, so that we can try to reproduce.</p>
<p>Without more information, let me assume that the <code>P</code> you speak about is of this form:</p>
<pre><code>sage: H = HyperbolicPlane().PD()
sage: P = H.random_element()
sage: P
Point in PD 0.457058290632951 - 0.778395192442617*I
</code></pre>
<p>Indeed:</p>
<pre><code>sage: real_part(P)
TypeError: cannot coerce arguments: no canonical coercion from Hyperbolic plane in the Poincare Disk Model to Symbolic Ring
</code></pre>
<p>To find a method related to some object, a very nice way is to use <em>tab-completion</em>, that is you type:</p>
<pre><code>sage: P.<TAB>
</code></pre>
<p>Where <code><TAB></code> stands for the tab-key (which looks like two arrows on your keyboard).</p>
<p>There, you will find:</p>
<pre><code>sage: P.coordinates()
0.457058290632951 - 0.778395192442617*I
sage: parent(P.coordinates())
Symbolic Ring
</code></pre>
<p>Which looks good, given the previous error message, and indeed, the following works:</p>
<pre><code>sage: C = P.coordinates()
sage: word = text('my word',(real_part(C),imag_part(C)), color='black')
sage: word
Launched png viewer for Graphics object consisting of 1 graphics primitive
</code></pre>
https://ask.sagemath.org/question/45228/how-to-create-a-coercion-on-hyperbolic-models/?comment=45235#post-id-45235This is the first thing i teach during Sage trainings !Wed, 30 Jan 2019 10:52:34 +0100https://ask.sagemath.org/question/45228/how-to-create-a-coercion-on-hyperbolic-models/?comment=45235#post-id-45235