proofs/math/random/bounded.bend
bend-collections-laws-math@1.0.0.0 · 37 lines · 3 definitions
1import Base
2import bend-collections-laws-math@1.0.0.0/src/math/u64.bend as W
3import bend-collections-laws-math@1.0.0.0/src/math/w64.bend as X
4import bend-collections-laws-math@1.0.0.0/src/math/random/rand.bend as R
5import bend-collections-laws-math@1.0.0.0/spec/math/w64.bend as SW
6import bend-collections-laws-math@1.0.0.0/spec/math/random.bend as SRM
7import bend-collections-laws-math@1.0.0.0/spec/math/random/rand.bend as SR
8import bend-collections-laws-math@1.0.0.0/proofs/lib/logic.bend as L
9import bend-collections-laws-math@1.0.0.0/proofs/math/typed/w64add.bend as WA
10import bend-collections-laws-math@1.0.0.0/proofs/math/random/uint64n.bend as UN
11import bend-collections-laws-math@1.0.0.0/proofs/math/random/below.bend as BL
12
13
14
15
16def fst_val(-S: Data, r: W.U64 & S) -> {BL.pfst(S, SRM.val_pair(S, r)) == SW.value(R.fst(W.U64, S, r)) : Nat}:
17 match r:
18 case Tuple{x, s}:
19 {==}
20
21def nz_pos(+v: Nat, +h: {Nat.is_eq(v, 0n) == False{} : Bool}) -> {Nat.is_lt(0n, v) == True{} : Bool}:
22 match v:
23 case 0n:
24 Empty.absurd({Nat.is_lt(0n, 0n) == True{} : Bool}, L.true_false(h))
25 case 1n+p:
26 {==}
27
28def uint64n_lt(~S: Data, ~next: S -> W.U64 & S, +s: S, +n: W.U64, +hn: {X.is_zero(n) == False{} : Bool}) -> SRM.Uint64n.lt(~S, ~next, s, n, hn):
29 +vn = SW.value(n)
30 +hv = Equal.trans(Bool, Nat.is_eq(vn, 0n), X.is_zero(n), False{}, Equal.sym(Bool, X.is_zero(n), Nat.is_eq(vn, 0n), WA.is_zero_value(n)), hn)
31 +e = Equal.trans(Nat, SW.value(R.fst(W.U64, S, R.uint64n(~S, ~next, s, n))), BL.pfst(S, SRM.val_pair(S, R.uint64n(~S, ~next, s, n))), BL.pfst(S, SR.below(~S, ~next, 127n, vn, s)),
32 Equal.sym(Nat, BL.pfst(S, SRM.val_pair(S, R.uint64n(~S, ~next, s, n))), SW.value(R.fst(W.U64, S, R.uint64n(~S, ~next, s, n))), fst_val(S, R.uint64n(~S, ~next, s, n))),
33 Equal.cong(Nat & S, Nat, p => BL.pfst(S, p), SRM.val_pair(S, R.uint64n(~S, ~next, s, n)), SR.below(~S, ~next, 127n, vn, s), UN.uint64n_value(~S, ~next, s, n)))
34 Equal.trans(Bool, Nat.is_lt(SW.value(R.fst(W.U64, S, R.uint64n(~S, ~next, s, n))), vn), Nat.is_lt(BL.pfst(S, SR.below(~S, ~next, 127n, vn, s)), vn), True{},
35 Equal.cong(Nat, Bool, z => Nat.is_lt(z, vn), SW.value(R.fst(W.U64, S, R.uint64n(~S, ~next, s, n))), BL.pfst(S, SR.below(~S, ~next, 127n, vn, s)), e),
36 BL.below_lt(~S, ~next, 127n, vn, s, nz_pos(vn, hv)))
37