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.Wed, 03 Aug 2022 23:17:30 +0200replacing even powers of sin(x) by powers of (1-cos(x)^2)https://ask.sagemath.org/question/63514/replacing-even-powers-of-sinx-by-powers-of-1-cosx2/ Hi folks, I would like to force sage to take an expression like
f = cos(x)*(sin(x))^2+cos(x)^3*(sin(x))^5
and replace the even powers of sin(x) by powers of (1-cos(x)^2), so that the above would become
f=cos(x)*(1-cos(x)^2)+cos(x)^3*(1-cos(x)^2)^2*sin(x)
Any suggestions? Wed, 03 Aug 2022 21:55:57 +0200https://ask.sagemath.org/question/63514/replacing-even-powers-of-sinx-by-powers-of-1-cosx2/Answer by Max Alekseyev for <p>Hi folks, I would like to force sage to take an expression like</p>
<p>f = cos(x)<em>(sin(x))^2+cos(x)^3</em>(sin(x))^5</p>
<p>and replace the even powers of sin(x) by powers of (1-cos(x)^2), so that the above would become</p>
<p>f=cos(x)<em>(1-cos(x)^2)+cos(x)^3</em>(1-cos(x)^2)^2*sin(x)</p>
<p>Any suggestions? </p>
https://ask.sagemath.org/question/63514/replacing-even-powers-of-sinx-by-powers-of-1-cosx2/?answer=63516#post-id-63516One can use wildcards for this purpose:
f = cos(x)*(sin(x))^2+cos(x)^3*(sin(x))^5
w = SR.wild(0)
f.subs({sin(x)^w:((1-cos(x)^2)^floor(w/2)*sin(x)^(w-2*floor(w/2)))})Wed, 03 Aug 2022 23:17:30 +0200https://ask.sagemath.org/question/63514/replacing-even-powers-of-sinx-by-powers-of-1-cosx2/?answer=63516#post-id-63516