def written_at
bendtorch-core@0.1.0.0 · src/tensor/from_values_contract.bend:132
import bendtorch-core@0.1.0.0/src/tensor/from_values_contract.bend as FromValuesContract
import Base
import bendtorch-core@0.1.0.0/src/storage/LAWS.bend as StorageLaws
import bendtorch-core@0.1.0.0/src/storage/api.bend as Api
import bendtorch-core@0.1.0.0/src/storage/arith.bend as Arith
import bendtorch-core@0.1.0.0/src/tensor/word_conversion.bend as Conversion
132def written_at(+values: List<&2, F32>, +cursor: Nat, +limit: U32, +index: U32, +base: F32, +offset: Nat,
133 +room: {Nat.is_le(Nat.add(cursor, List.length(&2, F32, values)), U32.to_nat(limit)) == True{} : Bool},
134 at: {U32.to_nat(index) == Nat.add(cursor, offset) : Nat},
135 below: {Nat.is_lt(offset, List.length(&2, F32, values)) == True{} : Bool}) ->
136 {Some{StorageLaws.expected(writes(values, cursor), U32.to_nat(limit), index, base)} == List.get(&2, F32, values, offset) : Maybe<&2, F32>}:
137 match values offset:
138 case Nil{} _:
139 Empty.absurd({Some{base} == None{} : Maybe<&2, F32>}, Arith.lt_zero(offset, below))
140 case +value <> +rest 0n:
141 +exact = Equal.trans(Nat, U32.to_nat(index), Nat.add(cursor, 0n), cursor, at, Conversion.add_zero(cursor))
142 Equal.cong(F32, Maybe<&2, F32>, found => Some{found},
143 StorageLaws.expected(writes(rest, 1n+cursor), U32.to_nat(limit), index,
144 StorageLaws.latest(U32.to_nat(limit), StorageLaws.Write{U32.from_nat(cursor), value}, index, base)), value,
145 Equal.trans(F32,
146 StorageLaws.expected(writes(rest, 1n+cursor), U32.to_nat(limit), index,
147 StorageLaws.latest(U32.to_nat(limit), StorageLaws.Write{U32.from_nat(cursor), value}, index, base)),
148 StorageLaws.latest(U32.to_nat(limit), StorageLaws.Write{U32.from_nat(cursor), value}, index, base), value,
149 later_writes(rest, 1n+cursor, limit, index,
150 StorageLaws.latest(U32.to_nat(limit), StorageLaws.Write{U32.from_nat(cursor), value}, index, base),
151 room_next(cursor, List.length(&2, F32, rest), U32.to_nat(limit), room),
152 %Equal.sym(Nat, U32.to_nat(index), cursor, exact) : {Nat.is_lt(_, 1n+cursor) == True{} : Bool}
153 Arith.lt_succ(cursor, cursor, Api.le_refl(cursor))),
154 hit(cursor, List.length(&2, F32, rest), limit, index, value, base, room, exact)))
155 case +value <> +rest 1n+next:
156 written_at(rest, 1n+cursor, limit, index,
157 StorageLaws.latest(U32.to_nat(limit), StorageLaws.Write{U32.from_nat(cursor), value}, index, base), next,
158 room_next(cursor, List.length(&2, F32, rest), U32.to_nat(limit), room),
159 Equal.trans(Nat, U32.to_nat(index), Nat.add(cursor, 1n+next), 1n+Nat.add(cursor, next), at, Arith.add_succ(cursor, next)),
160 below)