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, 12 Feb 2013 17:43:27 +0100Sympy geometry: can't compute tangent lineshttps://ask.sagemath.org/question/9795/sympy-geometry-cant-compute-tangent-lines/Here's the problem:
from sympy import symbols, Plot
from sympy.geometry import *
c1 = Circle(Point(0,0),2)
a = Point(3,0)
at = c1.tangent_lines(a)
DomainError: can't compute a Groebner basis over RR
A little web search indicates that this was a problem with older versions of sympy, but Sage includes a newer version for which this issue is not supposed to be a problem. Any ideas on how to get round this?
Mon, 11 Feb 2013 00:36:34 +0100https://ask.sagemath.org/question/9795/sympy-geometry-cant-compute-tangent-lines/Answer by DSM for <p>Here's the problem:</p>
<pre><code>from sympy import symbols, Plot
from sympy.geometry import *
c1 = Circle(Point(0,0),2)
a = Point(3,0)
at = c1.tangent_lines(a)
DomainError: can't compute a Groebner basis over RR
</code></pre>
<p>A little web search indicates that this was a problem with older versions of sympy, but Sage includes a newer version for which this issue is not supposed to be a problem. Any ideas on how to get round this?</p>
https://ask.sagemath.org/question/9795/sympy-geometry-cant-compute-tangent-lines/?answer=14537#post-id-14537This seems to work for me in Sage 5.6:
sage: from sympy.geometry import Circle, Point
sage: c1 = Circle(Point(0,0),2)
sage: a = Point(3,0)
sage: at = c1.tangent_lines(a)
sage: at
[Line(Point(3, 0), Point(4/3, -2*5**(1/2)/3)), Line(Point(3, 0), Point(4/3, 2*5**(1/2)/3))]
as well as on `sagenb`'s 5.4.
BTW, star imports -- `from somewhere import *` -- are generally disfavoured in Python, and that's even more true in Sage, because it's very easy to accidentally rebind a name -- `sin`, say -- which originally referred to Sage's function with one which refers to the `sin` function of `sympy`, or `mpmath`, or `numpy`, or something, which will raise puzzling errors and be the source of mysterious bugs.
[My favourite example:
sage: all(i < 10 for i in [0..100])
False
sage: from numpy import *
sage: all(i < 10 for i in [0..100])
True
This once caused a bug in my code it took forever to track down.]
Mon, 11 Feb 2013 11:57:09 +0100https://ask.sagemath.org/question/9795/sympy-geometry-cant-compute-tangent-lines/?answer=14537#post-id-14537Comment by Alasdair for <p>This seems to work for me in Sage 5.6:</p>
<pre><code>sage: from sympy.geometry import Circle, Point
sage: c1 = Circle(Point(0,0),2)
sage: a = Point(3,0)
sage: at = c1.tangent_lines(a)
sage: at
[Line(Point(3, 0), Point(4/3, -2*5**(1/2)/3)), Line(Point(3, 0), Point(4/3, 2*5**(1/2)/3))]
</code></pre>
<p>as well as on <code>sagenb</code>'s 5.4.</p>
<p>BTW, star imports -- <code>from somewhere import *</code> -- are generally disfavoured in Python, and that's even more true in Sage, because it's very easy to accidentally rebind a name -- <code>sin</code>, say -- which originally referred to Sage's function with one which refers to the <code>sin</code> function of <code>sympy</code>, or <code>mpmath</code>, or <code>numpy</code>, or something, which will raise puzzling errors and be the source of mysterious bugs.</p>
<p>[My favourite example: </p>
<pre><code>sage: all(i < 10 for i in [0..100])
False
sage: from numpy import *
sage: all(i < 10 for i in [0..100])
True
</code></pre>
<p>This once caused a bug in my code it took forever to track down.]</p>
https://ask.sagemath.org/question/9795/sympy-geometry-cant-compute-tangent-lines/?comment=18243#post-id-18243I discovered that my mistake (not shown in the original example) was describing circles using real numbers:
Circle(Point(-0.25,0),1)
instead of rationals:
Circle(Point([-1/4,0]),1)
And thank you for the heads-up about not importing using *. That's just me being lazy!Tue, 12 Feb 2013 17:43:27 +0100https://ask.sagemath.org/question/9795/sympy-geometry-cant-compute-tangent-lines/?comment=18243#post-id-18243