def subtraction_conservation

bend-collections-laws-math@1.0.0.0 · proofs/lib/lemmas/proofs/division_remainder.bend:24

import bend-collections-laws-math@1.0.0.0/proofs/lib/lemmas/proofs/division_remainder.bend as DivisionRemainder
import Base
import bend-collections-laws-math@1.0.0.0/proofs/lib/lemmas/proofs/map_difference_order.bend as Order
import bend-collections-laws-math@1.0.0.0/proofs/lib/lemmas/proofs/word_comparison.bend as Compare
import bend-collections-laws-math@1.0.0.0/proofs/lib/lemmas/proofs/subtraction_bounds.bend as Sub
import bend-collections-laws-math@1.0.0.0/proofs/lib/lemmas/proofs/division_bounds.bend as Bounds

24def subtraction_conservation(+r: U32, +d: U32, above: {U32.is_ge(r, d) == True{} : Bool}) -> {U32.to_nat(r) == Nat.add(U32.to_nat(d), U32.to_nat(U32.sub(r, d))) : Nat}:
25  +enough = Equal.trans(Bool, Nat.is_le(U32.to_nat(d), U32.to_nat(r)), Nat.is_ge(U32.to_nat(r), U32.to_nat(d)), True{}, Equal.sym(Bool, Nat.is_ge(U32.to_nat(r), U32.to_nat(d)), Nat.is_le(U32.to_nat(d), U32.to_nat(r)), Bounds.ge_reverse(U32.to_nat(r), U32.to_nat(d))), Equal.trans(Bool, Nat.is_ge(U32.to_nat(r), U32.to_nat(d)), U32.is_ge(r, d), True{}, Equal.sym(Bool, U32.is_ge(r, d), Nat.is_ge(U32.to_nat(r), U32.to_nat(d)), Compare.u32_ge(r, d)), above))
26  Equal.trans(Nat, U32.to_nat(r), Nat.add(U32.to_nat(d), Nat.sub(U32.to_nat(r), U32.to_nat(d))), Nat.add(U32.to_nat(d), U32.to_nat(U32.sub(r, d))), Equal.sym(Nat, Nat.add(U32.to_nat(d), Nat.sub(U32.to_nat(r), U32.to_nat(d))), U32.to_nat(r), Order.add_complement(U32.to_nat(r), U32.to_nat(d), enough)), Equal.cong(Nat, Nat, x => Nat.add(U32.to_nat(d), x), Nat.sub(U32.to_nat(r), U32.to_nat(d)), U32.to_nat(U32.sub(r, d)), Equal.sym(Nat, U32.to_nat(U32.sub(r, d)), Nat.sub(U32.to_nat(r), U32.to_nat(d)), Sub.u32_exact(r, d, enough))))

Uses (17)

Used by (1)