ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 22 May 2013 09:24:35 -0500Zero solution does not result in zerohttps://ask.sagemath.org/question/10133/zero-solution-does-not-result-in-zero/The following looks like a bug to me, but I would value a second opinion:
----------------------------------------------------------------------
| Sage Version 5.8, Release Date: 2013-03-15 |
| Type "notebook()" for the browser-based notebook interface. |
| Type "help()" for help. |
----------------------------------------------------------------------
sage: phi = var('phi', domain='real')
sage: M = Matrix([
....: [-sqrt(-I)/(exp(I*phi)-1), sqrt(-I)/(exp(I*phi)-1)],
....: [-1/(exp(I*phi)-1)+exp(-I*phi), 1/(exp(I*phi)-1)]])
sage: z = M*vector((-I, 1))
sage: z = z[0]/z[1]
sage: zi = z.imag_part()
sage: s1 = [s.rhs() for s in solve(zi == 0, phi)]
sage: s1
[0, pi - arccos(1/2*sqrt(5) - 1/2), arccos(1/2*sqrt(5) + 1/2)]
sage: N(zi.subs(phi=s1[1]))
0.244669085661435
sage: zi.subs(phi=pi/2)
0
So the solutions *should* result in a zero of the `zi` expression, but apparently that is not the case. Instead, some value which is *not* listed among the solutions turns out to be a solution. Did I make some mistake here, or is this a bug in sage?
*Edit:* `zi` should be equal to `-1/2*sqrt(2)*cos(phi)/(sin(phi) + 1)`.
This is the expression from which I eventually derived the correct solution.
Wed, 22 May 2013 02:48:05 -0500https://ask.sagemath.org/question/10133/zero-solution-does-not-result-in-zero/Answer by tmonteil for <p>The following looks like a bug to me, but I would value a second opinion:</p>
<pre><code>----------------------------------------------------------------------
| Sage Version 5.8, Release Date: 2013-03-15 |
| Type "notebook()" for the browser-based notebook interface. |
| Type "help()" for help. |
----------------------------------------------------------------------
sage: phi = var('phi', domain='real')
sage: M = Matrix([
....: [-sqrt(-I)/(exp(I*phi)-1), sqrt(-I)/(exp(I*phi)-1)],
....: [-1/(exp(I*phi)-1)+exp(-I*phi), 1/(exp(I*phi)-1)]])
sage: z = M*vector((-I, 1))
sage: z = z[0]/z[1]
sage: zi = z.imag_part()
sage: s1 = [s.rhs() for s in solve(zi == 0, phi)]
sage: s1
[0, pi - arccos(1/2*sqrt(5) - 1/2), arccos(1/2*sqrt(5) + 1/2)]
sage: N(zi.subs(phi=s1[1]))
0.244669085661435
sage: zi.subs(phi=pi/2)
0
</code></pre>
<p>So the solutions <em>should</em> result in a zero of the <code>zi</code> expression, but apparently that is not the case. Instead, some value which is <em>not</em> listed among the solutions turns out to be a solution. Did I make some mistake here, or is this a bug in sage?</p>
<p><em>Edit:</em> <code>zi</code> should be equal to <code>-1/2*sqrt(2)*cos(phi)/(sin(phi) + 1)</code>.
This is the expression from which I eventually derived the correct solution.</p>
https://ask.sagemath.org/question/10133/zero-solution-does-not-result-in-zero/?answer=14961#post-id-14961This is indeed a bug, which is unfortunately not rare when working in the `Symbolic Ring` :/ Could you [report it on the trac server](http://trac.sagemath.org/sage_trac/) by yourself (ask for help in comment otherwise) ?
A way to get the correct solution, though not satisfactory, is to simplify the expression `zi` first, to help the solver:
sage: zzi = zi.full_simplify()
sage: zzi
-cos(phi)/(sqrt(2)*sin(phi) + sqrt(2))
sage: solve(zzi == 0, phi)
[phi == 1/2*pi]
This both gives you the correct answer and confirms that your hand-made calculation is reliable :)
Wed, 22 May 2013 06:34:13 -0500https://ask.sagemath.org/question/10133/zero-solution-does-not-result-in-zero/?answer=14961#post-id-14961Comment by tmonteil for <p>This is indeed a bug, which is unfortunately not rare when working in the <code>Symbolic Ring</code> :/ Could you <a href="http://trac.sagemath.org/sage_trac/">report it on the trac server</a> by yourself (ask for help in comment otherwise) ?</p>
<p>A way to get the correct solution, though not satisfactory, is to simplify the expression <code>zi</code> first, to help the solver:</p>
<pre><code>sage: zzi = zi.full_simplify()
sage: zzi
-cos(phi)/(sqrt(2)*sin(phi) + sqrt(2))
sage: solve(zzi == 0, phi)
[phi == 1/2*pi]
</code></pre>
<p>This both gives you the correct answer and confirms that your hand-made calculation is reliable :)</p>
https://ask.sagemath.org/question/10133/zero-solution-does-not-result-in-zero/?comment=17653#post-id-17653Thanks for reporting. As you can see the collection of [bugs concerning symbolic computations](http://trac.sagemath.org/sage_trac/wiki/symbolics) is quite huge, and i basically do not trust `SR` at all, and try to avoid it as much as i can (see for example [this problem](http://ask.sagemath.org/question/2518/get-variants-of-complex-cube-root?answer=3451#3451) with the square of a complex number) :(Wed, 22 May 2013 09:24:35 -0500https://ask.sagemath.org/question/10133/zero-solution-does-not-result-in-zero/?comment=17653#post-id-17653Comment by MvG for <p>This is indeed a bug, which is unfortunately not rare when working in the <code>Symbolic Ring</code> :/ Could you <a href="http://trac.sagemath.org/sage_trac/">report it on the trac server</a> by yourself (ask for help in comment otherwise) ?</p>
<p>A way to get the correct solution, though not satisfactory, is to simplify the expression <code>zi</code> first, to help the solver:</p>
<pre><code>sage: zzi = zi.full_simplify()
sage: zzi
-cos(phi)/(sqrt(2)*sin(phi) + sqrt(2))
sage: solve(zzi == 0, phi)
[phi == 1/2*pi]
</code></pre>
<p>This both gives you the correct answer and confirms that your hand-made calculation is reliable :)</p>
https://ask.sagemath.org/question/10133/zero-solution-does-not-result-in-zero/?comment=17654#post-id-17654Thank you for the confirmation. I just filed [a defect ticket](http://trac.sagemath.org/sage_trac/ticket/14628) for this issue. By the way, the other solution was not actually hand-made, but instead obtained by using the adjoint instead of the inverse matrix in some code leading up to the matrix `M` I had included in my post. The net effect was a multiplication of that matrix by the denominator of the bottom left entry. Also note that [since your answer here](http://ask.sagemath.org/question/2577/integrate-with-elliptic-integral-special-function?answer=3544#3544) I no longer trust `full_simplify` as much as I used to Wed, 22 May 2013 09:07:08 -0500https://ask.sagemath.org/question/10133/zero-solution-does-not-result-in-zero/?comment=17654#post-id-17654