def pow_go
bend-collections-laws-crypto@1.0.0.0 · src/math/generic.bend:170
import bend-collections-laws-crypto@1.0.0.0/src/math/generic.bend as Generic
import Base
import bend-collections-laws-crypto@1.0.0.0/src/math/num.bend as N
170
171
172
173def pow_go(~T: Data, ~op: N.Op<T> -> T, ~test: N.Test<T> -> Bool, fuel: Nat, +k: Nat, +b: T, +bok: Bool, st: T & Bool) -> Maybe<&2, T>:
174 match fuel k:
175 case 0n _:
176 st_fin(T, st)
177 case 1n+f 0n:
178 st_fin(T, st)
179 case 1n+f 1n+j:
180 pow_go(~T, ~op, ~test, f, Nat.div(1n+j, 2n), sq_val(~T, ~op, Nat.is_lt(1n, 1n+j), b), sq_ok(~T, ~test, Nat.is_lt(1n, 1n+j), b, bok), mul_st(~T, ~op, ~test, Nat.is_eq(Nat.mod(1n+j, 2n), 1n), b, bok, st))