src/autograd/reduce_fiber_proof.bend checks
raw source on the hub · import bendtorch-core@0.1.0.0/src/autograd/reduce_fiber_proof.bend as Reduce_fiber_proof
9 imports
import Base import ../shape/core.bend as Shape import ../shape/nat_proofs.bend as Nats import ../shape/index_proofs.bend as Index import ../shape/broadcast_proofs.bend as Broadcast import ../storage/arith.bend as Arith import ../storage/api.bend as Api import ../tensor/matrix_index_proof.bend as MatrixIndex import ./reduce.bend as Reduce
Types
type Split source · line 43 · raw
@-t:Nat -> @-size:Nat -> Data
t = quotient * size + remainder with remainder < size.
Split@-t:Nat -> @-size:Nat -> @quotient:Nat -> @remainder:Nat -> @below:{Nat.is_lt(remainder, size) == True{} : Bool} -> @sum:{Nat.add(Nat.mul(quotient, size), remainder) == t : Nat} -> Split<t, size>
type Decomposed source · line 92 · raw
@-t:Nat -> @-size:Nat -> Data
t = (t / size) * size + t % size, and t % size < size.
Decomposed@-t:Nat -> @-size:Nat -> @below:{Nat.is_lt(Nat.mod(t, size), size) == True{} : Bool} -> @sum:{Nat.add(Nat.mul(Nat.div(t, size), size), Nat.mod(t, size)) == t : Nat} -> Decomposed<t, size>
type BoundBy source · line 430 · raw
@-rest:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @-left:Nat -> @-stride:Nat -> Data
Below a kept row of left stride left, every walk of the rows below
stays under left: the rows are the index rows of an aligned broadcast
whose left count is left and whose output count is stride.
BoundBy@-rest:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @-left:Nat -> @-stride:Nat -> @lt:List<&2, Nat> -> @rt:List<&2, Nat> -> @ot:List<&2, Nat> -> @aligned:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Aligned(lt, rt, ot) -> @rows:{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.index_rows(lt, rt, ot) == rest : List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row>} -> @size:{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.numel(lt) == left : Nat} -> @count:{0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.numel(ot) == stride : Nat} -> BoundBy<rest, left, stride>
type MaskMode source · line 448 · raw
@-left:Nat -> @-digit:Nat -> @-target:Nat -> @-inner:Nat -> Data
How the rows below a block decide which positions land on the target: on a reduced row (left stride 0) the rows below land on the target itself; on the kept row's target digit they land on the target's remainder; on any other digit of a kept row nothing lands.
Free@-left:Nat -> @-digit:Nat -> @-target:Nat -> @-inner:Nat -> @zero:{0n == left : Nat} -> @same:{target == inner : Nat} -> MaskMode<left, digit, target, inner>Hit@-left:Nat -> @-digit:Nat -> @-target:Nat -> @-inner:Nat -> @given:Decomposed<target, left> -> @same:{digit == Nat.div(target, left) : Nat} -> @remainder:{Nat.mod(target, left) == inner : Nat} -> MaskMode<left, digit, target, inner>
type OffMode source · line 464 · raw
@-rest:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @-left:Nat -> @-stride:Nat -> @-digit:Nat -> @-target:Nat -> Data
Off@-rest:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @-left:Nat -> @-stride:Nat -> @-digit:Nat -> @-target:Nat -> @bound:BoundBy<rest, left, stride> -> @differ:{Nat.is_eq(digit, Nat.div(target, left)) == False{} : Bool} -> OffMode<rest, left, stride, digit, target>
Definitions
def add_comm source · line 21 · raw
@+a:Nat -> @+b:Nat -> {Nat.add(a, b) == Nat.add(b, a) : Nat}
def lt_succ_eq source · line 26 · raw
@+r:Nat -> @+size:Nat -> @below:{Nat.is_lt(r, size) == True{} : Bool} -> @not_below:{False{} == Nat.is_lt(1n+r, size) : Bool} -> {size == 1n+r : Nat}
def split_step source · line 47 · raw
@+t:Nat -> @+size:Nat -> @+q:Nat -> @+r:Nat -> @below:{Nat.is_lt(r, size) == True{} : Bool} -> @sum:{Nat.add(Nat.mul(q, size), r) == t : Nat} -> @last:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BoolCase<Nat.is_lt(1n+r, size)> -> Split<1n+t, size>
def split_next source · line 64 · raw
@+t:Nat -> @+size:Nat -> @previous:Split<t, size> -> Split<1n+t, size>
def split source · line 68 · raw
@+t:Nat -> @+size:Nat -> @positive:{Nat.is_lt(0n, size) == True{} : Bool} -> Split<t, size>
def split_divmod source · line 76 · raw
@-t:Nat -> @+size:Nat -> @+q:Nat -> @+r:Nat -> @below:{Nat.is_lt(r, size) == True{} : Bool} -> @sum:{Nat.add(Nat.mul(q, size), r) == t : Nat} -> {(q, r) == Nat.divmod(t, size) : Pair(Nat, Nat)}The quotient and remainder of a split are Nat.div and Nat.mod.
def div_of source · line 81 · raw
@-t:Nat -> @+size:Nat -> @+q:Nat -> @+r:Nat -> @below:{Nat.is_lt(r, size) == True{} : Bool} -> @sum:{Nat.add(Nat.mul(q, size), r) == t : Nat} -> {Nat.div(t, size) == q : Nat}
def mod_of source · line 86 · raw
@-t:Nat -> @+size:Nat -> @+q:Nat -> @+r:Nat -> @below:{Nat.is_lt(r, size) == True{} : Bool} -> @sum:{Nat.add(Nat.mul(q, size), r) == t : Nat} -> {Nat.mod(t, size) == r : Nat}
def decomposed source · line 96 · raw
@+t:Nat -> @+size:Nat -> @given:Split<t, size> -> Decomposed<t, size>
def decompose source · line 107 · raw
@+t:Nat -> @+size:Nat -> @positive:{Nat.is_lt(0n, size) == True{} : Bool} -> Decomposed<t, size>
def lt_irrefl source · line 110 · raw
@+x:Nat -> {Nat.is_lt(x, x) == False{} : Bool}
def le_add_cong source · line 117 · raw
@+c:Nat -> @+x:Nat -> @+y:Nat -> @h:{Nat.is_le(x, y) == True{} : Bool} -> {Nat.is_le(Nat.add(c, x), Nat.add(c, y)) == True{} : Bool}
def le_trans source · line 125 · raw
@+a:Nat -> @+b:Nat -> @+c:Nat -> @ab:{Nat.is_le(a, b) == True{} : Bool} -> @bc:{Nat.is_le(b, c) == True{} : Bool} -> {Nat.is_le(a, c) == True{} : Bool}
def mul_le_mono source · line 137 · raw
@+a:Nat -> @+q:Nat -> @+size:Nat -> @h:{Nat.is_le(a, q) == True{} : Bool} -> {Nat.is_le(Nat.mul(a, size), Nat.mul(q, size)) == True{} : Bool}
def quotient_below source · line 148 · raw
@+t:Nat -> @+a:Nat -> @+size:Nat -> @below:{Nat.is_lt(t, Nat.mul(a, size)) == True{} : Bool} -> @decision:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BoolCase<Nat.is_lt(Nat.div(t, size), a)> -> @given:Decomposed<t, size> -> {Nat.is_lt(Nat.div(t, size), a) == True{} : Bool}Below a * size, the quotient by size is below a.
def positive_of source · line 166 · raw
@+t:Nat -> @+a:Nat -> @+size:Nat -> @below:{Nat.is_lt(t, Nat.mul(a, size)) == True{} : Bool} -> {Nat.is_lt(0n, size) == True{} : Bool}
def div_below source · line 177 · raw
@+t:Nat -> @+a:Nat -> @+size:Nat -> @+below:{Nat.is_lt(t, Nat.mul(a, size)) == True{} : Bool} -> {Nat.is_lt(Nat.div(t, size), a) == True{} : Bool}
def eq_add_cancel source · line 182 · raw
@+a:Nat -> @+x:Nat -> @+y:Nat -> {Nat.is_eq(Nat.add(a, x), Nat.add(a, y)) == Nat.is_eq(x, y) : Bool}a + x = a + y exactly when x = y.
def ne_from source · line 189 · raw
@+d:Nat -> @+e:Nat -> @same:{e == d : Nat} -> @differ:{Nat.is_eq(d, e) == False{} : Bool} -> Empty
def mask_at source · line 197 · raw
@+size:Nat -> @+d:Nat -> @+w:Nat -> @+t:Nat -> @given:Decomposed<t, size> -> @same:{d == Nat.div(t, size) : Nat} -> {Nat.is_eq(Nat.add(Nat.mul(size, d), w), t) == Nat.is_eq(w, Nat.mod(t, size)) : Bool}On a kept row of left stride size, the position with digit d and
walk w below size lands on t exactly when d is t's quotient and w its
remainder.
def mask_off_decided source · line 206 · raw
@+size:Nat -> @+d:Nat -> @+w:Nat -> @+t:Nat -> @below:{Nat.is_lt(w, size) == True{} : Bool} -> @differ:{Nat.is_eq(d, Nat.div(t, size)) == False{} : Bool} -> @decision:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BoolCase<Nat.is_eq(Nat.add(Nat.mul(size, d), w), t)> -> {Nat.is_eq(Nat.add(Nat.mul(size, d), w), t) == False{} : Bool}
def mask_off source · line 222 · raw
@+size:Nat -> @+d:Nat -> @+w:Nat -> @+t:Nat -> @below:{Nat.is_lt(w, size) == True{} : Bool} -> @differ:{Nat.is_eq(d, Nat.div(t, size)) == False{} : Bool} -> {Nat.is_eq(Nat.add(Nat.mul(size, d), w), t) == False{} : Bool}
def kept source · line 229 · raw
@+keep:Bool -> @+position:Nat -> @rest:List<&2, Nat> -> List<&2, Nat>
def masked source · line 239 · raw
@fuel:Nat -> @+rows:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+target:Nat -> @+base:Nat -> @+cursor:Nat -> List<&2, Nat>
The contribution offsets base + walk_right(p) of the positions
p = cursor .. cursor + fuel - 1 whose walk_left is target, in order:
the words the masked fold of ReduceLaws.fiber adds.
def visited source · line 248 · raw
@+rows:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+extents:List<&2, Nat> -> @fuel:Nat -> @+target:Nat -> @+base:Nat -> @+digit:Nat -> List<&2, Nat>
The contribution offsets Reduce.fiber reads, in order.
def append_nil source · line 262 · raw
@+xs:List<&2, Nat> -> {List.append(&2, Nat, xs, []) == xs : List<&2, Nat>}
def kept_append source · line 269 · raw
@+keep:Bool -> @+position:Nat -> @-xs:List<&2, Nat> -> @-ys:List<&2, Nat> -> {kept(keep, position, List.append(&2, Nat, xs, ys)) == List.append(&2, Nat, kept(keep, position, xs), ys) : List<&2, Nat>}
def masked_split source · line 277 · raw
@+a:Nat -> @+b:Nat -> @+rows:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+target:Nat -> @+base:Nat -> @+cursor:Nat -> {masked(Nat.add(a, b), rows, target, base, cursor) == List.append(&2, Nat, masked(a, rows, target, base, cursor), masked(b, rows, target, base, Nat.add(cursor, a))) : List<&2, Nat>}
def le_step source · line 301 · raw
@+q:Nat -> @+m:Nat -> @+s:Nat -> @room:{Nat.is_le(Nat.add(q, 1n+m), s) == True{} : Bool} -> {Nat.is_le(Nat.add(1n+q, m), s) == True{} : Bool}
def lt_of_room source · line 306 · raw
@+q:Nat -> @+m:Nat -> @+s:Nat -> @room:{Nat.is_le(Nat.add(q, 1n+m), s) == True{} : Bool} -> {Nat.is_lt(q, s) == True{} : Bool}
def lt_succ_right source · line 313 · raw
@+b:Nat -> @+k:Nat -> @h:{Nat.is_lt(b, k) == True{} : Bool} -> {Nat.is_lt(b, 1n+k) == True{} : Bool}
def gt_not_eq source · line 322 · raw
@+a:Nat -> @+b:Nat -> @h:{Nat.is_lt(b, a) == True{} : Bool} -> {Nat.is_eq(a, b) == False{} : Bool}
def le_ne_succ source · line 331 · raw
@+a:Nat -> @+b:Nat -> @le:{Nat.is_le(a, b) == True{} : Bool} -> @ne:{Nat.is_eq(a, b) == False{} : Bool} -> {Nat.is_le(1n+a, b) == True{} : Bool}
def le_lt_absurd source · line 343 · raw
@+a:Nat -> @+b:Nat -> @le:{Nat.is_le(a, b) == True{} : Bool} -> @lt:{Nat.is_lt(b, a) == True{} : Bool} -> Empty
def lt_self_succ source · line 352 · raw
@+k:Nat -> {Nat.is_lt(k, 1n+k) == True{} : Bool}
def axis_zero source · line 359 · raw
@+rh:Nat -> @+oh:Nat -> @axis:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Axis<0n, rh, oh> -> {oh == 0n : Nat}
def axis_kept source · line 368 · raw
@+j:Nat -> @+rh:Nat -> @+oh:Nat -> @axis:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Axis<2n+j, rh, oh> -> {oh == 2n+j : Nat}
def walk_left_row source · line 377 · raw
@+lh:Nat -> @+rh:Nat -> @+oh:Nat -> @axis:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Axis<lh, rh, oh> -> @+size:Nat -> @+d:Nat -> @+w:Nat -> @d_below:{Nat.is_lt(d, oh) == True{} : Bool} -> @w_below:{Nat.is_lt(w, size) == True{} : Bool} -> {Nat.is_lt(Nat.add(Nat.mul(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.broadcast_index(lh, size), d), w), Nat.mul(lh, size)) == True{} : Bool}
def walk_left_below source · line 400 · raw
@+left:List<&2, Nat> -> @+right:List<&2, Nat> -> @+output:List<&2, Nat> -> @+aligned:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Aligned(left, right, output) -> @+q:Nat -> @+below:{Nat.is_lt(q, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.numel(output)) == True{} : Bool} -> {Nat.is_lt(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.walk_left(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.index_rows(left, right, output), q), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.numel(left)) == True{} : Bool}The left walk of a position below the output count lies below the left count.
def bound_at source · line 435 · raw
@-rest:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @-left:Nat -> @-stride:Nat -> @+by:BoundBy<rest, left, stride> -> @+q:Nat -> @+below:{Nat.is_lt(q, stride) == True{} : Bool} -> {Nat.is_lt(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.walk_left(rest, q), left) == True{} : Bool}
def mode_mask source · line 452 · raw
@+left:Nat -> @+digit:Nat -> @+target:Nat -> @+inner:Nat -> @+mode:MaskMode<left, digit, target, inner> -> @+w:Nat -> {Nat.is_eq(w, inner) == Nat.is_eq(Nat.add(Nat.mul(left, digit), w), target) : Bool}
def off_mask source · line 467 · raw
@+rest:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+left:Nat -> @+stride:Nat -> @+digit:Nat -> @+target:Nat -> @+mode:OffMode<rest, left, stride, digit, target> -> @+q:Nat -> @+below:{Nat.is_lt(q, stride) == True{} : Bool} -> {False{} == Nat.is_eq(Nat.add(Nat.mul(left, digit), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.walk_left(rest, q)), target) : Bool}
def shifted source · line 477 · raw
@+n:Nat -> @+stride:Nat -> @+left:Nat -> @+right:Nat -> @+rest:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+target:Nat -> @+inner:Nat -> @+base:Nat -> @+digit:Nat -> @+q:Nat -> @+room:{Nat.is_le(Nat.add(q, n), stride) == True{} : Bool} -> @+mode:MaskMode<left, digit, target, inner> -> {masked(n, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row{stride, left, right} <> rest, target, base, Nat.add(Nat.mul(digit, stride), q)) == masked(n, rest, inner, Nat.add(base, Nat.mul(right, digit)), q) : List<&2, Nat>}On a row of stride s, left stride L and right stride R, the positions d * s + q .. d * s + q + n - 1 have digit d and walk the rows below at q .. q + n - 1.
def shifted_off source · line 513 · raw
@+n:Nat -> @+stride:Nat -> @+left:Nat -> @+right:Nat -> @+rest:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+target:Nat -> @+base:Nat -> @+digit:Nat -> @+q:Nat -> @+room:{Nat.is_le(Nat.add(q, n), stride) == True{} : Bool} -> @+mode:OffMode<rest, left, stride, digit, target> -> {masked(n, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row{stride, left, right} <> rest, target, base, Nat.add(Nat.mul(digit, stride), q)) == [] : List<&2, Nat>}
def block source · line 538 · raw
@+stride:Nat -> @+left:Nat -> @+right:Nat -> @+rest:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+target:Nat -> @+inner:Nat -> @+base:Nat -> @+digit:Nat -> @+mode:MaskMode<left, digit, target, inner> -> {masked(stride, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row{stride, left, right} <> rest, target, base, Nat.mul(digit, stride)) == masked(stride, rest, inner, Nat.add(base, Nat.mul(right, digit)), 0n) : List<&2, Nat>}The first block of a row, at cursor digit * stride: the rows below at base + right * digit.
def block_off source · line 547 · raw
@+stride:Nat -> @+left:Nat -> @+right:Nat -> @+rest:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+target:Nat -> @+base:Nat -> @+digit:Nat -> @+mode:OffMode<rest, left, stride, digit, target> -> {masked(stride, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row{stride, left, right} <> rest, target, base, Nat.mul(digit, stride)) == [] : List<&2, Nat>}
def next_cursor source · line 554 · raw
@+digit:Nat -> @+stride:Nat -> {Nat.mul(1n+digit, stride) == Nat.add(Nat.mul(digit, stride), stride) : Nat}
def shift source · line 558 · raw
@+base:Nat -> @xs:List<&2, Nat> -> List<&2, Nat>
Moving the base moves every offset: base + xs.
def shift_append source · line 565 · raw
@+base:Nat -> @+xs:List<&2, Nat> -> @+ys:List<&2, Nat> -> {shift(base, List.append(&2, Nat, xs, ys)) == List.append(&2, Nat, shift(base, xs), shift(base, ys)) : List<&2, Nat>}
def shift_shift source · line 574 · raw
@+a:Nat -> @+b:Nat -> @+xs:List<&2, Nat> -> {shift(a, shift(b, xs)) == shift(Nat.add(a, b), xs) : List<&2, Nat>}
def kept_shift source · line 583 · raw
@+keep:Bool -> @+base:Nat -> @+x:Nat -> @+rest:List<&2, Nat> -> {kept(keep, Nat.add(base, x), shift(base, rest)) == shift(base, kept(keep, x, rest)) : List<&2, Nat>}
def masked_base source · line 591 · raw
@+n:Nat -> @+rows:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+target:Nat -> @+base:Nat -> @+cursor:Nat -> {masked(n, rows, target, base, cursor) == shift(base, masked(n, rows, target, 0n, cursor)) : List<&2, Nat>}
def visited_base source · line 606 · raw
@+rows:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+extents:List<&2, Nat> -> @+fuel:Nat -> @+target:Nat -> @+base:Nat -> @+digit:Nat -> {visited(rows, extents, fuel, target, base, digit) == shift(base, visited(rows, extents, fuel, target, 0n, digit)) : List<&2, Nat>}
def RestWalk source · line 643 · raw
@+rest:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+others:List<&2, Nat> -> @+inner:Nat -> @+stride:Nat -> Data
The walk below a row, at base 0, visits the masked positions below it.
def rest_at source · line 648 · raw
@+rest:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+others:List<&2, Nat> -> @+inner:Nat -> @+stride:Nat -> @+walk:RestWalk(rest, others, inner, stride) -> @+base:Nat -> {masked(stride, rest, inner, base, 0n) == visited(rest, others, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.first_span(rest, others), inner, base, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.first_digit(rest, inner)) : List<&2, Nat>}... and so at every base.
def reduced_blocks source · line 664 · raw
@+f:Nat -> @+stride:Nat -> @+right:Nat -> @+rest:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+extent:Nat -> @+others:List<&2, Nat> -> @+target:Nat -> @+base:Nat -> @+digit:Nat -> @+walk:RestWalk(rest, others, target, stride) -> {masked(Nat.mul(f, stride), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row{stride, 0n, right} <> rest, target, base, Nat.mul(digit, stride)) == visited(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row{stride, 0n, right} <> rest, extent <> others, f, target, base, digit) : List<&2, Nat>}A reduced row (left stride 0) walks every digit: the blocks digit .. digit + f - 1 of the masked positions are what the walk visits.
def kept_after source · line 694 · raw
@+f:Nat -> @+stride:Nat -> @+left:Nat -> @+right:Nat -> @+rest:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+target:Nat -> @+base:Nat -> @+digit:Nat -> @+after:{Nat.is_lt(Nat.div(target, left), digit) == True{} : Bool} -> @+bound:BoundBy<rest, left, stride> -> {masked(Nat.mul(f, stride), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row{stride, left, right} <> rest, target, base, Nat.mul(digit, stride)) == [] : List<&2, Nat>}On a kept row, the blocks after the target's digit hold no position.
def kept_hit_step source · line 714 · raw
@+g:Nat -> @+stride:Nat -> @+left:Nat -> @+right:Nat -> @+rest:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+target:Nat -> @+base:Nat -> @+digit:Nat -> @decision:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BoolCase<Nat.is_eq(digit, Nat.div(target, left))> -> @+from:{Nat.is_le(digit, Nat.div(target, left)) == True{} : Bool} -> @+until:{Nat.is_lt(Nat.div(target, left), Nat.add(digit, 1n+g)) == True{} : Bool} -> @+given:Decomposed<target, left> -> @+bound:BoundBy<rest, left, stride> -> @rec:(@+next:Nat -> @+from:{Nat.is_le(next, Nat.div(target, left)) == True{} : Bool} -> @+until:{Nat.is_lt(Nat.div(target, left), Nat.add(next, g)) == True{} : Bool} -> {masked(Nat.mul(g, stride), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row{stride, left, right} <> rest, target, base, Nat.mul(next, stride)) == masked(stride, rest, Nat.mod(target, left), Nat.add(base, Nat.mul(right, Nat.div(target, left))), 0n) : List<&2, Nat>}) -> {masked(Nat.mul(1n+g, stride), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row{stride, left, right} <> rest, target, base, Nat.mul(digit, stride)) == masked(stride, rest, Nat.mod(target, left), Nat.add(base, Nat.mul(right, Nat.div(target, left))), 0n) : List<&2, Nat>}
def kept_hit source · line 772 · raw
@+f:Nat -> @+stride:Nat -> @+left:Nat -> @+right:Nat -> @+rest:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+target:Nat -> @+base:Nat -> @+digit:Nat -> @+from:{Nat.is_le(digit, Nat.div(target, left)) == True{} : Bool} -> @+until:{Nat.is_lt(Nat.div(target, left), Nat.add(digit, f)) == True{} : Bool} -> @+given:Decomposed<target, left> -> @+bound:BoundBy<rest, left, stride> -> {masked(Nat.mul(f, stride), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row{stride, left, right} <> rest, target, base, Nat.mul(digit, stride)) == masked(stride, rest, Nat.mod(target, left), Nat.add(base, Nat.mul(right, Nat.div(target, left))), 0n) : List<&2, Nat>}On a kept row, the blocks from digit that cover the target's digit hold
exactly the rows below at the target's remainder.
def kept_row source · line 791 · raw
@+size:Nat -> @+stride:Nat -> @+right:Nat -> @+rest:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row> -> @+extent:Nat -> @+others:List<&2, Nat> -> @+target:Nat -> @+base:Nat -> @+inside:{Nat.is_lt(target, Nat.mul(extent, size)) == True{} : Bool} -> @+walk:RestWalk(rest, others, Nat.mod(target, size), stride) -> @+bound:BoundBy<rest, size, stride> -> {masked(Nat.mul(extent, stride), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row{stride, size, right} <> rest, target, base, 0n) == visited(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Row{stride, size, right} <> rest, extent <> others, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.span(size, extent), target, base, Nat.div(target, size)) : List<&2, Nat>}A kept row walks the one digit the target names there.
def RowsWalk source · line 819 · raw
@+left:List<&2, Nat> -> @+right:List<&2, Nat> -> @+output:List<&2, Nat> -> @+target:Nat -> Data
def fiber_cons source · line 822 · raw
@+lh:Nat -> @+lt:List<&2, Nat> -> @+rh:Nat -> @+rt:List<&2, Nat> -> @+oh:Nat -> @+ot:List<&2, Nat> -> @+axis:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Axis<lh, rh, oh> -> @+tail:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Aligned(lt, rt, ot) -> @+target:Nat -> @+below:{Nat.is_lt(target, Nat.mul(lh, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.numel(lt))) == True{} : Bool} -> @rec:(@+inner:Nat -> @+inside:{Nat.is_lt(inner, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.numel(lt)) == True{} : Bool} -> RowsWalk(lt, rt, ot, inner)) -> RowsWalk(lh <> lt, rh <> rt, oh <> ot, target)
def fiber_walk source · line 849 · raw
@+left:List<&2, Nat> -> @+right:List<&2, Nat> -> @+output:List<&2, Nat> -> @+aligned:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Aligned(left, right, output) -> @+target:Nat -> @+below:{Nat.is_lt(target, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.numel(left)) == True{} : Bool} -> RowsWalk(left, right, output, target)The fiber-walk lemma: for the index rows of an aligned broadcast and a cell below the left count, the offsets the walk reads, in order, are the masked positions.