Applying sin(-x)=-sin(x) with SymbolicUtils

Hi, I am trying to simplify some trigonometric expressions using SymbolicUtils. After applying the product rules for sine and cosine terms, you can end up with negative arguments and I would like to implement the following rules for these:

sin(-x) = -sin(x) & cos(-x) = cos(x)

However, this works only in some cases because my trigonometric expressions have arguments of the type nwt where n can be any integer, together with a negative sign. Using the following code:

r8 = @acrule sin(~x)cos(~y) => 0.5*(sin(~x + ~y) + sin(~x - ~y))
r12 = @rule sin(-1*(~x)) => -1 * sin((~x))

expr20 = simplify(expand(Asin(2wt)cos(13w*t)), RuleSet([r8, r12]))
println(expr20)
expr21 = simplify(expand(expr20), RuleSet([r12]))
println(expr21)

Returns the following:

0.5A*(sin(-11tw) + sin(15tw))
0.5Asin(-11tw) + 0.5Asin(15tw)

As you can see, it does not catch the negative argument and I have tried a bunch of ways. Would anyone know how I could perform this simplification?

Thanks!

Maybe (?)

Define the rule

r12 = @rule sin((~-)*(~x)) => - sin((~x))

( You should see the output

sin(~(-) * ~x) => -(sin(~x)) 

)

Apply the rule

expr = simplify(sin(-x), r12)

(You should see the output

−sin(𝑥)

)

Greetings to Delft in the sun.

Hi Domenico,

Thank you for your suggestion, unfortunately it only works if your argument is a single variable. The problem which I face is that my arguments are a product of 3 variables, hence it is harder for it to detect. While it works for sin(-x) it doesn’t for sin(-wt) for example.

1/ Requires more thinking to tackle the more general case.

2/ One (less immediate) approach is to develop an approach on sympy first (larger legacy) and subsequently translate to Julia symbolics.

3/ I am confused on how you arrive at the 11 wt and 15 wt arguments? Can you please explain?

4/ I updated Section 5 of sediment-transport-rivers/symbolic_julia.ipynb at main · ziolai/sediment-transport-rivers · GitHub with a non-linear model for damping. Possible this provides clues.

Cheers. D.