def pow_mod_go

bend-collections-laws-math@1.0.0.0 · src/math/generic.bend:524

import bend-collections-laws-math@1.0.0.0/src/math/generic.bend as Generic
import Base
import bend-collections-laws-math@1.0.0.0/src/math/num.bend as N

524# right-to-left binary exponentiation on (e, e == 0), every product reduced
525# mod m
526def pow_mod_go(~T: Data, ~op: N.Op<T> -> T, ~test: N.Test<T> -> Bool, fuel: Nat, +m: T, +b: T, +acc: T, st: T & Bool) -> T:
527  match fuel st:
528    case 0n _:
529      acc
530    case 1n+f Tuple{e, True{}}:
531      acc
532    case 1n+f Tuple{+e, False{}}:
533      pow_mod_go(~T, ~op, ~test, f, m, op(N.MulMod{b, b, m}), mm_bit(~T, ~op, test(N.Odd{e}), m, b, acc), zst(~T, ~test, op(N.Half{e})))

Uses (8)

Used by (5)