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.Thu, 02 Dec 2010 21:53:45 +0100why won't simplify multiply out square roots?https://ask.sagemath.org/question/7787/why-wont-simplify-multiply-out-square-roots/I was trying to remove half angles in an expression. And it seems simplify() does not like to multiply out square root.
sage:theta=var('theta')
sage:assume(theta,'real')
sage:assume(theta>0)
sage:assume(theta<pi)
sage:m=((sin((1/2)*theta)*cos((1/2)*theta)).trig_expand(half_angles=True))
sage:view(m.simplify_full())
The output I get is $\frac{1}{2}\sqrt{-\cos\left(\theta\right) + 1} \sqrt{\cos\left(\theta\right) + 1}$
Is there a way I can make sage multiply out the the expression and give me $(1/2)sin \theta$
Thu, 02 Dec 2010 17:06:54 +0100https://ask.sagemath.org/question/7787/why-wont-simplify-multiply-out-square-roots/Comment by Evgeny for <p>I was trying to remove half angles in an expression. And it seems simplify() does not like to multiply out square root. </p>
<pre><code>sage:theta=var('theta')
sage:assume(theta,'real')
sage:assume(theta>0)
sage:assume(theta<pi)
sage:m=((sin((1/2)*theta)*cos((1/2)*theta)).trig_expand(half_angles=True))
sage:view(m.simplify_full())
</code></pre>
<p>The output I get is $\frac{1}{2}\sqrt{-\cos\left(\theta\right) + 1} \sqrt{\cos\left(\theta\right) + 1}$</p>
<p>Is there a way I can make sage multiply out the the expression and give me $(1/2)sin \theta$</p>
https://ask.sagemath.org/question/7787/why-wont-simplify-multiply-out-square-roots/?comment=22459#post-id-22459Hi, I've formatted the code part a bit. The input actually accepts simple formatting called Markdown. For code every line must be indented by four spaces, it can also be done by selecting a range and then hitting "format code" button in the editor that has numbers written on itThu, 02 Dec 2010 19:49:07 +0100https://ask.sagemath.org/question/7787/why-wont-simplify-multiply-out-square-roots/?comment=22459#post-id-22459Answer by Jason Bandlow for <p>I was trying to remove half angles in an expression. And it seems simplify() does not like to multiply out square root. </p>
<pre><code>sage:theta=var('theta')
sage:assume(theta,'real')
sage:assume(theta>0)
sage:assume(theta<pi)
sage:m=((sin((1/2)*theta)*cos((1/2)*theta)).trig_expand(half_angles=True))
sage:view(m.simplify_full())
</code></pre>
<p>The output I get is $\frac{1}{2}\sqrt{-\cos\left(\theta\right) + 1} \sqrt{\cos\left(\theta\right) + 1}$</p>
<p>Is there a way I can make sage multiply out the the expression and give me $(1/2)sin \theta$</p>
https://ask.sagemath.org/question/7787/why-wont-simplify-multiply-out-square-roots/?answer=11810#post-id-11810Probably not what you're looking for, but the best I could do:
sage: sqrt(m^2).simplify_full()
1/2*abs(sin(theta))
Thu, 02 Dec 2010 21:30:33 +0100https://ask.sagemath.org/question/7787/why-wont-simplify-multiply-out-square-roots/?answer=11810#post-id-11810Answer by kcrisman for <p>I was trying to remove half angles in an expression. And it seems simplify() does not like to multiply out square root. </p>
<pre><code>sage:theta=var('theta')
sage:assume(theta,'real')
sage:assume(theta>0)
sage:assume(theta<pi)
sage:m=((sin((1/2)*theta)*cos((1/2)*theta)).trig_expand(half_angles=True))
sage:view(m.simplify_full())
</code></pre>
<p>The output I get is $\frac{1}{2}\sqrt{-\cos\left(\theta\right) + 1} \sqrt{\cos\left(\theta\right) + 1}$</p>
<p>Is there a way I can make sage multiply out the the expression and give me $(1/2)sin \theta$</p>
https://ask.sagemath.org/question/7787/why-wont-simplify-multiply-out-square-roots/?answer=11811#post-id-11811In general, multi-valued functions shouldn't be simplified "nicely" by default. It should be possible to get Maxima to do something like this using `radexpand:True`, I think, but I don't believe Sage has this wrapped. It is also NOT obvious in the Maxima documentation what to do unless you really dig...
sage: maxima_console()
(%i1) exp:1/2*sqrt(-cos(theta) + 1)*sqrt(cos(theta) + 1);
sqrt(1 - cos(theta)) sqrt(cos(theta) + 1)
(%o1) -----------------------------------------
2
(%i2) trigsimp(rootscontract(exp));
abs(sin(theta))
(%o2) ---------------
2
There is currently not a consensus on just how much customization should be available through Sage commands. However, the `maxima_methods()` command allows access to pretty much all of them.
sage: exp = 1/2*sqrt(-cos(theta) + 1)*sqrt(cos(theta) + 1)
sage: exp = exp.maxima_methods().rootscontract(); exp
1/2*sqrt(-cos(theta)^2 + 1)
sage: exp.simplify_full()
1/2*abs(sin(theta))
There are a number of things that the Maxima assumption framework (which Sage uses) doesn't interact with, so perhaps the part where you are trying to ensure sin is positive is one of those things...Thu, 02 Dec 2010 21:53:45 +0100https://ask.sagemath.org/question/7787/why-wont-simplify-multiply-out-square-roots/?answer=11811#post-id-11811