Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Request) Trigonometry and more math functions? #570

Closed
dogevspenguin opened this issue Jun 8, 2024 · 3 comments · Fixed by #616
Closed

(Request) Trigonometry and more math functions? #570

dogevspenguin opened this issue Jun 8, 2024 · 3 comments · Fixed by #616
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers HVM About the HVM syntax About Bend's syntax

Comments

@dogevspenguin
Copy link

dogevspenguin commented Jun 8, 2024

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?

@developedby
Copy link
Member

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

@developedby developedby added the syntax About Bend's syntax label Jun 9, 2024
@developedby
Copy link
Member

developedby commented Jun 20, 2024

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.

@developedby
Copy link
Member

developedby commented Jun 24, 2024

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.

@developedby developedby added the good first issue Good for newcomers label Jun 24, 2024
@imaqtkatt imaqtkatt self-assigned this Jul 4, 2024
@imaqtkatt imaqtkatt linked a pull request Jul 4, 2024 that will close this issue
github-merge-queue bot pushed a commit that referenced this issue Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers HVM About the HVM syntax About Bend's syntax
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants