proofs/traversal_batch_refinement.bend checks
raw source on the hub · import stelliferous@0.0.3.0/proofs/traversal_batch_refinement.bend as Traversal_batch_refinement
A batch writes the mapped values of consecutive positions after reading all of them from the original tree. Inside the tree it is the ordered in-place map of the same positions: no step of that map reads a position an earlier step wrote. For every element type and every batch length.
13 imports
import Base import ../traversal_array.bend as Traversal import ../traversal_loop.bend as Loop import ./traversal_array_refinement.bend as ArrayLaws import ./traversal_map_readback.bend as MapReadback import ./storage_tree_model.bend as Tree import ./storage_shape.bend as Shape import ./nat_to_u32_bounds.bend as Bounds import ./nat_order.bend as Order import ./natural_addition.bend as Addition import ./nat_interval.bend as Interval import ./loop_projection.bend as Projection import ./row_major_index.bend as RowMajor
Types
type RoundPlan source · line 145 · raw
@-Element:Data -> @-Context:Data -> @-width:Nat -> Data
Consecutive fixed-width jobs use the indexed traversal invariant. A caller supplies the equation for one batch and its preserved reader frame.
RoundPlan@-Element:Data -> @-Context:Data -> @-width:Nat -> @count:Nat -> @context:Context -> @original:0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_tree_model.Tree<Element> -> @depth:Nat -> @capacity:U32 -> @capacity_equal:{0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_tree_model.capacity(Element, original) == capacity : U32} -> @balanced:0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_shape.Balanced(Element, depth, original) -> @depth_ok:{Nat.is_le(depth, 31n) == True{} : Bool} -> @capacity_ok:{U32.is_le(capacity, 2147483648) == True{} : Bool} -> @room:{Nat.is_le(Nat.mul(count, width), U32.to_nat(capacity)) == True{} : Bool} -> RoundPlan<Element, Context, width>
Templates
template batch source · line 19 · raw
@-Element:Data -> @-Context:Data -> @-map:(@_:Context -> @_:U32 -> @_:Element -> Element) -> @count:Nat -> @+position:U32 -> @+context:Context -> @+source:0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_tree_model.Tree<Element> -> @target:0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_tree_model.Tree<Element> -> 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_tree_model.Tree<Element>
template ModelState source · line 26 · raw
@-Element:Data -> @-Context:Data -> Data
template last_step source · line 30 · raw
@-State:Data -> @-step:(@_:State -> State) -> @+count:Nat -> @+state:State -> {0xd6aaab858a4fbd1461bd0fee27b97184/traversal_loop.run(State, step, 1n+count, state) == step(0xd6aaab858a4fbd1461bd0fee27b97184/traversal_loop.run(State, step, count, state)) : State}A loop's last step, for every state and count.
template state_after source · line 37 · raw
@-Element:Data -> @-Context:Data -> @-map:(@_:Context -> @_:U32 -> @_:Element -> Element) -> @+count:Nat -> @+start:Nat -> @+context:Context -> @+input:0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_tree_model.Tree<Element> -> {0xd6aaab858a4fbd1461bd0fee27b97184/traversal_loop.run(ModelState(Element, Context), 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/traversal_array_refinement.model_map_step(Element, Context, map), count, 0xd6aaab858a4fbd1461bd0fee27b97184/traversal_array.State{Unit{}, input, U32.from_nat(start), context}) == 0xd6aaab858a4fbd1461bd0fee27b97184/traversal_array.State{Unit{}, 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/traversal_map_readback.run_indexed(Element, Context, map, count, U32.from_nat(start), context, input), U32.from_nat(Nat.add(start, count)), context} : ModelState(Element, Context)}The whole state after count steps of the model map.
template map_split source · line 57 · raw
@-Element:Data -> @-Context:Data -> @-map:(@_:Context -> @_:U32 -> @_:Element -> Element) -> @+first:Nat -> @+second:Nat -> @+start:Nat -> @+context:Context -> @+input:0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_tree_model.Tree<Element> -> {0xd6aaab858a4fbd1461bd0fee27b97184/proofs/traversal_map_readback.run_indexed(Element, Context, map, Nat.add(first, second), U32.from_nat(start), context, input) == 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/traversal_map_readback.run_indexed(Element, Context, map, second, U32.from_nat(Nat.add(start, first)), context, 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/traversal_map_readback.run_indexed(Element, Context, map, first, U32.from_nat(start), context, input)) : 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_tree_model.Tree<Element>}One more step of the model map writes the position after the ones it mapped.
template extended source · line 70 · raw
@-Element:Data -> @-Context:Data -> @-map:(@_:Context -> @_:U32 -> @_:Element -> Element) -> @+done:Nat -> @+start:Nat -> @+context:Context -> @+input:0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_tree_model.Tree<Element> -> {0xd6aaab858a4fbd1461bd0fee27b97184/proofs/traversal_map_readback.run_indexed(Element, Context, map, 1n+done, U32.from_nat(start), context, input) == 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_tree_model.write(Element, 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/traversal_map_readback.run_indexed(Element, Context, map, done, U32.from_nat(start), context, input), U32.from_nat(Nat.add(start, done)), map(context, U32.from_nat(Nat.add(start, done)), 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_tree_model.read(Element, 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/traversal_map_readback.run_indexed(Element, Context, map, done, U32.from_nat(start), context, input), U32.from_nat(Nat.add(start, done))))) : 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_tree_model.Tree<Element>}
template continued source · line 90 · raw
@-Element:Data -> @-Context:Data -> @-map:(@_:Context -> @_:U32 -> @_:Element -> Element) -> @+remaining:Nat -> @+done:Nat -> @+start:Nat -> @+context:Context -> @+input:0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_tree_model.Tree<Element> -> @+depth:Nat -> @+capacity:U32 -> @+capacity_equal:{0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_tree_model.capacity(Element, input) == capacity : U32} -> @+balanced:0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_shape.Balanced(Element, depth, input) -> @+limit:{Nat.is_le(depth, 31n) == True{} : Bool} -> @+capacity_ok:{U32.is_le(capacity, 2147483648) == True{} : Bool} -> @+room:{Nat.is_le(Nat.add(Nat.add(start, done), remaining), U32.to_nat(capacity)) == True{} : Bool} -> {batch(Element, Context, map, remaining, U32.from_nat(Nat.add(start, done)), context, input, 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/traversal_map_readback.run_indexed(Element, Context, map, done, U32.from_nat(start), context, input)) == 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/traversal_map_readback.run_indexed(Element, Context, map, Nat.add(done, remaining), U32.from_nat(start), context, input) : 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_tree_model.Tree<Element>}A batch that continues done steps of the map completes the map.
template mapped source · line 132 · raw
@-Element:Data -> @-Context:Data -> @-map:(@_:Context -> @_:U32 -> @_:Element -> Element) -> @+count:Nat -> @+start:Nat -> @+context:Context -> @+input:0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_tree_model.Tree<Element> -> @+depth:Nat -> @+capacity:U32 -> @+capacity_equal:{0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_tree_model.capacity(Element, input) == capacity : U32} -> @+balanced:0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_shape.Balanced(Element, depth, input) -> @+limit:{Nat.is_le(depth, 31n) == True{} : Bool} -> @+capacity_ok:{U32.is_le(capacity, 2147483648) == True{} : Bool} -> @+room:{Nat.is_le(Nat.add(start, count), U32.to_nat(capacity)) == True{} : Bool} -> {batch(Element, Context, map, count, U32.from_nat(start), context, input, input) == 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/traversal_map_readback.run_indexed(Element, Context, map, count, U32.from_nat(start), context, input) : 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_tree_model.Tree<Element>}A batch from the original tree is the map of its positions.
template round_count source · line 152 · raw
@-Element:Data -> @-Context:Data -> @-width:Nat -> @plan:RoundPlan<Element, Context, width> -> Nat
template round_context source · line 156 · raw
@-Element:Data -> @-Context:Data -> @-width:Nat -> @plan:RoundPlan<Element, Context, width> -> Context
template round_original source · line 160 · raw
@-Element:Data -> @-Context:Data -> @-width:Nat -> @plan:RoundPlan<Element, Context, width> -> 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_tree_model.Tree<Element>
template round_update source · line 164 · raw
@-Element:Data -> @-Context:Data -> @-State:Data -> @-width:Nat -> @-step:(@_:U32 -> @_:Context -> @_:State -> State) -> @index:U32 -> @plan:RoundPlan<Element, Context, width> -> @state:State -> State
template round_frame source · line 167 · raw
@-Element:Data -> @-Context:Data -> @-State:Data -> @-MapContext:Data -> @-width:Nat -> @-output:(@_:State -> 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_tree_model.Tree<Element>) -> @-map_context:(@_:Context -> MapContext) -> @-map:(@_:MapContext -> @_:U32 -> @_:Element -> Element) -> @-Frame:(@_:Context -> @_:State -> Data) -> @plan:RoundPlan<Element, Context, width> -> @index:Nat -> @state:State -> Data
template round_frame_step source · line 173 · raw
@-Element:Data -> @-Context:Data -> @-State:Data -> @-MapContext:Data -> @-width:Nat -> @-output:(@_:State -> 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_tree_model.Tree<Element>) -> @-map_context:(@_:Context -> MapContext) -> @-map:(@_:MapContext -> @_:U32 -> @_:Element -> Element) -> @-Frame:(@_:Context -> @_:State -> Data) -> @-step:(@_:U32 -> @_:Context -> @_:State -> State) -> @-frame_step:(@+context:Context -> @+index:U32 -> @+state:State -> @_:Frame(context, state) -> Frame(context, step(index, context, state))) -> @-batch_matches:(@+context:Context -> @+index:Nat -> @+state:State -> @+depth:Nat -> @+capacity:U32 -> @_:Frame(context, state) -> @_:{0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_tree_model.capacity(Element, output(state)) == capacity : U32} -> @_:0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_shape.Balanced(Element, depth, output(state)) -> @_:{Nat.is_le(depth, 31n) == True{} : Bool} -> @_:{U32.is_le(capacity, 2147483648) == True{} : Bool} -> @_:{Nat.is_le(Nat.add(Nat.mul(index, width), width), U32.to_nat(capacity)) == True{} : Bool} -> {output(step(U32.from_nat(index), context, state)) == 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/traversal_map_readback.run_indexed(Element, MapContext, map, width, U32.from_nat(Nat.mul(index, width)), map_context(context), output(state)) : 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_tree_model.Tree<Element>}) -> @+plan:RoundPlan<Element, Context, width> -> @+index:Nat -> @+state:State -> @inside:{Nat.is_lt(index, round_count(Element, Context, width, plan)) == True{} : Bool} -> @progress:round_frame(Element, Context, State, MapContext, width, output, map_context, map, Frame, plan, index, state) -> round_frame(Element, Context, State, MapContext, width, output, map_context, map, Frame, plan, 1n+index, round_update(Element, Context, State, width, step, U32.from_nat(index), plan, state))
template round_same_step source · line 215 · raw
@-Element:Data -> @-Context:Data -> @-State:Data -> @-width:Nat -> @-step:(@_:U32 -> @_:Context -> @_:State -> State) -> @+index:U32 -> @+plan:RoundPlan<Element, Context, width> -> @+state:State -> {round_update(Element, Context, State, width, step, index, plan, state) == step(index, round_context(Element, Context, width, plan), state) : State}
template fold_mapped source · line 220 · raw
@-Element:Data -> @-Context:Data -> @-State:Data -> @-MapContext:Data -> @-width:Nat -> @-output:(@_:State -> 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_tree_model.Tree<Element>) -> @-map_context:(@_:Context -> MapContext) -> @-map:(@_:MapContext -> @_:U32 -> @_:Element -> Element) -> @-Frame:(@_:Context -> @_:State -> Data) -> @-step:(@_:U32 -> @_:Context -> @_:State -> State) -> @-frame_step:(@+context:Context -> @+index:U32 -> @+state:State -> @_:Frame(context, state) -> Frame(context, step(index, context, state))) -> @-batch_matches:(@+context:Context -> @+index:Nat -> @+state:State -> @+depth:Nat -> @+capacity:U32 -> @_:Frame(context, state) -> @_:{0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_tree_model.capacity(Element, output(state)) == capacity : U32} -> @_:0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_shape.Balanced(Element, depth, output(state)) -> @_:{Nat.is_le(depth, 31n) == True{} : Bool} -> @_:{U32.is_le(capacity, 2147483648) == True{} : Bool} -> @_:{Nat.is_le(Nat.add(Nat.mul(index, width), width), U32.to_nat(capacity)) == True{} : Bool} -> {output(step(U32.from_nat(index), context, state)) == 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/traversal_map_readback.run_indexed(Element, MapContext, map, width, U32.from_nat(Nat.mul(index, width)), map_context(context), output(state)) : 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_tree_model.Tree<Element>}) -> @+count:Nat -> @+context:Context -> @+state:State -> @+depth:Nat -> @+capacity:U32 -> @+frame:Frame(context, state) -> @+capacity_equal:{0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_tree_model.capacity(Element, output(state)) == capacity : U32} -> @+balanced:0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_shape.Balanced(Element, depth, output(state)) -> @+depth_ok:{Nat.is_le(depth, 31n) == True{} : Bool} -> @+capacity_ok:{U32.is_le(capacity, 2147483648) == True{} : Bool} -> @+room:{Nat.is_le(Nat.mul(count, width), U32.to_nat(capacity)) == True{} : Bool} -> 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_shape.Both<Frame(context, 0xd6aaab858a4fbd1461bd0fee27b97184/traversal_array.indexed_fold(State, Context, step, count, 0, context, state)), {output(0xd6aaab858a4fbd1461bd0fee27b97184/traversal_array.indexed_fold(State, Context, step, count, 0, context, state)) == 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/traversal_map_readback.run_indexed(Element, MapContext, map, Nat.mul(count, width), 0, map_context(context), output(state)) : 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/storage_tree_model.Tree<Element>}>