Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplifcation of Expression Containing Trig Function #633

Open
abrombo opened this issue Aug 17, 2024 · 0 comments
Open

Simplifcation of Expression Containing Trig Function #633

abrombo opened this issue Aug 17, 2024 · 0 comments

Comments

@abrombo
Copy link

abrombo commented Aug 17, 2024

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))

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant