def read_word

bendtorch-core@0.1.0.0 · src/tensor/reduction_PROOF.bend:287

import bendtorch-core@0.1.0.0/src/tensor/reduction_PROOF.bend as ReductionPROOF
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/lifecycle.bend as Lifecycle
import bendtorch-core@0.1.0.0/src/tensor/reduction.bend as Reduction
import bendtorch-core@0.1.0.0/src/storage/main.bend as Storage
import bendtorch-core@0.1.0.0/src/storage/model.bend as Model
import bendtorch-core@0.1.0.0/src/storage/refinement.bend as Refinement
import bendtorch-core@0.1.0.0/src/storage/route.bend as Route

287# The word a read of slot `index` returns is the one a checked observation
288# of the storage finds there.
289def read_word(-shape: Shape.Shape, +depth: Nat, +length: Nat, -original: Array<F32>, -balanced: Model.Balanced(F32, depth, original),
290  -valid: {Storage.bounds(depth, length) == True{} : Bool},
291  -exact: {length == Shape.logical_numel(Shape.dimensions(shape)) : Nat}, -array: Array<F32>, +index: U32,
292  -pair: Array<F32> & F32, -read: {pair == Array.get(F32, array, index) : Array<F32> & F32},
293  -same: {array == original : Array<F32>}, +value: F32,
294  -observed: {Core.checked_observe(shape, Core.TTensor{Storage.Owned{depth, length, original, balanced, valid}, exact}, index) ==
295    Some{value} : Maybe<&2, F32>}) -> Fact<{Refinement.second(F32, pair) == value : F32}>:
296  Fact{some_injective(Refinement.second(F32, pair), value,
297    Equal.trans(Maybe<&2, F32>, Some{Refinement.second(F32, pair)}, Some{Refinement.second(F32, Array.get(F32, array, index))}, Some{value},
298      Equal.cong(Array<F32> & F32, Maybe<&2, F32>, p => Some{Refinement.second(F32, p)}, pair, Array.get(F32, array, index), read),
299      Equal.trans(Maybe<&2, F32>, Some{Refinement.second(F32, Array.get(F32, array, index))},
300        Model.observe(F32, depth, array, Refinement.route(depth, index)), Some{value},
301        Refinement.law_get_refines(F32, depth, array, index,
302          {\{Reduction.Fact: p => p} : Reduction.Fact<(Model.Balanced(F32, depth, array))> -> Model.Balanced(F32, depth, array)}(
303            Reduction.kept_balanced(depth, original, balanced, array, same))),
304        Equal.trans(Maybe<&2, F32>, Model.observe(F32, depth, array, Refinement.route(depth, index)),
305          Model.observe(F32, depth, original, Refinement.route(depth, index)), Some{value},
306          Equal.cong(Array<F32>, Maybe<&2, F32>, a => Model.observe(F32, depth, a, Refinement.route(depth, index)), array, original, same),
307          Equal.trans(Maybe<&2, F32>, Model.observe(F32, depth, original, Refinement.route(depth, index)),
308            Lifecycle.observe_allowed(depth, length, original, index, Nat.is_lt(U32.to_nat(index), length)), Some{value},
309            Equal.sym(Maybe<&2, F32>, Lifecycle.observe_allowed(depth, length, original, index, Nat.is_lt(U32.to_nat(index), length)),
310              Model.observe(F32, depth, original, Refinement.route(depth, index)),
311              allowed_observe(depth, length, original, index, Nat.is_lt(U32.to_nat(index), length),
312                allowed_true(depth, length, original, index, Nat.is_lt(U32.to_nat(index), length), value, observed),
313                Equal.sym(Bool, True{}, Storage.index_matches(depth, length, index),
314                  Route.index_complete(depth, length, index, valid,
315                    allowed_true(depth, length, original, index, Nat.is_lt(U32.to_nat(index), length), value, observed))))),
316            observed)))))}

Uses (34)

Used by (1)