def preserved_certificate

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

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

196def preserved_certificate(+fuel: Nat, -shape: Shape.Shape, -original: Core.Tensor<shape>, +cursor: Nat, +accumulator: F32,
197  -rec: @tensor: Core.Tensor<shape> -> @+value: F32 -> Laws.Preserved<shape, tensor, Reduction.natural_sum_loop(fuel, shape, tensor, 1n+cursor, value)>,
198  certificate: Core.Read<shape, original, U32.from_nat(cursor)>, -retention: Core.SourceReadKeeps<shape, original, U32.from_nat(cursor)>) ->
199  Laws.Preserved<shape, original, Reduction.read_step(shape,
200    tensor => value => Reduction.natural_sum_loop(fuel, shape, tensor, 1n+cursor, value), accumulator, Core.read_flat(shape, original, U32.from_nat(cursor)))>:
201  Core.Read{tensor, +result, +exact} = certificate
202  Laws.Preserved{other =>
203    claim : @certificate: Laws.Preserved<shape, original, Reduction.read_step(shape,
204      tensor => value => Reduction.natural_sum_loop(fuel, shape, tensor, 1n+cursor, value), accumulator, (tensor, result))> ->
205      {Laws.retained_observe(shape, Reduction.read_step(shape,
206        tensor => value => Reduction.natural_sum_loop(fuel, shape, tensor, 1n+cursor, value), accumulator, (tensor, result)), other) ==
207        Laws.successful_observe(shape, original, Reduction.read_step(shape,
208          tensor => value => Reduction.natural_sum_loop(fuel, shape, tensor, 1n+cursor, value), accumulator, (tensor, result)), other) : Maybe<&2, F32>} =
209      \{Laws.Preserved: kept => kept(other)}
210    prove : @retention: Core.SourceReadKeeps<shape, original, U32.from_nat(cursor)> ->
211      {Laws.retained_observe(shape, Reduction.read_step(shape,
212        tensor => value => Reduction.natural_sum_loop(fuel, shape, tensor, 1n+cursor, value), accumulator, Core.read_flat(shape, original, U32.from_nat(cursor))), other) ==
213        Laws.successful_observe(shape, original, Reduction.read_step(shape,
214          tensor => value => Reduction.natural_sum_loop(fuel, shape, tensor, 1n+cursor, value), accumulator, Core.read_flat(shape, original, U32.from_nat(cursor))), other) : Maybe<&2, F32>} =
215      \{Core.SourceReadKeeps: kept =>
216      %exact :
217        {Laws.retained_observe(shape, Reduction.read_step(shape,
218          tensor => value => Reduction.natural_sum_loop(fuel, shape, tensor, 1n+cursor, value), accumulator, _), other) ==
219          Laws.successful_observe(shape, original, Reduction.read_step(shape,
220            tensor => value => Reduction.natural_sum_loop(fuel, shape, tensor, 1n+cursor, value), accumulator, _), other) : Maybe<&2, F32>}
221      claim(preserved_read(fuel, shape, original, cursor, accumulator, tensor, result, rec,
222        other => Equal.trans(Maybe<&2, F32>, Core.checked_observe(shape, tensor, other),
223          Core.retained_read_observe(shape, Core.read_flat(shape, original, U32.from_nat(cursor)), other), Core.checked_observe(shape, original, other),
224          Equal.cong(Core.Tensor<shape> & Result<&2, &2, Core.Error, F32>, Maybe<&2, F32>, pair => Core.retained_read_observe(shape, pair, other),
225            (tensor, result), Core.read_flat(shape, original, U32.from_nat(cursor)), exact), kept(other))))}
226    prove(retention)}

Uses (23)

Used by (1)