proofs/nat_division_order.bend checks
raw source on the hub · import stelliferous@0.0.3.0/proofs/nat_division_order.bend as Nat_division_order
Natural division by a positive divisor: the quotient/remainder identity and monotone quotients, plus monotone truncated subtraction.
6 imports
import Base import ./nat_order.bend as Order import ./nat_division.bend as Division import ./natural_addition.bend as Addition import ./row_major_index.bend as RowMajor import ./word_encoding.bend as WordEncoding
Types
type Witness source · line 10 · raw
@-value:Nat -> @-divisor:Nat -> Data
Witness@-value:Nat -> @-divisor:Nat -> @quotient:Nat -> @remainder:Nat -> @exact:{value == Nat.add(Nat.mul(quotient, divisor), remainder) : Nat} -> @small:{Nat.is_lt(remainder, divisor) == True{} : Bool} -> Witness<value, divisor>
Definitions
def not_below source · line 14 · raw
@+value:Nat -> @+limit:Nat -> @+below:{Nat.is_lt(value, limit) == True{} : Bool} -> @+outside:{Nat.is_lt(1n+value, limit) == False{} : Bool} -> {1n+value == limit : Nat}
def advanced source · line 26 · raw
@+value:Nat -> @+divisor:Nat -> @+quotient:Nat -> @+remainder:Nat -> @+inside:Bool -> @+exact:{value == Nat.add(Nat.mul(quotient, divisor), remainder) : Nat} -> @+small:{Nat.is_lt(remainder, divisor) == True{} : Bool} -> @+positive:{Nat.is_lt(0n, divisor) == True{} : Bool} -> @+next:{Nat.is_lt(1n+remainder, divisor) == inside : Bool} -> Witness<1n+value, divisor>
def successor source · line 48 · raw
@+value:Nat -> @+divisor:Nat -> @+positive:{Nat.is_lt(0n, divisor) == True{} : Bool} -> @+previous:Witness<value, divisor> -> Witness<1n+value, divisor>
def observed_quotient source · line 52 · raw
@-value:Nat -> @-divisor:Nat -> @found:Witness<value, divisor> -> Nat
def observed_remainder source · line 56 · raw
@-value:Nat -> @-divisor:Nat -> @found:Witness<value, divisor> -> Nat
def observed_pair source · line 60 · raw
@+value:Nat -> @+divisor:Nat -> @+found:Witness<value, divisor> -> @positive:{Nat.is_lt(0n, divisor) == True{} : Bool} -> {Nat.divmod(value, divisor) == (observed_quotient(value, divisor, found), observed_remainder(value, divisor, found)) : Pair(Nat, Nat)}
def advanced_pair source · line 65 · raw
@+value:Nat -> @+divisor:Nat -> @+quotient:Nat -> @+remainder:Nat -> @inside:Bool -> @+exact:{value == Nat.add(Nat.mul(quotient, divisor), remainder) : Nat} -> @+small:{Nat.is_lt(remainder, divisor) == True{} : Bool} -> @+positive:{Nat.is_lt(0n, divisor) == True{} : Bool} -> @+next:{Nat.is_lt(1n+remainder, divisor) == inside : Bool} -> {Nat.divmod(1n+value, divisor) == Bool.pick(Pair(Nat, Nat), inside, (quotient, 1n+remainder), (1n+quotient, 0n)) : Pair(Nat, Nat)}
def increment_case source · line 73 · raw
@+value:Nat -> @+divisor:Nat -> @+quotient:Nat -> @+remainder:Nat -> @+exact:{value == Nat.add(Nat.mul(quotient, divisor), remainder) : Nat} -> @+small:{Nat.is_lt(remainder, divisor) == True{} : Bool} -> @+positive:{Nat.is_lt(0n, divisor) == True{} : Bool} -> @which:0xd6aaab858a4fbd1461bd0fee27b97184/proofs/nat_order.UpperBound<1n+remainder, divisor> -> {Nat.divmod(1n+value, divisor) == Bool.pick(Pair(Nat, Nat), Nat.is_eq(1n+remainder, divisor), (1n+quotient, 0n), (quotient, 1n+remainder)) : Pair(Nat, Nat)}
def witness source · line 89 · raw
@+value:Nat -> @+divisor:Nat -> @+positive:{Nat.is_lt(0n, divisor) == True{} : Bool} -> Witness<value, divisor>
def quotient_exact_of source · line 94 · raw
@+value:Nat -> @+divisor:Nat -> @+positive:{Nat.is_lt(0n, divisor) == True{} : Bool} -> @+found:Witness<value, divisor> -> {value == Nat.add(Nat.mul(Nat.div(value, divisor), divisor), Nat.mod(value, divisor)) : Nat}
def quotient_exact source · line 101 · raw
@+value:Nat -> @+divisor:Nat -> @+positive:{Nat.is_lt(0n, divisor) == True{} : Bool} -> {value == Nat.add(Nat.mul(Nat.div(value, divisor), divisor), Nat.mod(value, divisor)) : Nat}
def remainder_small_of source · line 105 · raw
@+value:Nat -> @+divisor:Nat -> @+positive:{Nat.is_lt(0n, divisor) == True{} : Bool} -> @+found:Witness<value, divisor> -> {Nat.is_lt(Nat.mod(value, divisor), divisor) == True{} : Bool}
def remainder_small source · line 112 · raw
@+value:Nat -> @+divisor:Nat -> @+positive:{Nat.is_lt(0n, divisor) == True{} : Bool} -> {Nat.is_lt(Nat.mod(value, divisor), divisor) == True{} : Bool}
def remainder_le source · line 116 · raw
@+value:Nat -> @+divisor:Nat -> @+positive:{Nat.is_lt(0n, divisor) == True{} : Bool} -> {Nat.is_le(Nat.mod(value, divisor), value) == True{} : Bool}
def product_below source · line 122 · raw
@+value:Nat -> @+divisor:Nat -> @+positive:{Nat.is_lt(0n, divisor) == True{} : Bool} -> {Nat.is_le(Nat.mul(Nat.div(value, divisor), divisor), value) == True{} : Bool}
def next_above source · line 128 · raw
@+value:Nat -> @+divisor:Nat -> @+positive:{Nat.is_lt(0n, divisor) == True{} : Bool} -> {Nat.is_lt(value, Nat.mul(1n+Nat.div(value, divisor), divisor)) == True{} : Bool}
def quotient_below source · line 140 · raw
@+value:Nat -> @+limit:Nat -> @+divisor:Nat -> @positive:{Nat.is_lt(0n, divisor) == True{} : Bool} -> @inside:{Nat.is_lt(value, Nat.mul(limit, divisor)) == True{} : Bool} -> {Nat.is_lt(Nat.div(value, divisor), limit) == True{} : Bool}
def quotient_le source · line 145 · raw
@+smaller:Nat -> @+larger:Nat -> @+divisor:Nat -> @+positive:{Nat.is_lt(0n, divisor) == True{} : Bool} -> @+ordered:{Nat.is_le(smaller, larger) == True{} : Bool} -> {Nat.is_le(Nat.div(smaller, divisor), Nat.div(larger, divisor)) == True{} : Bool}
def subtract_le source · line 153 · raw
@+smaller:Nat -> @+larger:Nat -> @+amount:Nat -> @+ordered:{Nat.is_le(smaller, larger) == True{} : Bool} -> {Nat.is_le(Nat.sub(smaller, amount), Nat.sub(larger, amount)) == True{} : Bool}
def shifted_exact source · line 166 · raw
@+value:Nat -> @+divisor:Nat -> @+rows:Nat -> @+positive:{Nat.is_lt(0n, divisor) == True{} : Bool} -> {Nat.add(Nat.mul(rows, divisor), value) == Nat.add(Nat.mul(Nat.add(rows, Nat.div(value, divisor)), divisor), Nat.mod(value, divisor)) : Nat}Adding whole rows changes the quotient and preserves the remainder.
def shifted_pair source · line 176 · raw
@+value:Nat -> @+divisor:Nat -> @+rows:Nat -> @+positive:{Nat.is_lt(0n, divisor) == True{} : Bool} -> {Nat.divmod(Nat.add(Nat.mul(rows, divisor), value), divisor) == (Nat.add(rows, Nat.div(value, divisor)), Nat.mod(value, divisor)) : Pair(Nat, Nat)}
def quotient_shift source · line 180 · raw
@+value:Nat -> @+divisor:Nat -> @+rows:Nat -> @+positive:{Nat.is_lt(0n, divisor) == True{} : Bool} -> {Nat.div(Nat.add(Nat.mul(rows, divisor), value), divisor) == Nat.add(rows, Nat.div(value, divisor)) : Nat}
def remainder_shift source · line 184 · raw
@+value:Nat -> @+divisor:Nat -> @+rows:Nat -> @+positive:{Nat.is_lt(0n, divisor) == True{} : Bool} -> {Nat.mod(Nat.add(Nat.mul(rows, divisor), value), divisor) == Nat.mod(value, divisor) : Nat}
def multiply_left_le source · line 188 · raw
@+factor:Nat -> @+smaller:Nat -> @+larger:Nat -> @+ordered:{Nat.is_le(smaller, larger) == True{} : Bool} -> {Nat.is_le(Nat.mul(factor, smaller), Nat.mul(factor, larger)) == True{} : Bool}
def right_factor_positive source · line 194 · raw
@+head:Nat -> @+tail:Nat -> @positive:{Nat.is_lt(0n, Nat.mul(head, tail)) == True{} : Bool} -> {Nat.is_lt(0n, tail) == True{} : Bool}
def le_multiple source · line 197 · raw
@+images:Nat -> @+elements:Nat -> @positive:{Nat.is_lt(0n, images) == True{} : Bool} -> {Nat.is_le(elements, Nat.mul(images, elements)) == True{} : Bool}
def subtract_sum source · line 202 · raw
@+a:Nat -> @+b:Nat -> {Nat.sub(Nat.add(a, b), b) == a : Nat}