Implement pow-by-constant with NAF for FpVar #72
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Description
Warning: this PR is more complicated than one may expect.
This PR changes
FpVar's implementation ofpow_by_constantto a special version that uses NAF.However, there are several subtle issues.
First, for correctness and soundness,
base= 0,exp!= 0, the result should be zero, and the constraint system should be satisfied. This means that one cannot simply useinverseto compute the inverse of the base, as it may create an unsatisfiable constraint.base= 0,exp= 0, there should be panic, and the constraint system is guaranteed to be unsatisfied.Second, for efficiency,
closes: #55
Note that currently
algebra'spowdoes not panic whenbase= 0 andexp= 0, which will be handled in a separate PR.This PR is associated with four tests.
For review, this PR will need some effort, as it appears to be quite complicated.
If you find any good ideas to simplify the code, please propose. The current code is a little bit longer than expected (due to the handling of soundness in respect to the corner cases).
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
Pendingsection inCHANGELOG.mdFiles changedin the Github PR explorer