def mod_inverse
import bend-collections-laws-math@1.0.0.0/src/math/natural.bend as Naturalimport Base
323# pow(a, -1, m): the x < m with a * x == 1 (mod m)
324def mod_inverse(+a: Nat, +m: Nat) -> Result<&2, &2, MathError, Nat>:
325 match m:
326 case 0n:
327 Fail{ZeroDivision{}}
328 case 1n+ +mp:
329 inv_fin(1n+mp, inv_go(1n+mp, 1n+mp, 1n+mp, 0n, Nat.mod(a, 1n+mp), 1n))
Uses (6)
Used by (13)
- bend-collections-laws-math@1.0.0.0/spec/math/generic:ModInverse.agrees
- bend-collections-laws-math@1.0.0.0/proofs/math/natural/inverse:inverse_done
- bend-collections-laws-math@1.0.0.0/proofs/math/natural/inverse:inverse_fail
- bend-collections-laws-math@1.0.0.0/proofs/math/natural/inverse:inverse_zero
- bend-collections-laws-math@1.0.0.0/proofs/math/typed/u32int:inv_top
- …