Natural.pow_mod_odd: def of bend-collections-laws-math@1.0.0.0 Import: import bend-collections-laws-math@1.0.0.0/src/math/natural.bend as Natural Lines 275-282 of bend-collections-laws-math@1.0.0.0/src/math/natural.bend: https://jend.leeeet.dev/read.txt?path=bend-collections-laws-math@1.0.0.0/src/math/natural.bend&start_line=275&end_line=282 import Base # right-to-left binary exponentiation, reducing mod m after every product: # acc * base^e == b^e0 (mod m) throughout def pow_mod_odd(+m: Nat, +bit: Nat, +base: Nat, +acc: Nat) -> Nat: match bit: case 0n: acc case 1n+z: Nat.mod(Nat.mul(acc, base), m) Uses (3): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat.mod https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat.mul