theoremcompareTrace (original suffix targetSuffix rank position : ListBool)
(x v : Nat) (ambient : σ) (register : OptionBool) :
(advance (TM2.step program))^[x + min x v + 3]
(some (cfg (some (.inl .field)) .checking original (encodeWord x ++ suffix)
(encodeWord v ++ targetSuffix) [] rank position ambient register)) =
some (cfg (some (.inr .dispatch)) .checking original suffix
(encodeWord v ++ targetSuffix) (List.replicate (if x = v then1else0) true)
rank position ambient none) :=by
proof · 14
lines
have h :=MachineCloudCount.preservingFieldTrace BaseLabel.field BaseLabel.restore BaseLabel.done
baseProgram rfl rfl original suffix targetSuffix [] rank x v ambient register
simp only [List.append_nil] at h
havehhalt : (advance (TM2.step baseProgram))^[x + min x v + 3]
(some ⟨some .field, ((ambient, false), register),
MachineCloudCount.memory original (encodeWord x ++ suffix)
(encodeWord v ++ targetSuffix) [] [] rank⟩) =
some ⟨none, ((ambient, false), none),
MachineCloudCount.memory original suffix (encodeWord v ++ targetSuffix) []
(List.replicate (if x = v then1else0) true) rank⟩ :=by
rw [show x + min x v + 3 = (x + min x v + 2) + 1by omega,
Function.iterate_succ_apply', h, advance_some]
rfl
convert liftTrace Phase.checking position _ _ _ hhalt using1 <;> rfl
theoremdispatch_miss (original work target rank position : ListBool) (ambient : σ) :
TM2.step program (cfg (some (.inr .dispatch)) .checking
original work target [] rank position ambient none) =
some (cfg (some (.inl (skipLabel 0))) .advancing
original work target [] rank position ambient none) :=by
theoremdispatch_hit_zero (original work target rankSuffix position : ListBool) (ambient : σ) :
TM2.step program (cfg (some (.inr .dispatch)) .checking
original work target [true] (encodeWord 0 ++ rankSuffix) position ambient none) =
some (cfg (some (.inl .clearWork)) .finishing
original work target [] rankSuffix position ambient none) :=by
theoremselectedTrace (v : Nat) (original work targetSuffix rankSuffix position : ListBool)
(ambient : σ) (register : OptionBool) :
(advance (TM2.step program))^[2 * v + work.length + rankSuffix.length + 8]
(some (cfg (some (.inl .field)) .checking original (encodeWord v ++ work)
(encodeWord v ++ targetSuffix) [] (encodeWord 0 ++ rankSuffix) position ambient register)) =
some (cfg none .checking original [] (encodeWord v ++ targetSuffix) [] [] position ambient none) :=by
proof · 10
lines
have hcompare := compareTrace original work targetSuffix (encodeWord 0 ++ rankSuffix)
position v v ambient register
simp only [ite_true, List.replicate_succ, List.replicate_zero] at hcompare
rw [show2 * v + work.length + rankSuffix.length + 8 =
(work.length + rankSuffix.length + 4) + (1 + (v + min v v + 3)) by
simp only [Nat.min_self]; omega,
Function.iterate_add_apply _ (work.length + rankSuffix.length + 4),
Function.iterate_add_apply _ 1, hcompare, Function.iterate_one, advance_some,
dispatch_hit_zero]
exact cleanupTrace original work (encodeWord v ++ targetSuffix) rankSuffix position ambient
theoremprefixSelectedTrace (preceding : ListRow)
(hwidth : ∀ r ∈ preceding, r.2.length = 4097) (v position : Nat)
(original work targetSuffix rankSuffix outputSuffix : ListBool)
(ambient : σ) (register : OptionBool) :
(advance (TM2.step program))^[prefixTime v preceding + 2 * v + work.length + rankSuffix.length + 8]
(some (cfg (some (.inl .field)) .checking original
(encodeWords (preceding.flatMap rowWords) ++ (encodeWord v ++ work))
(encodeWord v ++ targetSuffix) [] (encodeWord (rowsHits v preceding) ++ rankSuffix)
(encodeWord position ++ outputSuffix) ambient register)) =
some (cfg none .checking original [] (encodeWord v ++ targetSuffix) [] []
(encodeWord (position + preceding.length) ++ outputSuffix) ambient none) :=by
proof · 10
lines
have hp := prefixTrace preceding hwidth v 0 position original (encodeWord v ++ work)
targetSuffix rankSuffix outputSuffix ambient register
simp only [Nat.add_zero] at hp
have hs := selectedTrace v original work targetSuffix rankSuffix
(encodeWord (position + preceding.length) ++ outputSuffix) ambient
(if preceding = [] then register else none)
rw [show prefixTime v preceding + 2 * v + work.length + rankSuffix.length + 8 =
(2 * v + work.length + rankSuffix.length + 8) + prefixTime v preceding by omega,
Function.iterate_add_apply, hp]
exact hs
theoremfullTrace (n m v rank : Nat) (rs preceding : ListRow) (work : ListBool)
(hwidth : ∀ r ∈ preceding, r.2.length = 4097)
(hword : encodeWords (rs.flatMap rowWords) =
encodeWords (preceding.flatMap rowWords) ++ (encodeWord v ++ work))
(hrank : rank = rowsHits v preceding) (querySuffix outputSuffix : ListBool)
(ambient : σ) (register : OptionBool) :
(advance (TM2.step program))^[totalSteps n m v rank rs preceding work querySuffix]
(some (cfg (some (.inr .initialize)) .checking (MachineCloudCount.inputWord n m rs)
[] (queryWord v rank querySuffix) [] [] outputSuffix ambient register)) =
some (cfg none .checking (MachineCloudCount.inputWord n m rs) []
(queryWord v rank querySuffix) [] [] (encodeWord preceding.length ++ outputSuffix) ambient none) :=by
proof · 12
lines
have hp := prepareTrace n m v rank rs querySuffix (encodeWord 0 ++ outputSuffix) ambient none
have hs := prefixSelectedTrace preceding hwidth v 0 (MachineCloudCount.inputWord n m rs) work
(encodeWord rank ++ querySuffix) querySuffix outputSuffix ambient none
simp only [Nat.zero_add] at hs
rw [← hrank, ← hword] at hs
rw [show totalSteps n m v rank rs preceding work querySuffix =
(prefixTime v preceding + 2 * v + work.length + querySuffix.length + 8) +
(prepareSteps n m v rank rs querySuffix + 1) by unfold totalSteps; omega,
Function.iterate_add_apply _ (prefixTime v preceding + 2 * v + work.length + querySuffix.length + 8),
Function.iterate_succ_apply _ (prepareSteps n m v rank rs querySuffix),
advance_some, initializeStep, hp]
exact hs
theoremtotalSteps_le (n m v rank : Nat) (rs preceding : ListRow) (work querySuffix : ListBool)
(hword : encodeWords (rs.flatMap rowWords) =
encodeWords (preceding.flatMap rowWords) ++ (encodeWord v ++ work)) :
totalSteps n m v rank rs preceding work querySuffix ≤10 * ((MachineCloudCount.inputWord n m rs).length + (queryWord v rank querySuffix).length) + 20:=by
proof · 10
lines
have hp := prefixTime_le v preceding
have hw := congrArg List.length hword
simp only [List.length_append, encodeWord_length] at hw
have ht :=MachineCloudCount.inputWord_length n m rs
havehq : (queryWord v rank querySuffix).length =
v + 1 + (rank + 1) + querySuffix.length :=by
simp only [queryWord, MachineCloudRank.queryWord, List.length_append, encodeWord_length]
omega
unfold totalSteps prepareSteps
omega
defcloudSelectSteps (t : GraphTables.Table) (v : Fin t.vertices)
(i : Fin (PreprocessingCloudIndex.cloudSize t v)) (querySuffix : ListBool) : Nat:=
body · 3
lines
let e := (PreprocessingCloudIndex.cloudSelect t v i).val
totalSteps t.vertices t.darts v.val i.val (tableRows t) ((tableRows t).take e.val)
(remainder t e) querySuffix
theoremcloudSelectTrace (t : GraphTables.Table) (v : Fin t.vertices)
(i : Fin (PreprocessingCloudIndex.cloudSize t v)) (querySuffix outputSuffix : ListBool)
(ambient : σ) (register : OptionBool) :
(advance (TM2.step program))^[cloudSelectSteps t v i querySuffix]
(some (cfg (some (.inr .initialize)) .checking (GraphTables.tableBits t)
[] (queryWord v.val i.val querySuffix) [] [] outputSuffix ambient register)) =
some (cfg none .checking (GraphTables.tableBits t) [] (queryWord v.val i.val querySuffix)
[] [] (encodeWord (PreprocessingCloudIndex.cloudSelect t v i).val.val ++ outputSuffix)
ambient none) :=by
proof · 14
lines
let e :=PreprocessingCloudIndex.cloudSelect t v i
have hword := tableWord_split t v e.val e.property
havehrank : i.val = rowsHits v.val ((tableRows t).take e.val.val) :=by
simpa only [PreprocessingCloudIndex.cloudRank_cloudSelect] usingMachineCloudRank.cloudRank_eq_prefix_count t v (PreprocessingCloudIndex.cloudSelect t v i)
have h := fullTrace t.vertices t.darts v.val i.val (tableRows t)
((tableRows t).take e.val.val) (remainder t e.val)
(by intro r hr; exact MachineCloudCount.tableRows_width t r (List.mem_of_mem_take hr))
hword hrank querySuffix outputSuffix ambient register
havehtake : ((tableRows t).take e.val.val).length = e.val.val :=by
rw [List.length_take, MachineCloudRank.tableRows_length,
Nat.min_eq_left e.val.isLt.le]
rw [MachineCloudCount.tableRows_input, htake] at h
exact h
theoremcloudSelectSteps_le (t : GraphTables.Table) (v : Fin t.vertices)
(i : Fin (PreprocessingCloudIndex.cloudSize t v)) (querySuffix : ListBool) :
cloudSelectSteps t v i querySuffix ≤10 * ((GraphTables.tableBits t).length + (queryWord v.val i.val querySuffix).length) + 20:=by
proof · 5
lines
let e :=PreprocessingCloudIndex.cloudSelect t v i
have h := totalSteps_le t.vertices t.darts v.val i.val (tableRows t)
((tableRows t).take e.val.val) (remainder t e.val) querySuffix
(tableWord_split t v e.val e.property)
simpa only [cloudSelectSteps, e, MachineCloudCount.tableRows_input] using h
defcloudSelectInTime (t : GraphTables.Table) (v : Fin t.vertices)
(i : Fin (PreprocessingCloudIndex.cloudSize t v)) (querySuffix outputSuffix : ListBool)
(ambient : σ) (register : OptionBool) :
StateTransition.EvalsToInTime (TM2.step program)
(cfg (some (.inr .initialize)) .checking (GraphTables.tableBits t)
[] (queryWord v.val i.val querySuffix) [] [] outputSuffix ambient register)
(some (cfg none .checking (GraphTables.tableBits t) [] (queryWord v.val i.val querySuffix)
[] [] (encodeWord (PreprocessingCloudIndex.cloudSelect t v i).val.val ++ outputSuffix)
ambient none))
(timePolynomial.eval ((GraphTables.tableBits t).length + (queryWord v.val i.val querySuffix).length)) where
body · 5
lines
steps := cloudSelectSteps t v i querySuffix
evals_in_steps := cloudSelectTrace t v i querySuffix outputSuffix ambient register
steps_le_m :=by
simpa only [timePolynomial, Polynomial.eval_add, Polynomial.eval_mul,
Polynomial.eval_C, Polynomial.eval_X] using cloudSelectSteps_le t v i querySuffix
defmachineInTime (t : GraphTables.Table) (v : Fin t.vertices)
(i : Fin (PreprocessingCloudIndex.cloudSize t v)) (querySuffix outputSuffix : ListBool)
(register : OptionBool) :
StateTransition.EvalsToInTime machine.step
(cfg (some (.inr .initialize)) .checking (GraphTables.tableBits t)
[] (queryWord v.val i.val querySuffix) [] [] outputSuffix () register)
(some (cfg none .checking (GraphTables.tableBits t) [] (queryWord v.val i.val querySuffix)
[] [] (encodeWord (PreprocessingCloudIndex.cloudSelect t v i).val.val ++ outputSuffix)
() none))
(timePolynomial.eval ((GraphTables.tableBits t).length + (queryWord v.val i.val querySuffix).length)) where
body · 7
lines
steps := cloudSelectSteps t v i querySuffix
evals_in_steps :=by
convert cloudSelectTrace t v i querySuffix outputSuffix () register using1
rfl
steps_le_m :=by
simpa only [timePolynomial, Polynomial.eval_add, Polynomial.eval_mul,
Polynomial.eval_C, Polynomial.eval_X] using cloudSelectSteps_le t v i querySuffix