def sel0

bend-collections-laws-crypto@1.0.0.0 · proofs/crypto/secp256k1/sel.bend:32

import bend-collections-laws-crypto@1.0.0.0/proofs/crypto/secp256k1/sel.bend as Sel
import Base
import bend-collections-laws-crypto@1.0.0.0/spec/lib/common.bend as C
import bend-collections-laws-crypto@1.0.0.0/spec/crypto/secp256k1/field.bend as FS
import bend-collections-laws-crypto@1.0.0.0/src/crypto/secp256k1/limbs.bend as L
import bend-collections-laws-crypto@1.0.0.0/proofs/lib/logic.bend as Lg
import bend-collections-laws-crypto@1.0.0.0/proofs/lib/lemmas/proofs/nat_algebra.bend as NA

32def sel0(+one: Nat, n: Nat, xs: List<&2, Nat>, ys: List<&2, Nat>, +hx: {FS.limbs16(one, n, xs) == True{} : Bool}, +hy: {FS.limbs16(one, n, ys) == True{} : Bool}) -> {L.select(0n, xs, ys) == ys : List<&2, Nat>}:
33  match n xs:
34    case 0n Nil{}:
35      match ys:
36        case Nil{}:
37          {==}
38        case y <> t:
39          Empty.absurd({L.select(0n, [], y <> t) == y <> t : List<&2, Nat>}, Lg.false_true(hy))
40    case 0n x <> t:
41      Empty.absurd({L.select(0n, x <> t, ys) == ys : List<&2, Nat>}, Lg.false_true(hx))
42    case 1n+k Nil{}:
43      Empty.absurd({L.select(0n, [], ys) == ys : List<&2, Nat>}, Lg.false_true(hx))
44    case 1n+ +k +x <> +xt:
45      match ys:
46        case Nil{}:
47          Empty.absurd({L.select(0n, x <> xt, []) == [] : List<&2, Nat>}, Lg.false_true(hy))
48        case +y <> +yt:
49          +hxt = Lg.and_right(Nat.is_lt(x, C.shift(16n, one)), FS.limbs16(one, k, xt), hx)
50          +hyt = Lg.and_right(Nat.is_lt(y, C.shift(16n, one)), FS.limbs16(one, k, yt), hy)
51          %Equal.sym(List<&2, Nat>, L.select(0n, xt, yt), yt, sel0(one, k, xt, yt, hxt, hyt)) : {Nat.add(Nat.mul(x, 0n), Nat.mul(y, 1n)) <> _ == y <> yt : List<&2, Nat>}
52          %Equal.sym(Nat, Nat.mul(x, 0n), 0n, NA.mul_zero(x)) : {Nat.add(_, Nat.mul(y, 1n)) <> yt == y <> yt : List<&2, Nat>}
53          %Equal.sym(Nat, Nat.mul(y, 1n), y, NA.mul_one(y)) : {Nat.add(0n, _) <> yt == y <> yt : List<&2, Nat>}
54          {==}

Uses (15)

Used by (8)