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.Sun, 11 Oct 2015 22:46:40 +0200Factoring expression involving exponentialshttps://ask.sagemath.org/question/29823/factoring-expression-involving-exponentials/ I've got a complicated expression, which looks like:
e(4ik+3iω+ip)−e(4ik+2iω+2ip)−e(4ik+2iω)+e(4ik+iω+ip)+2e(2ik+4iω+ip)−e(2ik+3iω+2ip)−e(2ik+3iω) + ...
How would you do to factor the exponentials with the same power of k, i.e. e(4ik)*(...) + e(2ik)*(...) and so on?
Thu, 08 Oct 2015 10:34:33 +0200https://ask.sagemath.org/question/29823/factoring-expression-involving-exponentials/Answer by José Luis for <p>I've got a complicated expression, which looks like:
e(4ik+3iω+ip)−e(4ik+2iω+2ip)−e(4ik+2iω)+e(4ik+iω+ip)+2e(2ik+4iω+ip)−e(2ik+3iω+2ip)−e(2ik+3iω) + ...</p>
<p>How would you do to factor the exponentials with the same power of k, i.e. e(4ik)<em>(...) + e(2ik)</em>(...) and so on? </p>
https://ask.sagemath.org/question/29823/factoring-expression-involving-exponentials/?answer=29908#post-id-29908Maybe by a change of variables:
sage: var('k,w,p')
sage: expr(k,w,p)=exp(4*i*k+3*i*w+i*p)-exp(4*i*k+2*i*w+2*i*p)-exp(4*i*k+2*i*w)+exp(4*i*k+i*w+i*p)+2*exp(2*i*k+4*i*w+i*p)-
exp(2*i*k+3*i*w+2*i*p)-exp(2*i*k+3*i*w)
sage: f(k,w,p)=expr(log(k),log(w),log(p))
sage: g(k,w,p)=f.canonicalize_radical()
sage: g(exp(k),exp(w),exp(p)).factor()
Sat, 10 Oct 2015 23:54:33 +0200https://ask.sagemath.org/question/29823/factoring-expression-involving-exponentials/?answer=29908#post-id-29908Comment by mforets for <p>Maybe by a change of variables:</p>
<p>sage: var('k,w,p')</p>
<p>sage: expr(k,w,p)=exp(4<em>i</em>k+3<em>i</em>w+i<em>p)-exp(4</em>i<em>k+2</em>i<em>w+2</em>i<em>p)-exp(4</em>i<em>k+2</em>i<em>w)+exp(4</em>i<em>k+i</em>w+i<em>p)+2</em>exp(2<em>i</em>k+4<em>i</em>w+i<em>p)- <br/>
exp(2</em>i<em>k+3</em>i<em>w+2</em>i<em>p)-exp(2</em>i<em>k+3</em>i*w)</p>
<p>sage: f(k,w,p)=expr(log(k),log(w),log(p))</p>
<p>sage: g(k,w,p)=f.canonicalize_radical()</p>
<p>sage: g(exp(k),exp(w),exp(p)).factor() </p>
https://ask.sagemath.org/question/29823/factoring-expression-involving-exponentials/?comment=29918#post-id-29918This answer was useful, thanks. But at the end factor doesn't work as expected (it just leds to the original expression). We can use instead use the coefficient function to conclude.Sun, 11 Oct 2015 22:42:31 +0200https://ask.sagemath.org/question/29823/factoring-expression-involving-exponentials/?comment=29918#post-id-29918Answer by mforets for <p>I've got a complicated expression, which looks like:
e(4ik+3iω+ip)−e(4ik+2iω+2ip)−e(4ik+2iω)+e(4ik+iω+ip)+2e(2ik+4iω+ip)−e(2ik+3iω+2ip)−e(2ik+3iω) + ...</p>
<p>How would you do to factor the exponentials with the same power of k, i.e. e(4ik)<em>(...) + e(2ik)</em>(...) and so on? </p>
https://ask.sagemath.org/question/29823/factoring-expression-involving-exponentials/?answer=29919#post-id-29919Using both ideas we can formulate a complete answer (assume that expr(k) is the expression in terms of phases in powers of k that we want to factor):
f1(k) = expr(-I*log(k)); f1
g1(k) = f1.canonicalize_radical(); g1
g1(k).coefficient(k,4)Sun, 11 Oct 2015 22:46:40 +0200https://ask.sagemath.org/question/29823/factoring-expression-involving-exponentials/?answer=29919#post-id-29919Answer by fidbc for <p>I've got a complicated expression, which looks like:
e(4ik+3iω+ip)−e(4ik+2iω+2ip)−e(4ik+2iω)+e(4ik+iω+ip)+2e(2ik+4iω+ip)−e(2ik+3iω+2ip)−e(2ik+3iω) + ...</p>
<p>How would you do to factor the exponentials with the same power of k, i.e. e(4ik)<em>(...) + e(2ik)</em>(...) and so on? </p>
https://ask.sagemath.org/question/29823/factoring-expression-involving-exponentials/?answer=29835#post-id-29835I would probably try using the `factor` method.
sage: var('x,y,z')
(x, y, z)
sage: expr=exp(4*x-2*y+4*z)+exp(4*x-3*y+5*z)
sage: expr.factor()
(e^y + e^z)*e^(4*x - 3*y + 4*z)
Perhaps the [manual](http://doc.sagemath.org/html/en/reference/calculus/sage/symbolic/expression.html#sage.symbolic.expression.Expression.factor) will contain useful info on that as well.Thu, 08 Oct 2015 16:21:53 +0200https://ask.sagemath.org/question/29823/factoring-expression-involving-exponentials/?answer=29835#post-id-29835Comment by mforets for <p>I would probably try using the <code>factor</code> method.</p>
<pre><code>sage: var('x,y,z')
(x, y, z)
sage: expr=exp(4*x-2*y+4*z)+exp(4*x-3*y+5*z)
sage: expr.factor()
(e^y + e^z)*e^(4*x - 3*y + 4*z)
</code></pre>
<p>Perhaps the <a href="http://doc.sagemath.org/html/en/reference/calculus/sage/symbolic/expression.html#sage.symbolic.expression.Expression.factor">manual</a> will contain useful info on that as well.</p>
https://ask.sagemath.org/question/29823/factoring-expression-involving-exponentials/?comment=29855#post-id-29855Thanks, but you can see this doesn't do the job: the goal was to collect the terms in exp(4*x), and so on (try adding for instance exp(2*x-3*y+5*z) and factoring, it does something correct but is not what I need). I thought it'd be useful a previous step transforming the exp(2*x) into z and exp(4*x) into z^2, etc and then factoring, but I am not able to get the substitution done..Thu, 08 Oct 2015 23:07:46 +0200https://ask.sagemath.org/question/29823/factoring-expression-involving-exponentials/?comment=29855#post-id-29855