def mod_inverse

bend-collections-laws-math@1.0.0.0 · src/math/natural.bend:323

import bend-collections-laws-math@1.0.0.0/src/math/natural.bend as Natural
import 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)