ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 24 Nov 2018 09:32:05 -0600.simplify_full() doesn't simplify an obvious trigonometric expressionhttp://ask.sagemath.org/question/44391/simplify_full-doesnt-simplify-an-obvious-trigonometric-expression/Hello, I'm trying to simplify a trigonometric expression, and it didn't work as I expected. The original example was larger, but I reproduced the issue with a smaller one:
sage: y = (sin(x)+2) * sqrt( sin(x) / (sin(x)^2 + 4*sin(x) + 4) )
sage: y.simplify_full()
sqrt(sin(x)/(sin(x)^2 + 4*sin(x) + 4))*(sin(x) + 2)
Why doesn't that turn into `sqrt(sin(x))`? What do I miss?
Fri, 23 Nov 2018 02:50:56 -0600http://ask.sagemath.org/question/44391/simplify_full-doesnt-simplify-an-obvious-trigonometric-expression/Answer by slelievre for <p>Hello, I'm trying to simplify a trigonometric expression, and it didn't work as I expected. The original example was larger, but I reproduced the issue with a smaller one:</p>
<pre><code>sage: y = (sin(x)+2) * sqrt( sin(x) / (sin(x)^2 + 4*sin(x) + 4) )
sage: y.simplify_full()
sqrt(sin(x)/(sin(x)^2 + 4*sin(x) + 4))*(sin(x) + 2)
</code></pre>
<p>Why doesn't that turn into <code>sqrt(sin(x))</code>? What do I miss?</p>
http://ask.sagemath.org/question/44391/simplify_full-doesnt-simplify-an-obvious-trigonometric-expression/?answer=44392#post-id-44392This is because simplify_full does not attack square roots.
There is another method for doing that, which is called `canonicalize_radical`.
sage: y = (sin(x) + 2) * sqrt(sin(x) / (sin(x)^2 + 4 * sin(x) + 4))
sage: y.canonicalize_radical()
sqrt(sin(x))Fri, 23 Nov 2018 08:02:54 -0600http://ask.sagemath.org/question/44391/simplify_full-doesnt-simplify-an-obvious-trigonometric-expression/?answer=44392#post-id-44392Comment by sagenovice for <p>This is because simplify_full does not attack square roots.</p>
<p>There is another method for doing that, which is called <code>canonicalize_radical</code>.</p>
<pre><code>sage: y = (sin(x) + 2) * sqrt(sin(x) / (sin(x)^2 + 4 * sin(x) + 4))
sage: y.canonicalize_radical()
sqrt(sin(x))
</code></pre>
http://ask.sagemath.org/question/44391/simplify_full-doesnt-simplify-an-obvious-trigonometric-expression/?comment=44417#post-id-44417Thanks for the link and details! Personally I'd say sqrt() is a single-valued conditional function, and its symbolic representation depends on the sign of its argument, like, sqrt(x^2) = {x if x>=0; -x if x<0 }. It's just in my case the sign was known, so I hoped sage would guess that... Anyway, I posted that as a separate "[canonicalize_radical produces incorrect result](https://ask.sagemath.org/question/44414/canonicalize_radical-produces-incorrect-result/)" question. I hope it makes sense.Sat, 24 Nov 2018 09:32:05 -0600http://ask.sagemath.org/question/44391/simplify_full-doesnt-simplify-an-obvious-trigonometric-expression/?comment=44417#post-id-44417Comment by slelievre for <p>This is because simplify_full does not attack square roots.</p>
<p>There is another method for doing that, which is called <code>canonicalize_radical</code>.</p>
<pre><code>sage: y = (sin(x) + 2) * sqrt(sin(x) / (sin(x)^2 + 4 * sin(x) + 4))
sage: y.canonicalize_radical()
sqrt(sin(x))
</code></pre>
http://ask.sagemath.org/question/44391/simplify_full-doesnt-simplify-an-obvious-trigonometric-expression/?comment=44411#post-id-44411Yes, I think the "unsafe to use blindly" aspect was one reason for removing
"canonicalize_radical" (which at the time was called "simplify_radical") from
"simplify_full", in [Sage Trac ticket 12737](https://trac.sagemath.org/ticket/12737).
The sign issue is a recurring discussion which every time leads to a debate
about what "sqrt" stands for: a multivalued function from the complex numbers
to the complex numbers, or a single-valued function from the non-negative reals
to the non-negative reals.Sat, 24 Nov 2018 08:49:54 -0600http://ask.sagemath.org/question/44391/simplify_full-doesnt-simplify-an-obvious-trigonometric-expression/?comment=44411#post-id-44411Comment by sagenovice for <p>This is because simplify_full does not attack square roots.</p>
<p>There is another method for doing that, which is called <code>canonicalize_radical</code>.</p>
<pre><code>sage: y = (sin(x) + 2) * sqrt(sin(x) / (sin(x)^2 + 4 * sin(x) + 4))
sage: y.canonicalize_radical()
sqrt(sin(x))
</code></pre>
http://ask.sagemath.org/question/44391/simplify_full-doesnt-simplify-an-obvious-trigonometric-expression/?comment=44410#post-id-44410Ah, thank you! I've just read canonicalize_radical docs and it looks unsafe to use blindly. I experimented with it a little and reproduced a problem: `( (sin(x)-2) * sqrt( sin(x) / (sin(x)^2 - 4*sin(x) + 4) ) ).canonicalize_radical()` becomes "sqrt(sin(x))" while it should be "-sqrt(sin(x))". I wonder if there's a way to tell it the sign to simplify sqrt()... But that should probably be another question. Thanks for your answer!Sat, 24 Nov 2018 08:11:33 -0600http://ask.sagemath.org/question/44391/simplify_full-doesnt-simplify-an-obvious-trigonometric-expression/?comment=44410#post-id-44410