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

**URL:** <https://discourse.julialang.org/t/applying-sin-x-sin-x-with-symbolicutils/124002>\
**Category:** General Usage\
**Tags:** question, package, symbolic-utils\
**Created:** [December 19, 2024, 9:45pm UTC](https://discourse.julialang.org/t/applying-sin-x-sin-x-with-symbolicutils/124002 "2024-12-19T21:45:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ValterDelft](https://avatars.discourse-cdn.com/v4/letter/v/b4bc9f/32.png) [@ValterDelft](https://discourse.julialang.org/u/ValterDelft)\
**Post date:** [December 19, 2024, 9:45pm UTC](https://discourse.julialang.org/t/applying-sin-x-sin-x-with-symbolicutils/124002/1 "2024-12-19T21:45:18Z")

</div>

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 n_w_t 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(A_sin(2_w_t)cos(13_w\*t)), RuleSet([r8, r12]))  
println(expr20)  
expr21 = simplify(expand(expr20), RuleSet([r12]))  
println(expr21)

Returns the following:

0.5A\*(sin(-11t_w) + sin(15t_w))  
0.5A_sin(-11t_w) + 0.5A_sin(15t_w)

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!

---

<div class="post-metadata">

**Author:** ![Domenico\_Lahaye](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/domenico_lahaye/32/203728_2.png) [@Domenico\_Lahaye](https://discourse.julialang.org/u/Domenico_Lahaye)\
**Post date:** [December 20, 2024, 8:07am UTC](https://discourse.julialang.org/t/applying-sin-x-sin-x-with-symbolicutils/124002/2 "2024-12-20T08:07:12Z")

</div>

Maybe (?)

Define the rule

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

```

( You should see the output

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

```

)

Apply the rule

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

```

(You should see the output

```julia
−sin(𝑥)

```

)

Greetings to Delft in the sun.

---

<div class="post-metadata">

**Author:** ![ValterDelft](https://avatars.discourse-cdn.com/v4/letter/v/b4bc9f/32.png) [@ValterDelft](https://discourse.julialang.org/u/ValterDelft)\
**Post date:** [December 20, 2024, 8:20pm UTC](https://discourse.julialang.org/t/applying-sin-x-sin-x-with-symbolicutils/124002/3 "2024-12-20T20:20:22Z")

</div>

> [@Domenico\_Lahaye](#):
>
> `r12 = @rule sin((~-)*(~x)) => - sin((~x))`

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.

---

<div class="post-metadata">

**Author:** ![Domenico\_Lahaye](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/domenico_lahaye/32/203728_2.png) [@Domenico\_Lahaye](https://discourse.julialang.org/u/Domenico_Lahaye)\
**Post date:** [December 20, 2024, 9:27pm UTC](https://discourse.julialang.org/t/applying-sin-x-sin-x-with-symbolicutils/124002/4 "2024-12-20T21:27:18Z")

</div>

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](https://github.com/ziolai/sediment-transport-rivers/blob/main/symbolic_julia.ipynb) with a non-linear model for damping. Possible this provides clues.

Cheers. D.
