def sal
bend-collections-laws-math@1.0.0.0 · proofs/math/typed/u32int.bend:356
import bend-collections-laws-math@1.0.0.0/proofs/math/typed/u32int.bend as U32int
import Base
import bend-collections-laws-math@1.0.0.0/spec/lib/common.bend as C
import bend-collections-laws-math@1.0.0.0/spec/math/generic.bend as SG
import bend-collections-laws-math@1.0.0.0/spec/math/natural.bend as NS
import bend-collections-laws-math@1.0.0.0/src/math/generic.bend as G
import bend-collections-laws-math@1.0.0.0/src/math/num.bend as NM
import bend-collections-laws-math@1.0.0.0/src/math/instances.bend as I
import bend-collections-laws-math@1.0.0.0/proofs/lib/nat.bend as N
import bend-collections-laws-math@1.0.0.0/proofs/lib/lemmas/proofs/nat_algebra.bend as NA
import bend-collections-laws-math@1.0.0.0/proofs/math/typed/u32laws.bend as LW
356def sal(+xs: List<&2, U32>, +r: Maybe<&2, U32>, +n: Nat, +c: Bool, +hr: {r == G.fits(U32, Bool.not(c), of(n)) : Maybe<&2, U32>}, +hc: {C.fits(32n, n) == c : Bool}) -> {G.ok(U32, G.sum_go(~U32, ~I.u32_op, ~I.u32_is, xs, r)) == SG.checked(~U32, ~SG.u32_of, 32n, Nat.add(n, NS.lsum(vals(xs)))) : Result<&2, &2, NM.NumError, U32>}:
357 match xs c:
358 case Nil{} True{}:
359 %Equal.sym(Maybe<&2, U32>, r, Some{of(n)}, hr) : {G.ok(U32, _) == SG.checked(~U32, ~SG.u32_of, 32n, Nat.add(n, 0n)) : Result<&2, &2, NM.NumError, U32>}
360 %Equal.sym(Nat, Nat.add(n, 0n), n, N.add_zero(n)) : {Done{of(n)} == SG.checked(~U32, ~SG.u32_of, 32n, _) : Result<&2, &2, NM.NumError, U32>}
361 %Equal.sym(Bool, C.fits(32n, n), True{}, hc) : {Done{of(n)} == SG.checked_pick(~U32, ~SG.u32_of, n, _) : Result<&2, &2, NM.NumError, U32>}
362 {==}
363 case Nil{} False{}:
364 %Equal.sym(Maybe<&2, U32>, r, None{}, hr) : {G.ok(U32, _) == SG.checked(~U32, ~SG.u32_of, 32n, Nat.add(n, 0n)) : Result<&2, &2, NM.NumError, U32>}
365 %Equal.sym(Nat, Nat.add(n, 0n), n, N.add_zero(n)) : {Fail{NM.Overflow{}} == SG.checked(~U32, ~SG.u32_of, 32n, _) : Result<&2, &2, NM.NumError, U32>}
366 %Equal.sym(Bool, C.fits(32n, n), False{}, hc) : {Fail{NM.Overflow{}} == SG.checked_pick(~U32, ~SG.u32_of, n, _) : Result<&2, &2, NM.NumError, U32>}
367 {==}
368 case Con{x, t} False{}:
369 %Equal.sym(Maybe<&2, U32>, r, None{}, hr) : {G.ok(U32, G.sum_go(~U32, ~I.u32_op, ~I.u32_is, Con{x, t}, _)) == SG.checked(~U32, ~SG.u32_of, 32n, Nat.add(n, NS.lsum(vals(Con{x, t})))) : Result<&2, &2, NM.NumError, U32>}
370 +s = Nat.add(n, NS.lsum(vals(Con{x, t})))
371 %Equal.sym(Bool, C.fits(32n, s), False{}, unfit_mono(32n, n, s, N.le_add_right(n, NS.lsum(vals(Con{x, t}))), hc)) : {Fail{NM.Overflow{}} == SG.checked_pick(~U32, ~SG.u32_of, s, _) : Result<&2, &2, NM.NumError, U32>}
372 {==}
373 case Con{+x, +t} True{}:
374 +n2 = Nat.add(n, v(x))
375 +hn = Equal.cong(Nat, Nat, z => Nat.add(z, v(x)), v(of(n)), n, LW.vo(n, hc))
376 %Equal.sym(Maybe<&2, U32>, r, Some{of(n)}, hr) : {G.ok(U32, G.sum_go(~U32, ~I.u32_op, ~I.u32_is, Con{x, t}, _)) == SG.checked(~U32, ~SG.u32_of, 32n, Nat.add(n, Nat.add(v(x), NS.lsum(vals(t))))) : Result<&2, &2, NM.NumError, U32>}
377 %NA.add_assoc(n, v(x), NS.lsum(vals(t))) : {G.ok(U32, G.sum_go(~U32, ~I.u32_op, ~I.u32_is, t, G.cadd(~U32, ~I.u32_op, ~I.u32_is, of(n), x))) == SG.checked(~U32, ~SG.u32_of, 32n, _) : Result<&2, &2, NM.NumError, U32>}
378 sal(t, G.cadd(~U32, ~I.u32_op, ~I.u32_is, of(n), x), n2, C.fits(32n, n2), cadd_rel(of(n), x, n2, hn, C.fits(32n, n2), {==}), {==})