~/bend-docscommunity

src/tensor/signed_PROOF.bend checks

raw source on the hub · import bendtorch-core@0.1.0.0/src/tensor/signed_PROOF.bend as Signed_PROOF

12 imports
import Base
import ../shape/core.bend as Shape
import ../shape/nat_proofs.bend as NatProofs
import ../storage/arith.bend as Arith
import ./core.bend as Core
import ./layout.bend as Layout
import ./transforms.bend as Transforms
import ./transpose_spec.bend as Transpose
import ./elementwise_totality.bend as Totality
import ./signed.bend as Signed
import ./slice.bend as Slice
import ./signed_LAWS.bend as Laws

Definitions

def lt_self source · line 18 · raw

@+n:Nat -> {Nat.is_lt(n, n) == False{} : Bool}

n < n is false.

def lt_past source · line 26 · raw

@+w:Nat -> @+k:Nat -> {Nat.is_lt(w, Nat.add(w, 1n+k)) == True{} : Bool}

w < w + (k + 1).

def le_from_lt source · line 34 · raw

@+a:Nat -> @+b:Nat -> @h:{Nat.is_lt(a, 1n+b) == True{} : Bool} -> {Nat.is_le(a, b) == True{} : Bool}

a < 1 + b gives a <= b.

def lt_positive source · line 46 · raw

@+a:Nat -> @+b:Nat -> @h:{Nat.is_lt(a, b) == True{} : Bool} -> {Nat.is_le(1n, b) == True{} : Bool}

a < b gives 1 <= b.

def add_succ_right source · line 53 · raw

@+a:Nat -> @+b:Nat -> {Nat.add(a, 1n+b) == 1n+Nat.add(a, b) : Nat}

def add_zero_right source · line 60 · raw

@+a:Nat -> {Nat.add(a, 0n) == a : Nat}

def add_comm source · line 67 · raw

@+a:Nat -> @+b:Nat -> {Nat.add(a, b) == Nat.add(b, a) : Nat}

def last_inside source · line 77 · raw

@+limit:U32 -> @+k:U32 -> @+inside:{U32.is_lt(k, limit) == True{} : Bool} -> {Nat.add(U32.to_nat(U32.sub(U32.sub(limit, 1), k)), 1n+U32.to_nat(k)) == U32.to_nat(limit) : Nat}

Last{k} in range is limit - 1 - k: the two subtractions borrow nothing.

def last_wrapped source · line 101 · raw

@+limit:U32 -> @+k:U32 -> @+inside:{U32.is_lt(k, limit) == True{} : Bool} -> {Nat.add(U32.to_nat(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.wrap(limit, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Last{k})), 1n+U32.to_nat(k)) == U32.to_nat(limit) : Nat}

def last_below source · line 116 · raw

@+limit:U32 -> @+k:U32 -> @+inside:{U32.is_lt(k, limit) == True{} : Bool} -> {U32.is_lt(U32.sub(U32.sub(limit, 1), k), limit) == True{} : Bool}

In range, limit - 1 - k is below limit.

def limit_not_below source · line 129 · raw

@+limit:U32 -> {U32.is_lt(limit, limit) == False{} : Bool}

limit is not below itself.

def last_decided source · line 134 · raw

@+limit:U32 -> @+k:U32 -> @decision:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BoolCase<U32.is_lt(k, limit)> -> {U32.is_lt(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.wrap(limit, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Last{k}), limit) == U32.is_lt(k, limit) : Bool}

def exacts_none source · line 224 · raw

@+dimensions:List<&2, U32> -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.inferred_count(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed_LAWS.exacts(dimensions)) == 0n : Nat}

def exacts_filled source · line 231 · raw

@+dimensions:List<&2, U32> -> @+size:U32 -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.filled(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed_LAWS.exacts(dimensions), size) == dimensions : List<&2, U32>}

def divides source · line 253 · raw

@+count:Nat -> @+rest:Nat -> @+quotient:Nat -> @exact:{Nat.mul(quotient, 1n+rest) == count : Nat} -> {Nat.divmod(count, 1n+rest) == (quotient, 0n) : Pair(Nat, Nat)}

q * (1 + rest) = count gives count divmod (1 + rest) = (q, 0).

def le_add source · line 266 · raw

@+a:Nat -> @+b:Nat -> {Nat.is_le(a, Nat.add(a, b)) == True{} : Bool}

The inference classifies the exact sizes' product against the count (Signed.capped) instead of forming it. These lemmas give capped as the classification of exact_product, so the laws stated with exact_product hold.

def not_le_add source · line 273 · raw

@+a:Nat -> @+b:Nat -> @+c:Nat -> @h:{Nat.is_le(a, c) == False{} : Bool} -> {Nat.is_le(Nat.add(a, b), c) == False{} : Bool}

def lt_not_le source · line 288 · raw

@+b:Nat -> @+a:Nat -> @h:{Nat.is_lt(b, a) == True{} : Bool} -> {Nat.is_le(a, b) == False{} : Bool}

b < a gives a <= b false.

def past_bound source · line 304 · raw

@+bound:Nat -> @+less:Nat -> @+rest:Nat -> @past:{Nat.is_lt(bound, 1n+less) == True{} : Bool} -> {Nat.is_le(Nat.mul(1n+less, 1n+rest), bound) == False{} : Bool}

A size past the bound times a nonzero product is past the bound.

def bounded_classified source · line 310 · raw

@+product:Nat -> @+below:Bool -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.bounded(product, below) == 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed_LAWS.classified(product, below) : 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Product}

signed.bend's cap sorts a product as the laws' classified does.

def times_scaled source · line 317 · raw

@+bound:Nat -> @+less:Nat -> @+rest:Nat -> @decision:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BoolCase<Nat.is_lt(bound, 1n+less)> -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.scaled(bound, 1n+less, 1n+rest, Nat.is_lt(bound, 1n+less)) == 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed_LAWS.classify(bound, Nat.mul(1n+less, 1n+rest)) : 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Product}

def times_within source · line 330 · raw

@+bound:Nat -> @+less:Nat -> @+rest:Nat -> @decision:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BoolCase<Nat.is_le(1n+rest, bound)> -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.times(bound, 1n+less, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed_LAWS.classified(1n+rest, Nat.is_le(1n+rest, bound))) == 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed_LAWS.classify(bound, Nat.mul(1n+less, 1n+rest)) : 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Product}

def times_classify source · line 344 · raw

@+bound:Nat -> @+size:Nat -> @+product:Nat -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.times(bound, size, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed_LAWS.classify(bound, product)) == 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed_LAWS.classify(bound, Nat.mul(size, product)) : 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Product}

times on a classified product classifies the product times the size.

def capped_classifies source · line 358 · raw

@+bound:Nat -> @+extents:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Extent> -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.capped(bound, extents) == 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed_LAWS.classify(bound, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.exact_product(extents)) : 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Product}

def is_within source · line 373 · raw

@product:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Product -> Bool

def within_value source · line 382 · raw

@product:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Product -> Nat

def within_decided source · line 391 · raw

@+bound:Nat -> @+r:Nat -> @+p:Nat -> @+within:{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed_LAWS.classified(1n+r, Nat.is_le(1n+r, bound)) == 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Within{p} : 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Product} -> @decision:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BoolCase<Nat.is_le(1n+r, bound)> -> {Nat.is_le(p, bound) == True{} : Bool}

def classify_within source · line 405 · raw

@+bound:Nat -> @+product:Nat -> @+p:Nat -> @within:{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed_LAWS.classify(bound, product) == 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Within{p} : 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Product} -> {Nat.is_le(p, bound) == True{} : Bool}

def size_beyond source · line 423 · raw

@+count:Nat -> @+extents:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Extent> -> @+rest:Nat -> @+quotient:Nat -> @exact:{Nat.mul(quotient, 1n+rest) == count : Nat} -> @past:{Nat.is_le(1n+rest, count) == False{} : Bool} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.beyond(count, extents) == Done{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.filled(extents, U32.from_nat(quotient))} : Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Error, List<&2, U32>>}

The two branches of a single Inferred size with a nonzero product p: p at most the count divides; p past it leaves an empty input's size 0 and refuses any other.

def size_decided source · line 438 · raw

@+count:Nat -> @+extents:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Extent> -> @+rest:Nat -> @+quotient:Nat -> @exact:{Nat.mul(quotient, 1n+rest) == count : Nat} -> @decision:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BoolCase<Nat.is_le(1n+rest, count)> -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.inferred_one(count, extents, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed_LAWS.classified(1n+rest, Nat.is_le(1n+rest, count))) == Done{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.filled(extents, U32.from_nat(quotient))} : Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Error, List<&2, U32>>}

def pred source · line 461 · raw

@n:Nat -> Nat

def succ_not_zero source · line 468 · raw

@-x:Nat -> @equal:{1n+x == 0n : Nat} -> Empty

def zero_not_one source · line 471 · raw

@equal:{0n == 1n : Nat} -> Empty

def filled_none source · line 475 · raw

@+extents:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Extent> -> @+size:U32 -> @none:{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.inferred_count(extents) == 0n : Nat} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.filled(extents, size)) == 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.exact_product(extents) : Nat}

With no Inferred size, the filled sizes hold the exact product.

def mul_swap source · line 488 · raw

@+e:Nat -> @+s:Nat -> @+p:Nat -> {Nat.mul(e, Nat.mul(s, p)) == Nat.mul(s, Nat.mul(e, p)) : Nat}

e * (s * p) = s * (e * p).

def filled_one source · line 495 · raw

@+extents:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Extent> -> @one:{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.inferred_count(extents) == 1n : Nat} -> @+size:U32 -> {0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.filled(extents, size)) == Nat.mul(U32.to_nat(size), 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.exact_product(extents)) : Nat}

def indivisible_beyond source · line 516 · raw

@+count:Nat -> @+extents:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Extent> -> @+rest:Nat -> @+quotient:Nat -> @+remainder:Nat -> @split:{Nat.divmod(count, 1n+rest) == (quotient, 1n+remainder) : Pair(Nat, Nat)} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.beyond(count, extents) == Fail{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.count_mismatch} : Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Error, List<&2, U32>>}

divmod(0, p) is (0, 0): a remainder means a nonempty input.

def indivisible_decided source · line 527 · raw

@+count:Nat -> @+extents:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Extent> -> @+rest:Nat -> @+quotient:Nat -> @+remainder:Nat -> @split:{Nat.divmod(count, 1n+rest) == (quotient, 1n+remainder) : Pair(Nat, Nat)} -> @decision:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BoolCase<Nat.is_le(1n+rest, count)> -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.inferred_one(count, extents, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed_LAWS.classified(1n+rest, Nat.is_le(1n+rest, count))) == Fail{0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.count_mismatch} : Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Error, List<&2, U32>>}

def bound_inside source · line 586 · raw

@+limit:U32 -> @+k:U32 -> @+inside:{U32.is_lt(k, limit) == True{} : Bool} -> {Nat.add(U32.to_nat(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.bound(limit, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Last{k})), 1n+U32.to_nat(k)) == U32.to_nat(limit) : Nat}