HigherOrderCO / HVM

A massively parallel, optimal functional runtime in Rust
https://higherorderco.com
Apache License 2.0
10.44k stars 397 forks source link

Add trigonometric function operators for F24 #384

Closed developedby closed 3 months ago

developedby commented 3 months ago

Is your feature request related to a problem? Please describe. A request by a Bend user in this issue: https://github.com/HigherOrderCO/Bend/issues/570.

We have log, atan2 and pow for floats, but not trigonometric functions like sin, cos and tan. I think they're common enough to warrant being a native operation. We should have at least one of them, the others could be easily derived (cos(x) = sqrt(1 - sin(x)²), etc)

Describe the solution you'd like Add at least one of sin, cos and tan functions as a native floating point operation. We could use SHL and SHR tags to implement them for f24 types.

Describe alternatives you've considered Approximating them using the already present operations. I think it can be done in around ~10-20 interactions each.

Janiczek commented 3 months ago

easily derived (cos(x) = sqrt(1 - sin(x)²))

I think you're missing an easier derivation:

cos x = sin (x + pi/2)