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

sets of exponents #4

Open
stevengj opened this issue Jun 10, 2021 · 0 comments
Open

sets of exponents #4

stevengj opened this issue Jun 10, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@stevengj
Copy link
Member

stevengj commented Jun 10, 2021

Since you can apply the @fastpow macro to a whole block of code, in principle it could recognize when you are computing multiple powers (e.g. x^2, x^5, and x^7) of a single variable, and then compute an optimal set of multiplications for the set, sharing operations wherever possible.

Finding the truly optimal set of multiplications is NP-complete, though, and I'm not sure if there is a good way to precompute and tabulate it like we do for a single exponent. But we could certainly compute a near-optimal set of multiplications using a variant of the power-by-squaring algorithm.

You would also have to be careful to identify when a given variable x refers to the same value at multiple points in the code, which is a bit hard to do at the macro level where types are unknown (so we can't be certain which operations might mutate x).

@stevengj stevengj added the enhancement New feature or request label Jun 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant