~/bend-docscommunity

src/tensor/matrix_index_proof.bend checks

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

13 imports
import Base
import ../shape/core.bend as Shape
import ../shape/LAWS.bend as ShapeLaws
import ../shape/PROOF.bend as ShapeProof
import ../shape/boundary_proofs.bend as Boundary
import ../shape/coordinate_proofs.bend as Coordinates
import ../shape/nat_proofs.bend as Nats
import ../shape/index_proofs.bend as Index
import ../storage/arith.bend as Arith
import ../storage/api.bend as Api
import ./matmul.bend as Matrix
import ./word_conversion.bend as Conversion
import ./read_contract.bend as Reads

Definitions

def word_exact source · line 18 · raw

@+number:Nat -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @below:{Nat.is_lt(number, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(shape))) == True{} : Bool} -> {U32.to_nat(U32.from_nat(number)) == number : Nat}

def word_inside source · line 26 · raw

@+number:Nat -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+below:{Nat.is_lt(number, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(shape))) == True{} : Bool} -> {Nat.is_lt(U32.to_nat(U32.from_nat(number)), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(shape))) == True{} : Bool}

def lt_mul_add source · line 33 · raw

@+a:Nat -> @+m:Nat -> @+b:Nat -> @+n:Nat -> @a_below:{Nat.is_lt(a, m) == True{} : Bool} -> @b_below:{Nat.is_lt(b, n) == True{} : Bool} -> {Nat.is_lt(Nat.add(Nat.mul(a, n), b), Nat.mul(m, n)) == True{} : Bool}

def left_below source · line 47 · raw

@+rows:Nat -> @+inner:Nat -> @+row:Nat -> @row_below:{Nat.is_lt(row, rows) == True{} : Bool} -> @+left:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @left_extents:{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(left) == [rows, inner] : List<&2, Nat>} -> @+k:Nat -> @below:{Nat.is_lt(k, inner) == True{} : Bool} -> {Nat.is_lt(Nat.add(Nat.mul(row, inner), k), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(left))) == True{} : Bool}

Factor k of cell (row, column) lies inside each input.

def right_below source · line 56 · raw

@+inner:Nat -> @+columns:Nat -> @+column:Nat -> @column_below:{Nat.is_lt(column, columns) == True{} : Bool} -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @right_extents:{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(right) == [inner, columns] : List<&2, Nat>} -> @+k:Nat -> @below:{Nat.is_lt(k, inner) == True{} : Bool} -> {Nat.is_lt(Nat.add(Nat.mul(k, columns), column), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(right))) == True{} : Bool}

def lt_from source · line 65 · raw

@+a:Nat -> @+b:Nat -> @below:{Nat.is_lt(a, b) == True{} : Bool} -> 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.LT(a, b)

def lt_same source · line 76 · raw

@-a:Nat -> @-b:Nat -> @-bound:Nat -> @same:{a == b : Nat} -> @below:{Nat.is_lt(b, bound) == True{} : Bool} -> {Nat.is_lt(a, bound) == True{} : Bool}

def lt_bound source · line 81 · raw

@-a:Nat -> @-bound:Nat -> @-other:Nat -> @same:{bound == other : Nat} -> @below:{Nat.is_lt(a, bound) == True{} : Bool} -> {Nat.is_lt(a, other) == True{} : Bool}

def word_below source · line 86 · raw

@+number:Nat -> @+limit:U32 -> @below:{Nat.is_lt(number, U32.to_nat(limit)) == True{} : Bool} -> {U32.to_nat(U32.from_nat(number)) == number : Nat}

def some_equal source · line 90 · raw

@-A:Data -> @-x:A -> @-y:A -> @equal:{Some{x} == Some{y} : Maybe<&2, A>} -> {x == y : A}

def div_one source · line 93 · raw

@+number:Nat -> {Nat.div(number, 1n) == number : Nat}

def row_at source · line 99 · raw

@+row:Nat -> @+column:Nat -> @+columns:Nat -> @below:{Nat.is_lt(column, columns) == True{} : Bool} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/matmul.row_of(columns, Nat.add(Nat.mul(row, columns), column)) == row : Nat}

def column_at source · line 107 · raw

@+row:Nat -> @+column:Nat -> @+columns:Nat -> @below:{Nat.is_lt(column, columns) == True{} : Bool} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/matmul.column_of(columns, Nat.add(Nat.mul(row, columns), column)) == column : Nat}

def position_digits source · line 115 · raw

@+output:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+rows:Nat -> @+columns:Nat -> @extents:{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(output) == [rows, columns] : List<&2, Nat>} -> @+position:Nat -> @+fits:{True{} == Nat.is_lt(position, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(output))) : Bool} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.indices(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(output), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.unflatten(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(output), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/coordinate_proofs.fin_from(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(output)), position, fits))) == [0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/matmul.row_of(columns, position), 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/matmul.column_of(columns, position)] : List<&2, Nat>}

def unflatten_at source · line 132 · raw

@+output:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+rows:Nat -> @+columns:Nat -> @extents:{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(output) == [rows, columns] : List<&2, Nat>} -> @+position:Nat -> @+below:{Nat.is_lt(position, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(output))) == True{} : Bool} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/shape/LAWS.coordinate_result(output, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.unflatten_checked(output, U32.from_nat(position))) == Some{[U32.from_nat(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/matmul.row_of(columns, position)), U32.from_nat(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/matmul.column_of(columns, position))]} : Maybe<&2, List<&2, U32>>}

def position_fits source · line 161 · raw

@+output:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+rows:Nat -> @+columns:Nat -> @+extents:{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(output) == [rows, columns] : List<&2, Nat>} -> @+position:Nat -> @+below:{Nat.is_lt(position, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(output))) == True{} : Bool} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.fit([rows, columns], [0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/matmul.row_of(columns, position), 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/matmul.column_of(columns, position)]) == True{} : Bool}

def offset_pair source · line 178 · raw

@+a:Nat -> @+b:Nat -> @+first:Nat -> @+second:Nat -> {0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.offset([first, second], [a, b]) == Nat.add(Nat.mul(a, second), b) : Nat}

def flat_pair source · line 188 · raw

@+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+first:U32 -> @+second:U32 -> @+x:U32 -> @+y:U32 -> @+dimensions:{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(shape) == [first, second] : List<&2, U32>} -> @x_inside:{Nat.is_lt(U32.to_nat(x), U32.to_nat(first)) == True{} : Bool} -> @y_inside:{Nat.is_lt(U32.to_nat(y), U32.to_nat(second)) == True{} : Bool} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/shape/LAWS.index_result(shape, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.flatten_checked(shape, [x, y])) == Some{U32.from_nat(Nat.add(Nat.mul(U32.to_nat(x), U32.to_nat(second)), U32.to_nat(y)))} : Maybe<&2, U32>}

def index_same source · line 218 · raw

@+a:Nat -> @+b:Nat -> @+x:Nat -> @+y:Nat -> @+stride:Nat -> @ax:{a == x : Nat} -> @by:{b == y : Nat} -> {Some{U32.from_nat(Nat.add(Nat.mul(a, stride), b))} == Some{U32.from_nat(Nat.add(Nat.mul(x, stride), y))} : Maybe<&2, U32>}

def lt_add source · line 225 · raw

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

def cursor_below source · line 233 · raw

@+cursor:Nat -> @+rest:Nat -> @+end:Nat -> @steps:{Nat.add(cursor, 1n+rest) == end : Nat} -> {Nat.is_lt(cursor, end) == True{} : Bool}

A cursor with steps left lies below the end.

def steps_next source · line 238 · raw

@+cursor:Nat -> @+rest:Nat -> @+end:Nat -> @steps:{Nat.add(cursor, 1n+rest) == end : Nat} -> {Nat.add(1n+cursor, rest) == end : Nat}

def stepped_left source · line 245 · raw

@+inner:Nat -> @+row:Nat -> @+k:Nat -> {Nat.add(1n, Nat.add(Nat.mul(row, inner), k)) == Nat.add(Nat.mul(row, inner), 1n+k) : Nat}

A matmul cell steps its left offset by one word and its right offset by a row of columns words: the term after term k sits at the offsets of k + 1.

def stepped_right source · line 249 · raw

@+columns:Nat -> @+column:Nat -> @+k:Nat -> {Nat.add(columns, Nat.add(Nat.mul(k, columns), column)) == Nat.add(Nat.mul(1n+k, columns), column) : Nat}