# Using test.jl to prove trig identies

**URL:** <https://discourse.julialang.org/t/using-test-jl-to-prove-trig-identies/48654>\
**Category:** General Usage\
**Tags:** testjl-unittesting, trigonometry\
**Created:** [October 19, 2020, 9:25pm UTC](https://discourse.julialang.org/t/using-test-jl-to-prove-trig-identies/48654 "2020-10-19T21:25:05Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [October 19, 2020, 9:25pm UTC](https://discourse.julialang.org/t/using-test-jl-to-prove-trig-identies/48654/1 "2020-10-19T21:25:05Z")

</div>

I’m trying to do a proof using trig identities, I get a fail, and I,m not sure if I’m using @test wrong, or if I made a mistake in my math s.t.

cos(x)-cos(y)=-2\*(sin((x+y)/2)\*sin((x-y)/2))

```julia
using Plots
using test

FX=f(x)=cos(x)
FY=f(y)=cos(y)

g(x,y)=abs(f(x)-f(y))
h(x,y)=-2*(sin((x+y)/2)*sin((x-y)/2))
delta(x,y)=abs(x-y)

plot(FX)
plot!(FY)
plot!(h)

```

@test h=g

plot(FX)  
plot!(FY)  
plot!(h)

```julia

```

---

<div class="post-metadata">

**Author:** ![pkofod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pkofod/32/2179_2.png) [@pkofod](https://discourse.julialang.org/u/pkofod)\
**Post date:** [October 19, 2020, 9:38pm UTC](https://discourse.julialang.org/t/using-test-jl-to-prove-trig-identies/48654/2 "2020-10-19T21:38:54Z")

</div>

Well, that is way beyond `@test`s abilities ( to show that two functions are the same), but you need to test that they are the same with ==. = is assignment.

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [October 19, 2020, 9:41pm UTC](https://discourse.julialang.org/t/using-test-jl-to-prove-trig-identies/48654/3 "2020-10-19T21:41:56Z")

</div>

OK, thanks I just did that for the Minimum. Is the problem the app and trig, or am I using it wrong?

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [October 19, 2020, 9:56pm UTC](https://discourse.julialang.org/t/using-test-jl-to-prove-trig-identies/48654/4 "2020-10-19T21:56:52Z")

</div>

You should test that the output of the functions are the same

```julia
x = 1:100
@test f.(x) == g.(x)

```

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [October 19, 2020, 10:06pm UTC](https://discourse.julialang.org/t/using-test-jl-to-prove-trig-identies/48654/5 "2020-10-19T22:06:38Z")

</div>

(Pretty much any non-trivial calculation using floating variables will only have limited accuracy though, so you probably want to use `isapprox` instead of `==` here.)

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [October 19, 2020, 10:08pm UTC](https://discourse.julialang.org/t/using-test-jl-to-prove-trig-identies/48654/6 "2020-10-19T22:08:29Z")

</div>

that makes sense. I didn’t get a result of @pdeffbach 's solution, but I did get an error message.

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [October 19, 2020, 10:09pm UTC](https://discourse.julialang.org/t/using-test-jl-to-prove-trig-identies/48654/7 "2020-10-19T22:09:31Z")

</div>

are periods part of the code?

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [October 19, 2020, 10:11pm UTC](https://discourse.julialang.org/t/using-test-jl-to-prove-trig-identies/48654/8 "2020-10-19T22:11:51Z")

</div>

invalad test macro call. with both == and isapprox

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [October 19, 2020, 11:44pm UTC](https://discourse.julialang.org/t/using-test-jl-to-prove-trig-identies/48654/9 "2020-10-19T23:44:43Z")

</div>

Yes the dots are definitely part of the code. The dot syntax, for broadcasting, is a pretty essential part of the language. Please read the documentation for broadcasting to get a better idea of what’s going on.

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [October 19, 2020, 11:46pm UTC](https://discourse.julialang.org/t/using-test-jl-to-prove-trig-identies/48654/10 "2020-10-19T23:46:14Z")

</div>

OK thanks.
