~/bend-docscommunity

LAWS_div.bend open laws/TODOs

raw source on the hub · import bend-osdev-u32@0.1.0.0/LAWS_div.bend as LAWS_div

Base's Nat division by a divisor 1 + bp (every positive divisor), as the packages' proofs use it: quotient and remainder recompose the dividend, the remainder is below the divisor, a dividend g (1 + bp) + i with i below the divisor has quotient g and remainder i, and rounding a up to a multiple of the divisor adds the slack (1 + bp - 1) - (a + bp) mod (1 + bp).

1 import
import Base

Laws

law nat_div_mod provedin PROOF_div.bend

Also proved in bend-mathlib as nat.div_mod_eq: import bend-mathlib@0.8.2.0/nat.bend as MNat, then MNat.div_mod_eq.

source · line 8 · raw

@+a:Nat -> @+bp:Nat -> {Nat.add(Nat.mul(Nat.div(a, 1n+bp), 1n+bp), Nat.mod(a, 1n+bp)) == a : Nat}

law nat_mod_lt provedin PROOF_div.bendsource · line 13 · raw

@+a:Nat -> @+bp:Nat -> {Nat.is_lt(Nat.mod(a, 1n+bp), 1n+bp) == True{} : Bool}

law nat_divmod_exact provedin PROOF_div.bendsource · line 18 · raw

@+g:Nat -> @+i:Nat -> @+bp:Nat -> @h:{Nat.is_lt(i, 1n+bp) == True{} : Bool} -> {Nat.divmod(Nat.add(Nat.mul(g, 1n+bp), i), 1n+bp) == (g, i) : Pair(Nat, Nat)}

law nat_round_up provedin PROOF_div.bendsource · line 25 · raw

@+bp:Nat -> @+a:Nat -> {Nat.mul(Nat.div(Nat.add(a, Nat.sub(1n+bp, 1n)), 1n+bp), 1n+bp) == Nat.add(a, Nat.sub(Nat.sub(1n+bp, 1n), Nat.mod(Nat.add(a, Nat.sub(1n+bp, 1n)), 1n+bp))) : Nat}