Using test.jl to prove trig identies

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

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)

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

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

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

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

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

1 Like

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

1 Like

are periods part of the code?

invalad test macro call. with both == and isapprox

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.

2 Likes

OK thanks.