proofs/loop_projection.bend checks
raw source on the hub · import stelliferous@0.0.3.0/proofs/loop_projection.bend as Loop_projection
One induction for every state representation, output index and step count.
7 imports
import Base import ./natural_addition.bend as Addition import ./bounded_u32_arithmetic.bend as Arithmetic import ./word_arithmetic.bend as WordArithmetic import ./nat_order.bend as Order import ./nat_division_order.bend as DivisionOrder import ../traversal_loop.bend as Loop
Definitions
def indexed_successor source · line 92 · raw
@+position:U32 -> @+offset:Nat -> {U32.add(position, U32.from_nat(1n+offset)) == U32.add(U32.add(position, 1), U32.from_nat(offset)) : U32}
Templates
template iterate source · line 10 · raw
@-State:Data -> @-step:(@_:State -> State) -> @count:Nat -> @state:State -> State
template iteration_split source · line 13 · raw
@-State:Type -> @-step:(@_:State -> State) -> @first:Nat -> @+second:Nat -> @-state:State -> {0xd6aaab858a4fbd1461bd0fee27b97184/traversal_loop.run(State, step, Nat.add(first, second), state) == 0xd6aaab858a4fbd1461bd0fee27b97184/traversal_loop.run(State, step, second, 0xd6aaab858a4fbd1461bd0fee27b97184/traversal_loop.run(State, step, first, state)) : State}
template eights source · line 20 · raw
@-State:Type -> @-step:(@_:State -> State) -> @-eight:(@_:State -> State) -> @-grouped:(@-state:State -> {eight(state) == 0xd6aaab858a4fbd1461bd0fee27b97184/traversal_loop.run(State, step, 8n, state) : State}) -> @count:Nat -> @-state:State -> {0xd6aaab858a4fbd1461bd0fee27b97184/traversal_loop.run(State, eight, count, state) == 0xd6aaab858a4fbd1461bd0fee27b97184/traversal_loop.run(State, step, Nat.mul(count, 8n), state) : State}count runs of a step that is eight steps are 8 * count steps.
template head_then_eights source · line 34 · raw
@-State:Type -> @-step:(@_:State -> State) -> @-eight:(@_:State -> State) -> @-grouped:(@-state:State -> {eight(state) == 0xd6aaab858a4fbd1461bd0fee27b97184/traversal_loop.run(State, step, 8n, state) : State}) -> @+count:Nat -> @-state:State -> {0xd6aaab858a4fbd1461bd0fee27b97184/traversal_loop.run(State, eight, Nat.div(count, 8n), 0xd6aaab858a4fbd1461bd0fee27b97184/traversal_loop.run(State, step, Nat.mod(count, 8n), state)) == 0xd6aaab858a4fbd1461bd0fee27b97184/traversal_loop.run(State, step, count, state) : State}The first count % 8 steps one by one, then the rest eight at a time.
template iteration_refines_model source · line 50 · raw
@-RuntimeState:Type -> @-ModelState:Data -> @-runtime_step:(@_:RuntimeState -> RuntimeState) -> @-model_step:(@_:ModelState -> ModelState) -> @-represent:(@_:ModelState -> RuntimeState) -> @-step_matches:(@+state:ModelState -> {runtime_step(represent(state)) == represent(model_step(state)) : RuntimeState}) -> @+count:Nat -> @+state:ModelState -> {0xd6aaab858a4fbd1461bd0fee27b97184/traversal_loop.run(RuntimeState, runtime_step, count, represent(state)) == represent(0xd6aaab858a4fbd1461bd0fee27b97184/traversal_loop.run(ModelState, model_step, count, state)) : RuntimeState}A single commuting step lifts to every count. RuntimeState may own arrays; only the model is duplicated in the proof. No runtime array is cloned.
template preserves_observation source · line 65 · raw
@-State:Data -> @-Observation:Data -> @-step:(@_:State -> State) -> @-observe:(@_:State -> Observation) -> @-preserved:(@+state:State -> {observe(step(state)) == observe(state) : Observation}) -> @+count:Nat -> @+state:State -> {observe(iterate(State, step, count, state)) == observe(state) : Observation}A read-only observation is preserved for every number of iterations.
template iteration_matches_denotation source · line 76 · raw
@-Observation:Data -> @-State:Data -> @-Index:Data -> @-step:(@_:State -> State) -> @-project:(@_:Index -> @_:State -> Observation) -> @-denote:(@_:Index -> @_:Nat -> @_:State -> Observation) -> @-at_zero:(@+index:Index -> @+state:State -> {project(index, state) == denote(index, 0n, state) : Observation}) -> @-after_step:(@+index:Index -> @+count:Nat -> @+state:State -> {denote(index, count, step(state)) == denote(index, 1n+count, state) : Observation}) -> @+count:Nat -> @+index:Index -> @+state:State -> {project(index, iterate(State, step, count, state)) == denote(index, count, state) : Observation}
template run_then_finishes source · line 100 · raw
@-State:Type -> @-Result:Type -> @-step:(@_:State -> State) -> @-finish:(@_:State -> Result) -> @count:Nat -> @-state:State -> {0xd6aaab858a4fbd1461bd0fee27b97184/traversal_loop.run_then(State, Result, step, finish, count, state) == finish(0xd6aaab858a4fbd1461bd0fee27b97184/traversal_loop.run(State, step, count, state)) : Result}The final step is applied once, to the state the loop ends in.
template natural_counter_progress source · line 107 · raw
@-State:Data -> @-step:(@_:State -> State) -> @-position:(@_:State -> Nat) -> @-advances:(@+state:State -> {position(step(state)) == 1n+position(state) : Nat}) -> @+count:Nat -> @+state:State -> {position(iterate(State, step, count, state)) == Nat.add(count, position(state)) : Nat}Natural counters use the same symbolic induction as machine counters.
template preserves_invariant source · line 119 · raw
@-State:Data -> @-Context:Data -> @-Property:(@_:Context -> @_:State -> Data) -> @-step:(@_:State -> State) -> @-preserved:(@+context:Context -> @+state:State -> @_:Property(context, state) -> Property(context, step(state))) -> @count:Nat -> @+context:Context -> @+state:State -> @evidence:Property(context, state) -> Property(context, 0xd6aaab858a4fbd1461bd0fee27b97184/traversal_loop.run(State, step, count, state))
Structural properties of an owned model also follow the shared loop.