~/bend-docscommunity

src/autograd/reduce_parallel_proof.bend open laws/TODOs

raw source on the hub · import bendtorch-core@0.1.0.0/src/autograd/reduce_parallel_proof.bend as Reduce_parallel_proof

20 imports
import Base
import ../storage/model.bend as Model
import ../storage/refinement.bend as Refinement
import ../tensor/elementwise_parallel_proof.bend as Parallel
import ../tensor/parallel_proofs.bend as Generic
import ../shape/core.bend as Shape
import ../shape/flat.bend as Flat
import ../shape/broadcast_proofs.bend as Broadcast
import ../shape/projection_proofs.bend as ShapeProjection
import ../storage/arith.bend as Arith
import ../shape/index_proofs.bend as Index
import ../tensor/word_conversion.bend as Conversion
import ../tensor/projection_LAWS.bend as Projection
import ../shape/LAWS.bend as ShapeLaws
import ../tensor/contracts/broadcast.bend as BroadcastMap
import ../tensor/contracts/broadcast_proof.bend as BroadcastProof
import ../tensor/contracts/pointwise_proof.bend as PointwiseProof
import ./reduce.bend as Reduce
import ./reduce_LAWS.bend as ReduceLaws
import ./reduce_fiber_proof.bend as Fiber

Types

type ObsStep source · line 256 · raw

@-d:Nat -> @-A:Array<F32> -> @-p:Nat -> @-w:F32 -> @-ps:List<&2, Nat> -> @-ws:List<&2, F32> -> Data

type FiberRun source · line 277 · raw

@-d:Nat -> @-A:Array<F32> -> @-positions:List<&2, Nat> -> @-accumulator:F32 -> @-result:Pair(F32, Array<F32>) -> Data

A run of Reduce.fiber: its total adds the words it saw, in order, and the array comes back unchanged.

type CellAt source · line 614 · raw

@-d:Nat -> @-A:Array<F32> -> @-rows:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @-extents:List<&2, Nat> -> @-position:Nat -> @-value:Maybe<&2, F32> -> Data

What target cell position holds: below count, the total of the words its walk saw, from +0.0; at or above it, +0.0.

Definitions

def numel_pad source · line 28 · raw

@+count:Nat -> @+dims:List<&2, Nat> -> {0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.pad(count, dims)) == 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.numel(dims) : Nat}

def padding_left source · line 36 · raw

@+left:List<&2, Nat> -> @+right:List<&2, Nat> -> @+output:List<&2, Nat> -> @+lp:Nat -> @+rp:Nat -> @+aligned:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Aligned(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.pad(lp, left), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.pad(rp, right), output) -> {lp == Nat.sub(List.length(&2, Nat, output), List.length(&2, Nat, left)) : Nat}

def padding_right source · line 43 · raw

@+left:List<&2, Nat> -> @+right:List<&2, Nat> -> @+output:List<&2, Nat> -> @+lp:Nat -> @+rp:Nat -> @+aligned:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Aligned(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.pad(lp, left), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.pad(rp, right), output) -> {rp == Nat.sub(List.length(&2, Nat, output), List.length(&2, Nat, right)) : Nat}

def table_walk source · line 52 · raw

@+left:List<&2, Nat> -> @+right:List<&2, Nat> -> @+output:List<&2, Nat> -> @+alignment:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Broadcast<left, right, output> -> @+target:Nat -> @+below:{Nat.is_lt(target, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.numel(left)) == True{} : Bool} -> 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce_fiber_proof.RestWalk(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.index_table(left, right, output), output, target, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.numel(output))

The index table of an aligned broadcast is walked as Fiber.fiber_walk says.

def plan_walk source · line 68 · raw

@+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan -> @+rows:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+exact:{rows == 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.index_table(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.left_shape(plan)), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.right_shape(plan)), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.output_shape(plan))) : List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row>} -> @+target:Nat -> @+below:{Nat.is_lt(target, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.left_shape(plan)))) == True{} : Bool} -> 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce_fiber_proof.RestWalk(rows, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.output_shape(plan)), target, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.output_shape(plan))))

The same for the rows of a plan's index map.

def offsets_walk source · line 81 · raw

@+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan -> @+map:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Index<0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.left_shape(plan)), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.right_shape(plan)), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.output_shape(plan))> -> @+position:Nat -> @+bound:{True{} == Nat.is_lt(position, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.elements(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.output_shape(plan))) : Bool} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/projection_LAWS.offset_spec(plan, position) == Some{(U32.from_nat(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/contracts/broadcast.left_walk(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.left_shape(plan)), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.right_shape(plan)), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.output_shape(plan)), map, position)), U32.from_nat(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/contracts/broadcast.right_walk(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.left_shape(plan)), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.right_shape(plan)), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.output_shape(plan)), map, position)))} : Maybe<&1, Pair(U32, U32)>}

As in reduce_fold_PROOF.bend: below the output count, the specified offsets are the index walks.

def gather source · line 113 · raw

@+values:List<&2, F32> -> @positions:List<&2, Nat> -> @total:Maybe<&2, F32> -> Maybe<&2, F32>

Adding the words at a list of positions, in order.

def gather_append source · line 120 · raw

@+values:List<&2, F32> -> @+xs:List<&2, Nat> -> @+ys:List<&2, Nat> -> @+total:Maybe<&2, F32> -> {gather(values, List.append(&2, Nat, xs, ys), total) == gather(values, ys, gather(values, xs, total)) : Maybe<&2, F32>}

def gather_kept source · line 128 · raw

@+values:List<&2, F32> -> @+keep:Bool -> @+position:Nat -> @+total:Maybe<&2, F32> -> {gather(values, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce_fiber_proof.kept(keep, position, []), total) == 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce_LAWS.matched(total, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce_LAWS.word_at(values, position), keep) : Maybe<&2, F32>}

def succ_add source · line 136 · raw

@+k:Nat -> {Nat.add(k, 1n) == 1n+k : Nat}

def fiber_masked source · line 142 · raw

@+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan -> @+rows:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+exact:{rows == 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.index_table(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.left_shape(plan)), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.right_shape(plan)), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.output_shape(plan))) : List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row>} -> @+values:List<&2, F32> -> @+index:U32 -> @+count:Nat -> @+room:{Nat.is_le(count, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.output_shape(plan)))) == True{} : Bool} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce_LAWS.fiber(plan, values, index, count) == gather(values, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce_fiber_proof.masked(count, rows, U32.to_nat(index), 0n, 0n), Some{0.0}) : Maybe<&2, F32>}

The masked fold of ReduceLaws.fiber adds, in order, the words at the masked positions.

def all_below source · line 191 · raw

@positions:List<&2, Nat> -> @+bound:Nat -> Bool

Every masked position lies inside the contribution.

def kept_below source · line 198 · raw

@+keep:Bool -> @+position:Nat -> @+rest:List<&2, Nat> -> @+bound:Nat -> @+inside:{Nat.is_lt(position, bound) == True{} : Bool} -> @+others:{all_below(rest, bound) == True{} : Bool} -> {all_below(0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce_fiber_proof.kept(keep, position, rest), bound) == True{} : Bool}

def masked_below source · line 208 · raw

@+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan -> @+rows:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+exact:{rows == 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.index_table(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.left_shape(plan)), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.right_shape(plan)), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.output_shape(plan))) : List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row>} -> @+target:Nat -> @+n:Nat -> @+cursor:Nat -> @+room:{Nat.is_le(Nat.add(cursor, n), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.output_shape(plan)))) == True{} : Bool} -> {all_below(0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce_fiber_proof.masked(n, rows, target, 0n, cursor), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.right_shape(plan)))) == True{} : Bool}

def fsum source · line 229 · raw

@words:List<&2, F32> -> @accumulator:F32 -> F32

def fsum_append source · line 236 · raw

@+xs:List<&2, F32> -> @+ys:List<&2, F32> -> @+accumulator:F32 -> {fsum(List.append(&2, F32, xs, ys), accumulator) == fsum(ys, fsum(xs, accumulator)) : F32}

def Obs source · line 245 · raw

@+d:Nat -> @-A:Array<F32> -> @positions:List<&2, Nat> -> @words:List<&2, F32> -> Data

Each word is what A holds at its position.

def obs_append source · line 259 · raw

@+d:Nat -> @-A:Array<F32> -> @+xs:List<&2, Nat> -> @+vs:List<&2, F32> -> @-ys:List<&2, Nat> -> @-ws:List<&2, F32> -> @-first:Obs(d, A, xs, vs) -> @-second:Obs(d, A, ys, ws) -> 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/elementwise_parallel_proof.Fact<Obs(d, A, List.append(&2, Nat, xs, ys), List.append(&2, F32, vs, ws))>

def leaf_run source · line 282 · raw

@+d:Nat -> @-A:Array<F32> -> @+base:Nat -> @-accumulator:F32 -> @-array:Array<F32> -> @pair:Pair(Array<F32>, F32) -> @-exact:{pair == Array.get(F32, array, U32.from_nat(base)) : Pair(Array<F32>, F32)} -> @-same:{array == A : Array<F32>} -> @-valid:0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Balanced(F32, d, A) -> 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/elementwise_parallel_proof.Fact<FiberRun<d, A, [base], accumulator, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.leaf_add(accumulator, pair)>>

def next_run source · line 296 · raw

@+d:Nat -> @-A:Array<F32> -> @-low:List<&2, Nat> -> @-high:List<&2, Nat> -> @-accumulator:F32 -> @-rec:(@_:F32 -> @_:Array<F32> -> Pair(F32, Array<F32>)) -> @pair:Pair(F32, Array<F32>) -> @-first:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/elementwise_parallel_proof.Fact<FiberRun<d, A, low, accumulator, pair>> -> @-next:(@value:F32 -> @array:Array<F32> -> @-same:{array == A : Array<F32>} -> 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/elementwise_parallel_proof.Fact<FiberRun<d, A, high, value, rec(value, array)>>) -> 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/elementwise_parallel_proof.Fact<FiberRun<d, A, List.append(&2, Nat, low, high), accumulator, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.walk_next(rec, pair)>>

def fiber_run source · line 318 · raw

@+rows:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+extents:List<&2, Nat> -> @+fuel:Nat -> @+target:Nat -> @+base:Nat -> @+digit:Nat -> @+d:Nat -> @-A:Array<F32> -> @+accumulator:F32 -> @array:Array<F32> -> @-same:{array == A : Array<F32>} -> @-valid:0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Balanced(F32, d, A) -> 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/elementwise_parallel_proof.Fact<FiberRun<d, A, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce_fiber_proof.visited(rows, extents, fuel, target, base, digit), accumulator, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.fiber(rows, extents, fuel, target, base, digit, accumulator, array)>>

def add_zero source · line 348 · raw

@+number:Nat -> {number == Nat.add(number, 0n) : Nat}

def offset_shift source · line 357 · raw

@+rows:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+extents:List<&2, Nat> -> @+target:Nat -> @+base:Nat -> {0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.single_offset(rows, extents, target, base) == Nat.add(base, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.single_offset(rows, extents, target, 0n)) : Nat}

The one word that rows of span 1 reach from base sits base past the one they reach from 0.

def leaf_kept source · line 379 · raw

@-rec:(@_:F32 -> @_:Array<F32> -> Pair(F32, Array<F32>)) -> @same:(@value:F32 -> @array:Array<F32> -> {rec(value, array) == (value, array) : Pair(F32, Array<F32>)}) -> @+accumulator:F32 -> @pair:Pair(Array<F32>, F32) -> {0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.walk_next(rec, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.leaf_add(accumulator, pair)) == 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.leaf_add(accumulator, pair) : Pair(F32, Array<F32>)}

A closure that hands its two arguments back as they are leaves a leaf add as it is.

def span_one source · line 386 · raw

@+left:Nat -> @+extent:Nat -> @+single:{Nat.is_eq(0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.span(left, extent), 1n) == True{} : Bool} -> {0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.span(left, extent) == 1n : Nat}

def single_fiber source · line 391 · raw

@+rows:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+extents:List<&2, Nat> -> @+single:{0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.single_rows(rows, extents) == True{} : Bool} -> @+target:Nat -> @+base:Nat -> @+accumulator:F32 -> @-array:Array<F32> -> 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/parallel_proofs.Fact<{0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.fiber(rows, extents, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.first_span(rows, extents), target, base, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.first_digit(rows, target), accumulator, array) == 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.leaf_add(accumulator, Array.get(F32, array, U32.from_nat(0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.single_offset(rows, extents, target, base)))) : Pair(F32, Array<F32>)}>

Rows of span 1 read one word: the one at single_offset.

def fiber_step source · line 432 · raw

@+stride:Nat -> @+left:Nat -> @+right:Nat -> @+rest:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+extent:Nat -> @+others:List<&2, Nat> -> @+single:{0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.single_rows(rest, others) == True{} : Bool} -> @+fuel:Nat -> @+target:Nat -> @+base:Nat -> @+digit:Nat -> @+accumulator:F32 -> @-array:Array<F32> -> @-kept:Array<F32> -> @-word:F32 -> @-read:{(kept, word) == Array.get(F32, array, U32.from_nat(0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.strided_offset(right, base, digit, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.single_offset(rest, others, Nat.mod(target, left), 0n)))) : Pair(Array<F32>, F32)} -> 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/parallel_proofs.Fact<{0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.fiber(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row{stride, left, right} <> rest, extent <> others, 1n+fuel, target, base, digit, accumulator, array) == 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.fiber(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row{stride, left, right} <> rest, extent <> others, fuel, target, base, 1n+digit, F32.add(accumulator, word), kept) : Pair(F32, Array<F32>)}>

One digit of a row whose rows below take one digit adds the word at its strided offset.

def run_fiber source · line 477 · raw

@+stride:Nat -> @+left:Nat -> @+right:Nat -> @+rest:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+extent:Nat -> @+others:List<&2, Nat> -> @+single:{0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.single_rows(rest, others) == True{} : Bool} -> @fuel:Nat -> @+target:Nat -> @+base:Nat -> @+digit:Nat -> @+accumulator:F32 -> @-array:Array<F32> -> @pair:Pair(Array<F32>, F32) -> @-read:{pair == Array.get(F32, array, U32.from_nat(0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.strided_offset(right, base, digit, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.single_offset(rest, others, Nat.mod(target, left), 0n)))) : Pair(Array<F32>, F32)} -> 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/parallel_proofs.Fact<{0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.strided_run(fuel, right, base, digit, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.single_offset(rest, others, Nat.mod(target, left), 0n), accumulator, pair) == 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.fiber(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row{stride, left, right} <> rest, extent <> others, 1n+fuel, target, base, digit, accumulator, array) : Pair(F32, Array<F32>)}>

The strided run of a row whose rows below take one digit is the fiber of that row from the same digit, one more word than the run's fuel.

def strided_fiber source · line 518 · raw

@+stride:Nat -> @+left:Nat -> @+right:Nat -> @+rest:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+extent:Nat -> @+others:List<&2, Nat> -> @+single:{0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.single_rows(rest, others) == True{} : Bool} -> @fuel:Nat -> @+target:Nat -> @+base:Nat -> @+digit:Nat -> @+accumulator:F32 -> @array:Array<F32> -> 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/parallel_proofs.Fact<{0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.strided(fuel, right, base, digit, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.single_offset(rest, others, Nat.mod(target, left), 0n), accumulator, array) == 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.fiber(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row{stride, left, right} <> rest, extent <> others, fuel, target, base, digit, accumulator, array) : Pair(F32, Array<F32>)}>

The strided loop of such a row is its fiber.

def SingleOk source · line 532 · raw

@single:Bool -> @+rows:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+extents:List<&2, Nat> -> Data

What a fast fiber's flag promises: True only where the rows below the first take one digit each.

def single_ok source · line 539 · raw

@+rows:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+extents:List<&2, Nat> -> @single:Bool -> @+exact:{single == 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.single_below(rows, extents) : Bool} -> SingleOk(single, rows, extents)

def next_same source · line 548 · raw

@-fast:(@_:F32 -> @_:Array<F32> -> Pair(F32, Array<F32>)) -> @-slow:(@_:F32 -> @_:Array<F32> -> Pair(F32, Array<F32>)) -> @same:(@value:F32 -> @array:Array<F32> -> 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/parallel_proofs.Fact<{fast(value, array) == slow(value, array) : Pair(F32, Array<F32>)}>) -> @pair:Pair(F32, Array<F32>) -> 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/parallel_proofs.Fact<{0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.walk_next(fast, pair) == 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.walk_next(slow, pair) : Pair(F32, Array<F32>)}>

Two closures equal on every argument continue a pair alike.

def fast_fiber source · line 556 · raw

@+rows:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+extents:List<&2, Nat> -> @fuel:Nat -> @single:Bool -> @-ok:SingleOk(single, rows, extents) -> @+target:Nat -> @+base:Nat -> @+digit:Nat -> @+accumulator:F32 -> @-array:Array<F32> -> 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/parallel_proofs.Fact<{0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.fiber_fast(rows, extents, fuel, single, target, base, digit, accumulator, array) == 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.fiber(rows, extents, fuel, target, base, digit, accumulator, array) : Pair(F32, Array<F32>)}>

The fast fiber returns what the fiber returns.

def visited_of source · line 609 · raw

@+rows:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+extents:List<&2, Nat> -> @+position:Nat -> List<&2, Nat>

The offsets the walk of cell position reads.

def CellSpec source · line 618 · raw

@+d:Nat -> @-A:Array<F32> -> @+rows:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+extents:List<&2, Nat> -> @+position:Nat -> @inside:Bool -> @-value:Maybe<&2, F32> -> Type

def CellIs source · line 626 · raw

@+d:Nat -> @-A:Array<F32> -> @+rows:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+extents:List<&2, Nat> -> @+count:Nat -> @+position:Nat -> @-value:Maybe<&2, F32> -> Type

def Cells source · line 630 · raw

@+depth:Nat -> @+d:Nat -> @-A:Array<F32> -> @+rows:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+extents:List<&2, Nat> -> @+count:Nat -> @+base:Nat -> @-out:Array<F32> -> Type

def cell_of source · line 636 · raw

@+rows:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+extents:List<&2, Nat> -> @+position:Nat -> @A:Array<F32> -> @inside:Bool -> Pair(F32, Pair(Array<F32>, Unit))

The reduce cell function of Parallel.build, from the contribution array.

def keep_equal source · line 639 · raw

@pair:Pair(F32, Array<F32>) -> @-none:Unit -> {0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.keep(pair, none) == (Pair.fst(F32, Array<F32>, pair), Pair.snd(F32, Array<F32>, pair), none) : Pair(F32, Pair(Array<F32>, Unit))}

def run_of source · line 644 · raw

@+d:Nat -> @A:Array<F32> -> @+rows:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+extents:List<&2, Nat> -> @+position:Nat -> @-valid:0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Balanced(F32, d, A) -> 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/elementwise_parallel_proof.Fact<FiberRun<d, A, visited_of(rows, extents, position), 0.0, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.fiber_of(rows, extents, position, A)>>

def cell_keeps source · line 660 · raw

@+d:Nat -> @A:Array<F32> -> @+rows:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+extents:List<&2, Nat> -> @+position:Nat -> @inside:Bool -> @-valid:0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Balanced(F32, d, A) -> 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/elementwise_parallel_proof.Fact<{Pair.snd(F32, Pair(Array<F32>, Unit), cell_of(rows, extents, position, A, inside)) == (A, Unit{}) : Pair(Array<F32>, Unit)}>

Every cell hands the contribution array back.

def cell_spec source · line 680 · raw

@+d:Nat -> @A:Array<F32> -> @+rows:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+extents:List<&2, Nat> -> @+position:Nat -> @inside:Bool -> @-observed:Maybe<&2, F32> -> @-computed:{observed == Some{Pair.fst(F32, Pair(Array<F32>, Unit), cell_of(rows, extents, position, A, inside))} : Maybe<&2, F32>} -> @-valid:0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Balanced(F32, d, A) -> 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/elementwise_parallel_proof.Fact<CellSpec(d, A, rows, extents, position, inside, observed)>

What the cell function computes is what CellSpec names.

def halves_equal source · line 701 · raw

@+d:Nat -> @-A:Array<F32> -> @pair:Pair(Array<F32>, Array<F32>) -> @-exact:{pair == Array.clone(F32, A) : Pair(Array<F32>, Array<F32>)} -> @-valid:0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Balanced(F32, d, A) -> 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/elementwise_parallel_proof.Fact<Pair({Pair.fst(Pair(Array<F32>, Unit), Pair(Array<F32>, Unit), 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.halves(pair)) == (A, Unit{}) : Pair(Array<F32>, Unit)}, {Pair.snd(Pair(Array<F32>, Unit), Pair(Array<F32>, Unit), 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.halves(pair)) == (A, Unit{}) : Pair(Array<F32>, Unit)})>

A split hands each half the contribution array.

def build_cells source · line 716 · raw

@+depth:Nat -> @+splits:Nat -> @+d:Nat -> @-A:Array<F32> -> @+rows:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+extents:List<&2, Nat> -> @+count:Nat -> @+base:Nat -> @array:Array<F32> -> @-same:{array == A : Array<F32>} -> @-valid:0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Balanced(F32, d, A) -> 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/elementwise_parallel_proof.Fact<Cells(depth, d, A, rows, extents, count, base, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.build(depth, splits, rows, extents, count, base, array))>

Whatever the split, every cell of the parallel build holds what CellIs names: the generic law of Parallel.build, with the reduce cell.

def Reads source · line 749 · raw

@+d:Nat -> @-A:Array<F32> -> @+values:List<&2, F32> -> @+bound:Nat -> Type

The words a walk saw are the contribution's words at the offsets it read.

def obs_gather source · line 753 · raw

@+d:Nat -> @-A:Array<F32> -> @+values:List<&2, F32> -> @+bound:Nat -> @+positions:List<&2, Nat> -> @+words:List<&2, F32> -> @+accumulator:F32 -> @-seen:Obs(d, A, positions, words) -> @+below:{all_below(positions, bound) == True{} : Bool} -> @-reads:Reads(d, A, values, bound) -> 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/elementwise_parallel_proof.Fact<{Some{fsum(words, accumulator)} == gather(values, positions, Some{accumulator}) : Maybe<&2, F32>}>

def cell_value source · line 780 · raw

@+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BroadcastPlan -> @+rows:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+exact:{rows == 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.index_table(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.left_shape(plan)), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.right_shape(plan)), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.output_shape(plan))) : List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row>} -> @+values:List<&2, F32> -> @+index:U32 -> @+d:Nat -> @-A:Array<F32> -> @+words:List<&2, F32> -> @-seen:Obs(d, A, visited_of(rows, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.output_shape(plan)), U32.to_nat(index)), words) -> @+inside:{Nat.is_lt(U32.to_nat(index), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.extents(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.left_shape(plan)))) == True{} : Bool} -> @-reads:Reads(d, A, values, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.right_shape(plan)))) -> 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/elementwise_parallel_proof.Fact<{Some{fsum(words, 0.0)} == 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce_LAWS.fiber(plan, values, index, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.logical_numel(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.dimensions(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.output_shape(plan)))) : Maybe<&2, F32>}>

A cell of the parallel build holds ReduceLaws.fiber: the words its walk saw add up, from +0.0, to the masked fold over the contribution.