theoremselect_eq_zip_filterMap (mask : ListBool) (records : List (ListBool)) :
select mask records =
(mask.zip records).filterMap (fun p =>if p.1then some p.2else none) :=by
proof · 6
lines
induction records generalizing mask with
| nil => simp [select]
| cons item rest ih =>
cases mask with
| nil => simpa [select] using ih []
| cons b mask => cases b <;> simp [select, ih]
theorempopTag_eval (t p k d b : Bool) (source mask accum output : ListBool) :
StructuredCalls.Eval popTag 1
(state t p k d (b :: source) mask accum output)
(state b true k d source mask accum output) :=by
proof · 4
lines
apply StructuredCalls.Eval.base
convert StructuredProgram.Eval.atom (.pop (0 : Fin4) 01)
(state t p k d (b :: source) mask accum output) using1
simp [Atom.eval, Atom.instr, State.ofCfg, execInstr, state, readRegs]
theorempopBit_eval (t p k d b : Bool) (source mask accum output : ListBool) :
StructuredCalls.Eval popBit 1
(state t p k d (b :: source) mask accum output)
(state t true k b source mask accum output) :=by
proof · 4
lines
apply StructuredCalls.Eval.base
convert StructuredProgram.Eval.atom (.pop (0 : Fin4) 31)
(state t p k d (b :: source) mask accum output) using1
simp [Atom.eval, Atom.instr, State.ofCfg, execInstr, state, readRegs]
theorempopMask_eval (t p k d : Bool) (source mask accum output : ListBool) :
StructuredCalls.Eval popMask 1 (state t p k d source mask accum output)
(state t (!mask.isEmpty) (mask.headD false) d source mask.tail accum output) :=by
proof · 5
lines
apply StructuredCalls.Eval.base
convert StructuredProgram.Eval.atom (.pop (1 : Fin4) 21)
(state t p k d source mask accum output) using1
cases mask <;>
simp [Atom.eval, Atom.instr, State.ofCfg, execInstr, state, readRegs]
theorempush_eval (r : Fin4) (t p k d : Bool) (source mask accum output : ListBool) :
StructuredCalls.Eval (atom (.push 2 r)) 1
(state t p k d source mask accum output)
(state t p k d source mask (regs t p k d r :: accum) output) :=by
proof · 4
lines
apply StructuredCalls.Eval.base
convert StructuredProgram.Eval.atom (.push (2 : Fin4) r)
(state t p k d source mask accum output) using1
simp [Atom.eval, Atom.instr, State.ofCfg, execInstr, state]
theorememit_eval (r : Fin4) (t p k d : Bool) (source mask accum output : ListBool) :
StructuredCalls.Eval (emit r) (emitCost k)
(state t p k d source mask accum output)
(state t p k d source mask
(ifk then regs t p k d r :: accum else accum) output) :=by
proof · 5
lines
cases k with
| false=>
exact StructuredCalls.Eval.ite_false rfl (.base (.skip _))
| true=>
exact StructuredCalls.Eval.ite_true rfl (push_eval r t p true d source mask accum output)
match bits with
| [] => state falsetrue keep bit tail mask accum output
| b :: bs => state truetrue keep bit (b :: (Encoding.frame bs ++ tail)) mask accum output
theorempop_frame_eval (bits tail mask accum output : ListBool) (t p k d : Bool) :
StructuredCalls.Eval popTag 1
(state t p k d (Encoding.frame bits ++ tail) mask accum output)
(frameReady bits tail mask accum output k d) :=by
proof · 3
lines
cases bits with
| nil => exact popTag_eval t p k d false tail mask accum output
| cons b bs => exact popTag_eval t p k d true _ mask accum output
theoremscanFrame_eval (bits tail mask accum output : ListBool) (t p keep bit : Bool) :
∃ steps ≤7 * bits.length + 4, ∃last : Bool,
StructuredCalls.Eval scanFrame steps
(state t p keep bit (Encoding.frame bits ++ tail) mask accum output)
(state falsetrue keep last tail mask
(if keep then (Encoding.frame bits).reverse ++ accum else accum) output) :=by
proof · 12
lines
obtain ⟨n, hn, last, hi⟩ := frameLoop_eval bits tail mask accum output keep bit
have hp := pop_frame_eval bits tail mask accum output t p keep bit
have he := emit_eval 0falsetrue keep last tail mask
(if keep then (framePrefix bits).reverse ++ accum else accum) output
have hrun :=StructuredCalls.Eval.seq hp (StructuredCalls.Eval.seq hi he)
refine ⟨1 + (n + emitCost keep), ?_, last, ?_⟩
· have hc := emitCost_le keep
omega
· convert hrun using1
· rfl
· cases keep <;>
simp [frame_eq_prefix, List.reverse_append, regs]
defrecordReady (records : List (ListBool)) (suffix mask accum output : ListBool)
(keep bit : Bool) : Data:=
body · 4
lines
match records with
| [] => state falsetrue keep bit suffix mask accum output
| item :: rest => state truetrue keep bit
(Encoding.frame item ++ (Encoding.encodeList id rest ++ suffix)) mask accum output
theorempop_record_eval (records : List (ListBool)) (suffix mask accum output : ListBool)
(t p k d : Bool) :
StructuredCalls.Eval popTag 1
(state t p k d (Encoding.encodeList id records ++ suffix) mask accum output)
(recordReady records suffix mask accum output k d) :=by
proof · 7
lines
cases records with
| nil => exact popTag_eval t p k d false suffix mask accum output
| cons item rest =>
simpa only [Encoding.encodeList, id_eq, List.cons_append, List.append_assoc,
recordReady] using
popTag_eval t p k d true
(Encoding.frame item ++ (Encoding.encodeList id rest ++ suffix)) mask accum output
theoremscanRecords_eval (records : List (ListBool))
(suffix mask accum output : ListBool) (t p keep bit : Bool) :
∃ steps ≤ recordCost records + 1, ∃finalKeep finalBit : Bool,
StructuredCalls.Eval scanRecords steps
(state t p keep bit (Encoding.encodeList id records ++ suffix) mask accum output)
(state falsetrue finalKeep finalBit suffix (mask.drop records.length)
((recordPrefix (select mask records)).reverse ++ accum) output) :=by
proof · 4
lines
obtain ⟨n, hn, finalKeep, finalBit, hi⟩ :=
recordLoop_eval records suffix mask accum output keep bit
refine ⟨1 + n, by omega, finalKeep, finalBit, ?_⟩
exact .seq (pop_record_eval records suffix mask accum output t p keep bit) hi
theoremrun_correct (records : List (ListBool)) (suffix mask : ListBool)
(t p keep bit : Bool) :
BitProgram.RunsIn program (runtimeBound records)
((state t p keep bit (Encoding.encodeList id records ++ suffix) mask [] []).withPC
(some program.entry))
((state falsefalsefalsefalse suffix (mask.drop records.length) []
(Encoding.encodeList id (select mask records))).withPC none) :=by
proof · 2
lines
obtain ⟨steps, hsteps, hrun⟩ := command_eval records suffix mask t p keep bit
exact ⟨steps + 1, hsteps, StructuredCalls.compiled_halt_trace hrun 03⟩
theoremprimitive_correct (records : List (ListBool)) (suffix mask : ListBool)
(t p keep bit : Bool) :
Computation.RunsIn (BitProgram.primitive program).step
(BitProgram.primitiveOverhead program * runtimeBound records)
(BitProgram.primitiveCfg program
((state t p keep bit (Encoding.encodeList id records ++ suffix) mask [] []).withPC
(some program.entry)))
(BitProgram.primitiveCfg program
((state falsefalsefalsefalse suffix (mask.drop records.length) []
(Encoding.encodeList id (select mask records))).withPC none)) :=
proof · 1
line
BitProgram.primitive_execution program (run_correct records suffix mask t p keep bit)