def dot_extend

bendtorch-core@0.1.0.0 · src/tensor/matmul_PROOF.bend:126

import bendtorch-core@0.1.0.0/src/tensor/matmul_PROOF.bend as MatmulPROOF
import Base
import bendtorch-core@0.1.0.0/src/shape/core.bend as Shape
import bendtorch-core@0.1.0.0/src/tensor/core.bend as Core
import bendtorch-core@0.1.0.0/src/tensor/matmul.bend as Matrix
import bendtorch-core@0.1.0.0/src/tensor/matmul_LAWS.bend as Laws
import bendtorch-core@0.1.0.0/src/tensor/dot_fold.bend as DotFold

126def dot_extend(+fuel: Nat, +left: Shape.Shape, +right: Shape.Shape, -a: Core.Tensor<left>, -b: Core.Tensor<right>,
127  -ra: Core.Tensor<left>, -rb: Core.Tensor<right>, +row: U32, +column: U32, +cursor: Nat, +accumulator: F32, +lv: F32, +rv: F32,
128  result: Result<&2, &1, Matrix.Error, Core.Tensor<left> & Core.Tensor<right> & F32>,
129  next: Laws.DotResultMeaning(fuel, left, right, ra, rb, row, column, 1n+cursor, F32.add(accumulator, F32.mul(lv, rv)), result),
130  -exact: {U32.to_nat(U32.from_nat(cursor)) == cursor : Nat},
131  -lo: {Laws.coordinate_observe(left, a, [row, U32.from_nat(cursor)]) == Some{lv} : Maybe<&2, F32>},
132  -ro: {Laws.coordinate_observe(right, b, [U32.from_nat(cursor), column]) == Some{rv} : Maybe<&2, F32>},
133  -left_kept: @+other: U32 -> {Core.checked_observe(left, ra, other) == Core.checked_observe(left, a, other) : Maybe<&2, F32>},
134  -right_kept: @+other: U32 -> {Core.checked_observe(right, rb, other) == Core.checked_observe(right, b, other) : Maybe<&2, F32>}) ->
135  Laws.DotResultMeaning(1n+fuel, left, right, a, b, row, column, cursor, accumulator, result):
136  match result:
137    case Fail{error}:
138      Unit{}
139    case Done{pair}:
140      (final_a, final_b, value) = pair
141      Laws.DotMeaning{values, logical, fold, lk, rk} = next
142      Laws.DotMeaning{DotFold.Factors{lv, rv} <> values,
143        Laws.DotStep{exact, lo, ro, logical_dot_original(fuel, left, right, a, b, ra, rb, row, column, 1n+cursor, values, logical, left_kept, right_kept)}, fold,
144        other => Equal.trans(Maybe<&2, F32>, Core.checked_observe(left, final_a, other),
145          Core.checked_observe(left, ra, other), Core.checked_observe(left, a, other), lk(other), left_kept(other)),
146        other => Equal.trans(Maybe<&2, F32>, Core.checked_observe(right, final_b, other),
147          Core.checked_observe(right, rb, other), Core.checked_observe(right, b, other), rk(other), right_kept(other))}

Uses (24)

Used by (1)