IxVM kernel: klimbs_pow via binary exponentiation#455
Open
arthurpaulino wants to merge 1 commit into
Open
Conversation
Replace `klimbs_mul(base, klimbs_pow(base, klimbs_dec(exp)))`'s O(exp) per-step memo growth with a binary-exponentiation recursion of depth O(log exp). Both `exp / 2` and `exp % 2` route through the native `unconstrained_big_uint_div_mod` op, so each level pays O(1) for the division — `log2(exp)` memo entries for `klimbs_pow` itself + the `klimbs_mul(base, base)` doublings. `lake test -- --ignored ixvm` on `IxVMPrim.nat_pow_big` (`(2 ^ 16384 : Nat) - 2 ^ 16384 = 0`, measured against the current `ap/utf8-mod-witness` baseline): 3_941_276_885 → 71_856_587 FFT (-98.2%). Tests/Ix/IxVM.lean: * new `IxVMPrim.nat_pow_big` synthetic — exercises `klimbs_pow` at a non-trivial exponent (`2 ^ 16384`) so future regressions in the body shift its FFT pin. * small pin shifts in `nat_shl_lit`, `nat_shr_lit`, `nat_div_lit`, `nat_mod_lit`, `nat_gcd_lit`, `bv_to_nat_lit` — all reduce via `klimbs_pow` / `klimbs_div_mod` and absorb the new cost shape.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Replace
klimbs_mul(base, klimbs_pow(base, klimbs_dec(exp)))'s O(exp) per-step memo growth with a binary-exponentiation recursion of depth O(log exp). Bothexp / 2andexp % 2route through the nativeunconstrained_big_uint_div_modop, so each level pays O(1) for the division —log2(exp)memo entries forklimbs_powitself + theklimbs_mul(base, base)doublings.lake test -- --ignored ixvmonIxVMPrim.nat_pow_big((2 ^ 16384 : Nat) - 2 ^ 16384 = 0, measured against the currentap/utf8-mod-witnessbaseline):3_941_276_885 → 71_856_587 FFT (-98.2%).
Tests/Ix/IxVM.lean:
IxVMPrim.nat_pow_bigsynthetic — exercisesklimbs_powat a non-trivial exponent (2 ^ 16384) so future regressions in the body shift its FFT pin.nat_shl_lit,nat_shr_lit,nat_div_lit,nat_mod_lit,nat_gcd_lit,bv_to_nat_lit— all reduce viaklimbs_pow/klimbs_div_modand absorb the new cost shape.