def write_spec

bendtorch-core@0.1.0.0 · src/tensor/contracts/matmul_parallel_proof.bend:316

import bendtorch-core@0.1.0.0/src/tensor/contracts/matmul_parallel_proof.bend as MatmulParallelProof
import Base
import bendtorch-core@0.1.0.0/src/shape/core.bend as Shape
import bendtorch-core@0.1.0.0/src/storage/model.bend as Model
import bendtorch-core@0.1.0.0/src/storage/LAWS.bend as StorageLaws
import bendtorch-core@0.1.0.0/src/shape/index_proofs.bend as Index
import bendtorch-core@0.1.0.0/src/storage/array.bend as ArrayCore
import bendtorch-core@0.1.0.0/src/storage/api.bend as Api

316# Writing cell k at the path whose position is k turns the spec for k into
317# the spec for 1 + k.
318def write_spec(+span: Nat, +columns: Nat, +left: Shape.Shape, +left_fill: F32, +left_ops: List<&2, StorageLaws.Op>, +right: Shape.Shape, +right_fill: F32, +right_ops: List<&2, StorageLaws.Op>, +k: Nat, +depth: Nat, +base: Nat, +path: Model.Path(depth),
319  +h: {Nat.add(Model.offset(depth, path), base) == k : Nat}) ->
320  {ArrayCore.write_path(F32, depth, out_spec(span, columns, left, left_fill, left_ops, right, right_fill, right_ops, k, depth, base), path, cell_word(span, columns, left, left_fill, left_ops, right, right_fill, right_ops, k)) == out_spec(span, columns, left, left_fill, left_ops, right, right_fill, right_ops, 1n+k, depth, base) : Array<F32>}:
321  match depth:
322    case 0n:
323      %h : {ALeaf{cell_word(span, columns, left, left_fill, left_ops, right, right_fill, right_ops, _)} == ALeaf{out_leaf(span, columns, left, left_fill, left_ops, right, right_fill, right_ops, base, Nat.is_lt(base, 1n+_))} : Array<F32>}
324      %Equal.sym(Bool, Nat.is_lt(base, 1n+base), True{}, lt_self_succ(base)) :
325        {ALeaf{cell_word(span, columns, left, left_fill, left_ops, right, right_fill, right_ops, base)} == ALeaf{out_leaf(span, columns, left, left_fill, left_ops, right, right_fill, right_ops, base, _)} : Array<F32>}
326      {==}
327    case 1n+inner:
328      Model.Step{+bit, +rest} = path
329      match bit:
330        case False{}:
331          +c = Model.capacity(inner)
332          +high = Nat.add(c, base)
333          +inside = Equal.trans(Bool, Nat.is_lt(k, high), Nat.is_lt(Nat.add(Model.offset(inner, rest), base), high), True{},
334            Equal.cong(Nat, Bool, x => Nat.is_lt(x, high), k, Nat.add(Model.offset(inner, rest), base),
335              Equal.sym(Nat, Nat.add(Model.offset(inner, rest), base), k, h)),
336            lt_add_right(Model.offset(inner, rest), c, base, Api.offset_lt(inner, rest)))
337          %Equal.sym(Array<F32>, ArrayCore.write_path(F32, inner, out_spec(span, columns, left, left_fill, left_ops, right, right_fill, right_ops, k, inner, base), rest, cell_word(span, columns, left, left_fill, left_ops, right, right_fill, right_ops, k)),
338            out_spec(span, columns, left, left_fill, left_ops, right, right_fill, right_ops, 1n+k, inner, base), write_spec(span, columns, left, left_fill, left_ops, right, right_fill, right_ops, k, inner, base, rest, h)) :
339            {ANode{_, out_spec(span, columns, left, left_fill, left_ops, right, right_fill, right_ops, k, inner, high)} == out_spec(span, columns, left, left_fill, left_ops, right, right_fill, right_ops, 1n+k, 1n+inner, base) : Array<F32>}
340          %Equal.sym(Array<F32>, out_spec(span, columns, left, left_fill, left_ops, right, right_fill, right_ops, k, inner, high), out_spec(span, columns, left, left_fill, left_ops, right, right_fill, right_ops, 1n+k, inner, high), above(span, columns, left, left_fill, left_ops, right, right_fill, right_ops, k, inner, high, inside)) :
341            {ANode{out_spec(span, columns, left, left_fill, left_ops, right, right_fill, right_ops, 1n+k, inner, base), _} == out_spec(span, columns, left, left_fill, left_ops, right, right_fill, right_ops, 1n+k, 1n+inner, base) : Array<F32>}
342          {==}
343        case True{}:
344          +c = Model.capacity(inner)
345          +high = Nat.add(c, base)
346          +off = Model.offset(inner, rest)
347          +lower = Equal.trans(Bool, Nat.is_le(high, k), Nat.is_le(high, Nat.add(c, Nat.add(off, base))), True{},
348            Equal.cong(Nat, Bool, x => Nat.is_le(high, x), k, Nat.add(c, Nat.add(off, base)),
349              Equal.trans(Nat, k, Nat.add(Nat.add(c, off), base), Nat.add(c, Nat.add(off, base)),
350                Equal.sym(Nat, Nat.add(Nat.add(c, off), base), k, h),
351                Equal.sym(Nat, Nat.add(c, Nat.add(off, base)), Nat.add(Nat.add(c, off), base), Index.add_assoc(c, off, base)))),
352            le_add_cong(c, base, Nat.add(off, base), Api.le_add_left(off, base)))
353          +shifted = Equal.trans(Nat, Nat.add(off, high), Nat.add(Nat.add(c, off), base), k, position_step(c, off, base), h)
354          %Equal.sym(Array<F32>, out_spec(span, columns, left, left_fill, left_ops, right, right_fill, right_ops, k, inner, base), out_spec(span, columns, left, left_fill, left_ops, right, right_fill, right_ops, 1n+k, inner, base), below(span, columns, left, left_fill, left_ops, right, right_fill, right_ops, k, inner, base, lower)) :
355            {ANode{_, ArrayCore.write_path(F32, inner, out_spec(span, columns, left, left_fill, left_ops, right, right_fill, right_ops, k, inner, high), rest, cell_word(span, columns, left, left_fill, left_ops, right, right_fill, right_ops, k))} == out_spec(span, columns, left, left_fill, left_ops, right, right_fill, right_ops, 1n+k, 1n+inner, base) : Array<F32>}
356          %Equal.sym(Array<F32>, ArrayCore.write_path(F32, inner, out_spec(span, columns, left, left_fill, left_ops, right, right_fill, right_ops, k, inner, high), rest, cell_word(span, columns, left, left_fill, left_ops, right, right_fill, right_ops, k)),
357            out_spec(span, columns, left, left_fill, left_ops, right, right_fill, right_ops, 1n+k, inner, high), write_spec(span, columns, left, left_fill, left_ops, right, right_fill, right_ops, k, inner, high, rest, shifted)) :
358            {ANode{out_spec(span, columns, left, left_fill, left_ops, right, right_fill, right_ops, 1n+k, inner, base), _} == out_spec(span, columns, left, left_fill, left_ops, right, right_fill, right_ops, 1n+k, 1n+inner, base) : Array<F32>}
359          {==}

Uses (30)

Used by (1)