You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to simplify expressions containing trig functions. Here is my test code and the code output. What is really surprising is that
whether or not some of the simplification work depend on what the variable names are. If I name them r, th, and phi more simplifications work than if I name them #1#, #2#, and #3#. Note that I use internal to my program variable names of the form #integer# so that when I post process latex strings it is easier to use regex to do the processing and then the last thing to do with the string is replace all the #integer# strings with the actual name strings from a dictionary. I do note that when I name a variable #1# and use println what is printed is var"#1#".
using Symbolics
using SymbolicUtils
r = Symbolics.variable("r")
th = Symbolics.variable("th")
phi = Symbolics.variable("phi")
#Is 1 it works
test1 = cos(th)^2+cos(phi)^2*sin(th)^2+sin(th)^2*sin(phi)^2
println(test1)
println(simplify(test1),"\n")
#Is 0 does not work
test2 = -r*cos(th)*sin(th)+r*cos(th)*cos(phi)^2*sin(th)+r*cos(th)*sin(th)*sin(phi)^2
println(test2)
println(simplify(test2),"\n")
#Is r^2 it works
test3 = r^2*sin(th)^2+r^2*cos(th)^2*cos(phi)^2+r^2*cos(th)^2*sin(phi)^2
println(test3)
println(simplify(test3),"\n")
#Is r^2*sin(th)^2 it works
test4 = r^2*cos(phi)^2*sin(th)^2+r^2*sin(th)^2*sin(phi)^2
println(test4)
println(simplify(test4),"\n")
r = Symbolics.variable("#1#")
th = Symbolics.variable("#2#")
phi = Symbolics.variable("#3#")
#Is 1 it works
test1 = cos(th)^2+cos(phi)^2*sin(th)^2+sin(th)^2*sin(phi)^2
println(test1)
println(simplify(test1),"\n")
#Is 0 does not work
test2 = -r*cos(th)*sin(th)+r*cos(th)*cos(phi)^2*sin(th)+r*cos(th)*sin(th)*sin(phi)^2
println(test2)
println(simplify(test2),"\n")
#Is r^2 does not work
test3 = r^2*sin(th)^2+r^2*cos(th)^2*cos(phi)^2+r^2*cos(th)^2*sin(phi)^2
println(test3)
println(simplify(test3),"\n")
#Is r^2*sin(th)^2 does not work
test4 = r^2*cos(phi)^2*sin(th)^2+r^2*sin(th)^2*sin(phi)^2
println(test4)
println(simplify(test4))
I am trying to simplify expressions containing trig functions. Here is my test code and the code output. What is really surprising is that
whether or not some of the simplification work depend on what the variable names are. If I name them
r
,th
, andphi
more simplifications work than if I name them#1#
,#2#
, and#3#
. Note that I use internal to my program variable names of the form #integer# so that when I post process latex strings it is easier to use regex to do the processing and then the last thing to do with the string is replace all the #integer# strings with the actual name strings from a dictionary. I do note that when I name a variable #1# and use println what is printed is var"#1#".And here is the code output -
cos(th)^2 + (sin(th)^2)(cos(phi)^2) + (sin(th)^2)(sin(phi)^2)
1
-rsin(th)cos(th) + rsin(th)(cos(phi)^2)cos(th) + rsin(th)cos(th)(sin(phi)^2)
-(1//2)rsin(2th) + (1//2)rsin(2th)(cos(phi)^2) + (1//2)rsin(2th)(sin(phi)^2)
(r^2)(sin(th)^2) + (r^2)(cos(phi)^2)(cos(th)^2) + (r^2)(cos(th)^2)*(sin(phi)^2)
r^2
(r^2)(sin(th)^2)(cos(phi)^2) + (r^2)(sin(th)^2)(sin(phi)^2)
(r^2)*(sin(th)^2)
cos(var"#2#")^2 + (cos(var"#3#")^2)(sin(var"#2#")^2) + (sin(var"#2#")^2)(sin(var"#3#")^2)
1
-var"#1#"*cos(var"#2#")*sin(var"#2#") + var"#1#"cos(var"#2#")(cos(var"#3#")^2)*sin(var"#2#") + var"#1#"*cos(var"#2#")sin(var"#2#")(sin(var"#3#")^2)
-(1//2)*var"#1#"*sin(2var"#2#") + (1//2)var"#1#"(cos(var"#3#")^2)*sin(2var"#2#") + (1//2)*var"#1#"sin(2var"#2#")(sin(var"#3#")^2)
(var"#1#"^2)(sin(var"#2#")^2) + (var"#1#"^2)(cos(var"#2#")^2)(cos(var"#3#")^2) + (var"#1#"^2)(cos(var"#2#")^2)(sin(var"#3#")^2)
(var"#1#"^2)(sin(var"#2#")^2) + (var"#1#"^2)(cos(var"#2#")^2)(cos(var"#3#")^2) + (var"#1#"^2)(cos(var"#2#")^2)(sin(var"#3#")^2)
(var"#1#"^2)(cos(var"#3#")^2)(sin(var"#2#")^2) + (var"#1#"^2)(sin(var"#2#")^2)(sin(var"#3#")^2)
(var"#1#"^2)(cos(var"#3#")^2)(sin(var"#2#")^2) + (var"#1#"^2)(sin(var"#2#")^2)(sin(var"#3#")^2)
The text was updated successfully, but these errors were encountered: