src/tensor/contracts/words_proof.bend
bendtorch-core@0.1.0.0 · 41 lines · 3 definitions
1import Base
2import bendtorch-core@0.1.0.0/src/shape/core.bend as Shape
3import bendtorch-core@0.1.0.0/src/storage/LAWS.bend as StorageLaws
4import bendtorch-core@0.1.0.0/src/tensor/contracts/replayed.bend as Replayed
5import bendtorch-core@0.1.0.0/src/tensor/contracts/pointwise.bend as Pointwise
6import bendtorch-core@0.1.0.0/src/tensor/contracts/pointwise_proof.bend as PointwiseProof
7import bendtorch-core@0.1.0.0/src/tensor/contracts/LAWS.bend as Laws
8
9
10def words_snoc(+shape: Shape.Shape, +fill: F32, +ops: List<&2, StorageLaws.Op>, +previous: Nat, +word: F32, +other: F32,
11 +before: List<&2, F32>, rest: {Laws.words(shape, fill, ops, previous) == before : List<&2, F32>},
12 last: {word == other : F32}) ->
13 {List.append(&2, F32, Laws.words(shape, fill, ops, previous), [word]) == List.append(&2, F32, before, [other]) : List<&2, F32>}:
14 %rest :
15 {List.append(&2, F32, Laws.words(shape, fill, ops, previous), [word]) == List.append(&2, F32, _, [other]) : List<&2, F32>}
16 %last :
17 {List.append(&2, F32, Laws.words(shape, fill, ops, previous), [word]) == List.append(&2, F32, Laws.words(shape, fill, ops, previous), [_]) : List<&2, F32>}
18 {==}
19
20
21def words_reads(~P: Data, ~map: P -> Nat -> Nat, +plan: P, +reads: Nat, +shape: Shape.Shape, +fill: F32, +ops: List<&2, StorageLaws.Op>,
22 +count: Nat) ->
23 {Laws.words(shape, fill, List.append(&2, StorageLaws.Op, ops, Pointwise.reads(~P, ~map, plan, reads)), count) ==
24 Laws.words(shape, fill, ops, count) : List<&2, F32>}:
25 match count:
26 case 0n:
27 {==}
28 case 1n+previous:
29 +position = U32.from_nat(previous)
30 +seen = List.append(&2, StorageLaws.Op, ops, Pointwise.reads(~P, ~map, plan, reads))
31 words_snoc(shape, fill, seen, previous, Replayed.value(shape, fill, seen, position), Replayed.value(shape, fill, ops, position),
32 Laws.words(shape, fill, ops, previous), words_reads(~P, ~map, plan, reads, shape, fill, ops, previous),
33 PointwiseProof.value_reads(~P, ~map, plan, reads, shape, fill, ops, position))
34
35
36def snoc_equal(+before: List<&2, F32>, +after: List<&2, F32>, +word: F32, +other: F32,
37 rest: {before == after : List<&2, F32>}, last: {word == other : F32}) ->
38 {List.append(&2, F32, before, [word]) == List.append(&2, F32, after, [other]) : List<&2, F32>}:
39 %rest : {List.append(&2, F32, before, [word]) == List.append(&2, F32, _, [other]) : List<&2, F32>}
40 %last : {List.append(&2, F32, before, [word]) == List.append(&2, F32, before, [_]) : List<&2, F32>}
41 {==}