HigherOrderCO / Bend

A massively parallel, high-level programming language

Home Page:https://higherorderco.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

(Request) Trigonometry and more math functions?

dogevspenguin opened this issue · comments

I am wondering how would I be able to use trigonometric functions, As Bend looked quite promising for a speed-up In a project I've been doing, But it requires the usage of trigonometric functions such as sin, cos tan, and even inverse function. So is it possible to add these math functions?

We can implement them as an approximation in Bend using the already existing operations, but I think they should exist as HVM operations.
I created this issue to track that HigherOrderCO/HVM#384, but if you want to use them right now look into the approximations like I said.

If by inverse you mean x^-1, you can already do that with the ** (pow) operator.

If by inverse you mean arcsin, arccos and arctan, HVM already implements atan2, it's just not exposed in Bend.
You can hack them in by using the internal representation of bitwise operations.

  • a & b = atan2(a, b), arctan(a / b)
  • a | b = log(a, b), log_b(a)
  • a ^ b = pow(a, b), a^b

With HigherOrderCO/HVM#384 done, we can now work on implementing it on Bend.
The same approach that was used for the other f24 primitives can be used here.

HVM implements sin(x + y) using the [<<] operator and tan(x + y) with the [>>] operator.
We can implement them in builtins.bend like we did the others, using a native hvm definition for sin(x) = (<< x 0.0). Cosine can be the same thing but + pi/2.