def read_certificate_interpretation

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

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/reduction.bend as Reduction
import bendtorch-core@0.1.0.0/src/tensor/reduction_LAWS.bend as Laws

88def read_certificate_interpretation(+fuel: Nat, -shape: Shape.Shape, -original: Core.Tensor<shape>, +cursor: Nat,
89  +accumulator: F32, +head: F32, +values: List<&2, F32>,
90  rec: @tensor: Core.Tensor<shape> -> @logical: Laws.LogicalValues(fuel, shape, tensor, 1n+cursor, values) ->
91    {Laws.loop_value(shape, Reduction.natural_sum_loop(fuel, shape, tensor, 1n+cursor, F32.add(accumulator, head))) ==
92      Some{Reduction.sequential_sum(values, F32.add(accumulator, head))} : Maybe<&2, F32>},
93  observed: {Core.checked_observe(shape, original, U32.from_nat(cursor)) == Some{head} : Maybe<&2, F32>},
94  remaining: Laws.LogicalValues(fuel, shape, original, 1n+cursor, values), certificate: Core.Read<shape, original, U32.from_nat(cursor)>,
95  meaning: {Core.read_value(shape, Core.read_flat(shape, original, U32.from_nat(cursor))) == Core.checked_observe(shape, original, U32.from_nat(cursor)) : Maybe<&2, F32>},
96  -kept: @+other: U32 -> {Core.retained_read_observe(shape, Core.read_flat(shape, original, U32.from_nat(cursor)), other) == Core.checked_observe(shape, original, other) : Maybe<&2, F32>}) ->
97  {Laws.loop_value(shape, Reduction.read_step(shape,
98    tensor => value => Reduction.natural_sum_loop(fuel, shape, tensor, 1n+cursor, value), accumulator, Core.read_flat(shape, original, U32.from_nat(cursor)))) ==
99    Some{Reduction.sequential_sum(head <> values, accumulator)} : Maybe<&2, F32>}:
100  Core.Read{tensor, +result, +exact} = certificate
101  %exact :
102    {Laws.loop_value(shape, Reduction.read_step(shape,
103      tensor => value => Reduction.natural_sum_loop(fuel, shape, tensor, 1n+cursor, value), accumulator, _)) ==
104      Some{Reduction.sequential_sum(head <> values, accumulator)} : Maybe<&2, F32>}
105  read_interpretation(fuel, shape, original, cursor, accumulator, head, values, tensor, result, rec, remaining,
106    Equal.trans(Maybe<&2, F32>, Core.result_value(result), Core.checked_observe(shape, original, U32.from_nat(cursor)), Some{head},
107      Equal.trans(Maybe<&2, F32>, Core.result_value(result), Core.read_value(shape, Core.read_flat(shape, original, U32.from_nat(cursor))),
108        Core.checked_observe(shape, original, U32.from_nat(cursor)),
109        Equal.cong(Core.Tensor<shape> & Result<&2, &2, Core.Error, F32>, Maybe<&2, F32>, pair => Core.read_value(shape, pair),
110          (tensor, result), Core.read_flat(shape, original, U32.from_nat(cursor)), exact),
111        meaning), observed),
112    other => Equal.trans(Maybe<&2, F32>, Core.checked_observe(shape, tensor, other),
113      Core.retained_read_observe(shape, Core.read_flat(shape, original, U32.from_nat(cursor)), other), Core.checked_observe(shape, original, other),
114      Equal.cong(Core.Tensor<shape> & Result<&2, &2, Core.Error, F32>, Maybe<&2, F32>, pair => Core.retained_read_observe(shape, pair, other),
115        (tensor, result), Core.read_flat(shape, original, U32.from_nat(cursor)), exact), kept(other)))

Uses (27)

Used by (1)