Download lean/OAI/Combinatorics/IndependentSets/Machines/Basic.lean from roseking/openAI-math-dataset: direct link, hf CLI and curl.
- Browser
- Download file 18.3 kB
-
https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Combinatorics/IndependentSets/Machines/Basic.lean
- Command line
-
hf download hf://datasets/roseking/openAI-math-dataset/lean/OAI/Combinatorics/IndependentSets/Machines/Basic.lean
-
curl -L -o Basic.lean https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Combinatorics/IndependentSets/Machines/Basic.lean
18.3 kB
Lean 4 · 73
declarations statementsfull
inductive Extra body · 2 lines
| m | index | work | scratch | vertices | darts | emit | output
deriving DecidableEqinstance : Fintype Extra where body · 2 lines
elems := {.m, .index, .work, .scratch, .vertices, .darts, .emit, .output}
complete value := by cases value <;> simpabbrev Tape := MachineCloudPrefix.Tape ⊕ Extra abbrev Alphabet (_ : Tape) := Bool abbrev State (σ : Type) := MachineCloudPrefix.State σ def tableTape : Tape := .inl (.inner .table) def nTape : Tape := .inl .bound def queryTape : Tape := .inl (.inner .query) def fuelTape : Tape := .inl .remaining def sumTape : Tape := .inl .total def mTape : Tape := .inr .m def indexTape : Tape := .inr .index def workTape : Tape := .inr .work def scratchTape : Tape := .inr .scratch def verticesTape : Tape := .inr .vertices def dartsTape : Tape := .inr .darts def emitTape : Tape := .inr .emit def outputTape : Tape := .inr .output def memory (inner : MachineCloudPrefix.Tape → List Bool)
(m index work scratch vertices darts emit output : List Bool) : Tape → List Bool body · 9 lines
| .inl k => inner k
| .inr .m => m
| .inr .index => index
| .inr .work => work
| .inr .scratch => scratch
| .inr .vertices => vertices
| .inr .darts => darts
| .inr .emit => emit
| .inr .output => outputdef frame (t n v f s m i w a N R e o : List Bool) : Tape → List Bool := body · 1 line
memory (MachineCloudPrefix.frame t v [] [] [] n f s) m i w a N R e o@[simp] theorem frame_table (t n v f s m i w a N R e o : List Bool) :
frame t n v f s m i w a N R e o tableTape = t := rfl @[simp] theorem frame_n (t n v f s m i w a N R e o : List Bool) :
frame t n v f s m i w a N R e o nTape = n := rfl @[simp] theorem frame_query (t n v f s m i w a N R e o : List Bool) :
frame t n v f s m i w a N R e o queryTape = v := rfl @[simp] theorem frame_fuel (t n v f s m i w a N R e o : List Bool) :
frame t n v f s m i w a N R e o fuelTape = f := rfl @[simp] theorem frame_sum (t n v f s m i w a N R e o : List Bool) :
frame t n v f s m i w a N R e o sumTape = s := rfl @[simp] theorem frame_m (t n v f s m i w a N R e o : List Bool) :
frame t n v f s m i w a N R e o mTape = m := rfl @[simp] theorem frame_index (t n v f s m i w a N R e o : List Bool) :
frame t n v f s m i w a N R e o indexTape = i := rfl @[simp] theorem frame_work (t n v f s m i w a N R e o : List Bool) :
frame t n v f s m i w a N R e o workTape = w := rfl @[simp] theorem frame_scratch (t n v f s m i w a N R e o : List Bool) :
frame t n v f s m i w a N R e o scratchTape = a := rfl @[simp] theorem frame_vertices (t n v f s m i w a N R e o : List Bool) :
frame t n v f s m i w a N R e o verticesTape = N := rfl @[simp] theorem frame_darts (t n v f s m i w a N R e o : List Bool) :
frame t n v f s m i w a N R e o dartsTape = R := rfl @[simp] theorem frame_emit (t n v f s m i w a N R e o : List Bool) :
frame t n v f s m i w a N R e o emitTape = e := rfl @[simp] theorem frame_output (t n v f s m i w a N R e o : List Bool) :
frame t n v f s m i w a N R e o outputTape = o := rfl @[simp] theorem update_frame_table (t n v f s m i w a N R e o x : List Bool) :
Function.update (frame t n v f s m i w a N R e o) tableTape x =
frame x n v f s m i w a N R e o := by proof · 9 lines
funext k
cases k with
| inl k =>
cases k with
| inner j => cases j <;> rfl
| bound => rfl
| remaining => rfl
| total => rfl
| inr j => cases j <;> rfl@[simp] theorem update_frame_n (t n v f s m i w a N R e o x : List Bool) :
Function.update (frame t n v f s m i w a N R e o) nTape x =
frame t x v f s m i w a N R e o := by proof · 9 lines
funext k
cases k with
| inl k =>
cases k with
| inner j => cases j <;> rfl
| bound => rfl
| remaining => rfl
| total => rfl
| inr j => cases j <;> rfl@[simp] theorem update_frame_query (t n v f s m i w a N R e o x : List Bool) :
Function.update (frame t n v f s m i w a N R e o) queryTape x =
frame t n x f s m i w a N R e o := by proof · 9 lines
funext k
cases k with
| inl k =>
cases k with
| inner j => cases j <;> rfl
| bound => rfl
| remaining => rfl
| total => rfl
| inr j => cases j <;> rfl@[simp] theorem update_frame_fuel (t n v f s m i w a N R e o x : List Bool) :
Function.update (frame t n v f s m i w a N R e o) fuelTape x =
frame t n v x s m i w a N R e o := by proof · 9 lines
funext k
cases k with
| inl k =>
cases k with
| inner j => cases j <;> rfl
| bound => rfl
| remaining => rfl
| total => rfl
| inr j => cases j <;> rfl@[simp] theorem update_frame_sum (t n v f s m i w a N R e o x : List Bool) :
Function.update (frame t n v f s m i w a N R e o) sumTape x =
frame t n v f x m i w a N R e o := by proof · 9 lines
funext k
cases k with
| inl k =>
cases k with
| inner j => cases j <;> rfl
| bound => rfl
| remaining => rfl
| total => rfl
| inr j => cases j <;> rfl@[simp] theorem update_frame_m (t n v f s m i w a N R e o x : List Bool) :
Function.update (frame t n v f s m i w a N R e o) mTape x =
frame t n v f s x i w a N R e o := by proof · 9 lines
funext k
cases k with
| inl k =>
cases k with
| inner j => cases j <;> rfl
| bound => rfl
| remaining => rfl
| total => rfl
| inr j => cases j <;> rfl@[simp] theorem update_frame_index (t n v f s m i w a N R e o x : List Bool) :
Function.update (frame t n v f s m i w a N R e o) indexTape x =
frame t n v f s m x w a N R e o := by proof · 9 lines
funext k
cases k with
| inl k =>
cases k with
| inner j => cases j <;> rfl
| bound => rfl
| remaining => rfl
| total => rfl
| inr j => cases j <;> rfl@[simp] theorem update_frame_work (t n v f s m i w a N R e o x : List Bool) :
Function.update (frame t n v f s m i w a N R e o) workTape x =
frame t n v f s m i x a N R e o := by proof · 9 lines
funext k
cases k with
| inl k =>
cases k with
| inner j => cases j <;> rfl
| bound => rfl
| remaining => rfl
| total => rfl
| inr j => cases j <;> rfl@[simp] theorem update_frame_scratch (t n v f s m i w a N R e o x : List Bool) :
Function.update (frame t n v f s m i w a N R e o) scratchTape x =
frame t n v f s m i w x N R e o := by proof · 9 lines
funext k
cases k with
| inl k =>
cases k with
| inner j => cases j <;> rfl
| bound => rfl
| remaining => rfl
| total => rfl
| inr j => cases j <;> rfl@[simp] theorem update_frame_vertices (t n v f s m i w a N R e o x : List Bool) :
Function.update (frame t n v f s m i w a N R e o) verticesTape x =
frame t n v f s m i w a x R e o := by proof · 9 lines
funext k
cases k with
| inl k =>
cases k with
| inner j => cases j <;> rfl
| bound => rfl
| remaining => rfl
| total => rfl
| inr j => cases j <;> rfl@[simp] theorem update_frame_darts (t n v f s m i w a N R e o x : List Bool) :
Function.update (frame t n v f s m i w a N R e o) dartsTape x =
frame t n v f s m i w a N x e o := by proof · 9 lines
funext k
cases k with
| inl k =>
cases k with
| inner j => cases j <;> rfl
| bound => rfl
| remaining => rfl
| total => rfl
| inr j => cases j <;> rfl@[simp] theorem update_frame_emit (t n v f s m i w a N R e o x : List Bool) :
Function.update (frame t n v f s m i w a N R e o) emitTape x =
frame t n v f s m i w a N R x o := by proof · 9 lines
funext k
cases k with
| inl k =>
cases k with
| inner j => cases j <;> rfl
| bound => rfl
| remaining => rfl
| total => rfl
| inr j => cases j <;> rfl@[simp] theorem update_frame_output (t n v f s m i w a N R e o x : List Bool) :
Function.update (frame t n v f s m i w a N R e o) outputTape x =
frame t n v f s m i w a N R e x := by proof · 9 lines
funext k
cases k with
| inl k =>
cases k with
| inner j => cases j <;> rfl
| bound => rfl
| remaining => rfl
| total => rfl
| inr j => cases j <;> rflinductive Field body · 2 lines
| vertices | darts
deriving DecidableEqinstance : Fintype Field where body · 2 lines
elems := {.vertices, .darts}
complete value := by cases value <;> simpinductive CopyPhase body · 2 lines
| count | rEmit | nEmit
deriving DecidableEqinstance : Fintype CopyPhase where body · 2 lines
elems := {.count, .rEmit, .nEmit}
complete value := by cases value <;> simpinductive Label body · 8 lines
| init | seedM | clearIndex
| lookup (field : Field) (label : MachinePreservingLookupClean.Label)
| prefix (label : MachineCloudPrefix.Label)
| copyFirst (phase : CopyPhase) | copySecond (phase : CopyPhase)
| add | scaleSeed | scaleScan | scaleRestore
| appendFirst | appendSecond | appendThird
| cleanupZeros | clearQuery | done
deriving DecidableEq, Fintypedef fieldTape : Field → Tape body · 2 lines
| .vertices => nTape
| .darts => mTapedef fieldExit : Field → Label body · 2 lines
| .vertices => .seedM
| .darts => .clearIndexdef lookupSlots (field : Field) : Fin 5 → Tape := body · 1 line
![tableTape, indexTape, workTape, fieldTape field, scratchTape]
theorem lookupSlots_injective (field : Field) : Function.Injective (lookupSlots field) := by proof · 3 lines
intro i j h
cases field <;> fin_cases i <;> fin_cases j <;>
simp_all [lookupSlots, fieldTape, tableTape, indexTape, workTape, nTape, mTape, scratchTape]def copySource : CopyPhase → Tape body · 3 lines
| .count => mTape
| .rEmit => dartsTape
| .nEmit => verticesTapedef copyDestination : CopyPhase → Tape body · 2 lines
| .count => verticesTape
| .rEmit | .nEmit => emitTapedef copyExit : CopyPhase → Label body · 3 lines
| .count => .add
| .rEmit => .copyFirst .nEmit
| .nEmit => .appendFirstdef prefixView : Tape → Option MachineCloudPrefix.Tape body · 2 lines
| .inl k => some k
| .inr _ => nonetheorem prefixView_left (k : MachineCloudPrefix.Tape) : prefixView (.inl k) = some k := rfl theorem prefixView_right (j : Tape) (k : MachineCloudPrefix.Tape)
(h : prefixView j = some k) : Sum.inl k = j := by proof · 1 line
cases j <;> simp_all [prefixView]
theorem prefixTapes (inner : MachineCloudPrefix.Tape → List Bool) (extra : Tape → List Bool) :
MachineCloudPadding.Placement.tapes prefixView inner extra =
memory inner (extra mTape) (extra indexTape) (extra workTape) (extra scratchTape)
(extra verticesTape) (extra dartsTape) (extra emitTape) (extra outputTape) := by proof · 4 lines
funext j
cases j with
| inl k => rfl
| inr k => cases k <;> rfldef program (q : Nat) : Label → TM2.Stmt Alphabet Label (State σ) body · 28 lines
| .init => .push indexTape (fun _ => false) (.goto fun _ => .lookup .vertices (.run .copyFirst))
| .seedM => .push indexTape (fun _ => true) (.goto fun _ => .lookup .darts (.run .copyFirst))
| .clearIndex => .pop indexTape (fun state _ => (state.1, none))
(.goto fun _ => .prefix .init)
| .lookup field l => MachinePreservingLookupClean.statement (lookupSlots field)
(Label.lookup field) (some (fieldExit field)) l
| .prefix l => MachineCloudPadding.Placement.statement Sum.inl Label.prefix
(some (.copyFirst .count)) (MachineCloudPrefix.program l)
| .copyFirst phase => Reduction.MachineTransfer.loopAt (copySource phase) scratchTape
id false (.copyFirst phase) (some (.copySecond phase))
| .copySecond phase => MachineCopy.forkLoop scratchTape (copySource phase) (copyDestination phase)
false (.copySecond phase) (some (copyExit phase))
| .add => MachineUnaryAddAt.loop sumTape verticesTape .add (some .scaleSeed)
| .scaleSeed => MachineUnaryAffineAt.seed dartsTape 0 .scaleScan
| .scaleScan => MachineUnaryAffineAt.scan verticesTape scratchTape dartsTape (q + 1)
.scaleScan .scaleRestore
| .scaleRestore => Reduction.MachineTransfer.loopAt scratchTape verticesTape id false
.scaleRestore (some (.copyFirst .rEmit))
| .appendFirst => Reduction.MachineTransfer.loopAt outputTape scratchTape id false
.appendFirst (some .appendSecond)
| .appendSecond => Reduction.MachineTransfer.loopAt emitTape scratchTape id false
.appendSecond (some .appendThird)
| .appendThird => Reduction.MachineTransfer.loopAt scratchTape outputTape id false
.appendThird (some .cleanupZeros)
| .cleanupZeros => .pop sumTape (fun state _ => (state.1, none))
(.pop fuelTape (fun state _ => (state.1, none)) (.goto fun _ => .clearQuery))
| .clearQuery => MachineLookup.discard queryTape .clearQuery .done
| .done => .halttheorem appendTrace {α : Type} (f : α → α) {a b : Nat} {x y z : α}
(hs : f^[a] x = y) (ht : f^[b] y = z) : f^[a + b] x = z := by proof · 1 line
rw [Nat.add_comm a b, Function.iterate_add_apply, hs, ht]def paddingTotal (t : GraphTables.Table) : Nat := body · 1 line
PreprocessingPaddingOffsets.offset (PreprocessingRegularTables.padding t) t.verticesdef vertexTotal (t : GraphTables.Table) : Nat := body · 1 line
PreprocessingRegularTables.vertexCount t (PreprocessingRegularTables.padding t)def dartTotal (q : Nat) (t : GraphTables.Table) : Nat := vertexTotal t * (q + 1) theorem vertexTotal_eq (t : GraphTables.Table) :
vertexTotal t = t.darts + paddingTotal t := by proof · 2 lines
unfold vertexTotal PreprocessingRegularTables.vertexCount paddingTotal
rw [PreprocessingPaddingOffsets.offset_all]theorem initStep (q : Nat) (table output : List Bool) (ambient : σ)
(register : Option Bool) :
TM2.step (program q)
⟨some .init, ((ambient, false), register),
frame table [] [] [] [] [] [] [] [] [] [] [] output⟩ =
some ⟨some (.lookup .vertices (.run .copyFirst)), ((ambient, false), register),
frame table [] [] [] [] [] (encodeWord 0) [] [] [] [] [] output⟩ := by proof · 1 line
simp [TM2.step, program, TM2.stepAux, encodeWord]theorem seedMStep (q : Nat) (table n output : List Bool) (ambient : σ)
(register : Option Bool) :
TM2.step (program q)
⟨some .seedM, ((ambient, false), register),
frame table n [] [] [] [] (encodeWord 0) [] [] [] [] [] output⟩ =
some ⟨some (.lookup .darts (.run .copyFirst)), ((ambient, false), register),
frame table n [] [] [] [] (encodeWord 1) [] [] [] [] [] output⟩ := by proof · 1 line
simp [TM2.step, program, TM2.stepAux, encodeWord]theorem clearIndexStep (q : Nat) (table n m output : List Bool) (ambient : σ)
(register : Option Bool) :
TM2.step (program q)
⟨some .clearIndex, ((ambient, false), register),
frame table n [] [] [] m (encodeWord 0) [] [] [] [] [] output⟩ =
some ⟨some (.prefix .init), ((ambient, false), none),
frame table n [] [] [] m [] [] [] [] [] [] output⟩ := by proof · 1 line
simp [TM2.step, program, TM2.stepAux, encodeWord]def readTime (t : GraphTables.Table) : Nat := body · 2 lines
1 + MachinePreservingLookupClean.steps (GraphTables.tableWords t) 0 + 1 +
MachinePreservingLookupClean.steps (GraphTables.tableWords t) 1 + 1theorem readTrace (q : Nat) (t : GraphTables.Table) (output : List Bool)
(ambient : σ) (register : Option Bool) :
(advance (TM2.step (program q)))^[readTime t]
(some ⟨some .init, ((ambient, false), register),
frame (GraphTables.tableBits t) [] [] [] [] [] [] [] [] [] [] [] output⟩) =
some ⟨some (.prefix .init), ((ambient, false), none),
frame (GraphTables.tableBits t) (encodeWord t.vertices) [] [] []
(encodeWord t.darts) [] [] [] [] [] [] output⟩ := by proof · 38 lines
have hi : (advance (TM2.step (program q)))^[1]
(some ⟨some .init, ((ambient, false), register),
frame (GraphTables.tableBits t) [] [] [] [] [] [] [] [] [] [] [] output⟩) =
some ⟨some (.lookup .vertices (.run .copyFirst)), ((ambient, false), register),
frame (GraphTables.tableBits t) [] [] [] [] [] (encodeWord 0) [] [] [] [] [] output⟩ :=
initStep q _ _ ambient register
have hn := MachinePreservingLookupClean.traceAt_fromTapes (lookupSlots .vertices)
(lookupSlots_injective .vertices) (Label.lookup .vertices) (some Label.seedM)
(program q) (fun _ => rfl)
(frame (GraphTables.tableBits t) [] [] [] [] [] (encodeWord 0) [] [] [] [] [] output)
(GraphTables.tableWords t) rfl rfl 0 t.vertices (by simp [GraphTables.tableWords]) []
(by simp [lookupSlots]) (by simp [lookupSlots]) (ambient, false) register
simp [MachinePreservingLookup.initialTapes, MachineLookup.tapes, lookupSlots, fieldTape] at hn
have hs : (advance (TM2.step (program q)))^[1]
(some ⟨some .seedM, ((ambient, false), none),
frame (GraphTables.tableBits t) (encodeWord t.vertices) [] [] [] []
(encodeWord 0) [] [] [] [] [] output⟩) =
some ⟨some (.lookup .darts (.run .copyFirst)), ((ambient, false), none),
frame (GraphTables.tableBits t) (encodeWord t.vertices) [] [] [] []
(encodeWord 1) [] [] [] [] [] output⟩ :=
seedMStep q _ _ _ ambient none
have hm := MachinePreservingLookupClean.traceAt_fromTapes (lookupSlots .darts)
(lookupSlots_injective .darts) (Label.lookup .darts) (some Label.clearIndex)
(program q) (fun _ => rfl)
(frame (GraphTables.tableBits t) (encodeWord t.vertices) [] [] [] []
(encodeWord 1) [] [] [] [] [] output)
(GraphTables.tableWords t) rfl rfl 1 t.darts (by simp [GraphTables.tableWords]) []
(by simp [lookupSlots]) (by simp [lookupSlots]) (ambient, false) none
simp [MachinePreservingLookup.initialTapes, MachineLookup.tapes, lookupSlots, fieldTape] at hm
have hc : (advance (TM2.step (program q)))^[1]
(some ⟨some .clearIndex, ((ambient, false), none),
frame (GraphTables.tableBits t) (encodeWord t.vertices) [] [] []
(encodeWord t.darts) (encodeWord 0) [] [] [] [] [] output⟩) =
some ⟨some (.prefix .init), ((ambient, false), none),
frame (GraphTables.tableBits t) (encodeWord t.vertices) [] [] []
(encodeWord t.darts) [] [] [] [] [] [] output⟩ :=
clearIndexStep q _ _ _ _ ambient none
exact appendTrace _ (appendTrace _ (appendTrace _ (appendTrace _ hi hn) hs) hm) hcOutline
- inductive
Extra15 - instance
19 - abbrev
Tape23 - abbrev
Alphabet24 - abbrev
State25 - def
tableTape27 - def
nTape28 - def
queryTape29 - def
fuelTape30 - def
sumTape31 - def
mTape32 - def
indexTape33 - def
workTape34 - def
scratchTape35 - def
verticesTape36 - def
dartsTape37 - def
emitTape38 - def
outputTape39 - def
memory41 - def
frame53 - theorem
frame_table56 - theorem
frame_n58 - theorem
frame_query60 - theorem
frame_fuel62 - theorem
frame_sum64 - theorem
frame_m66 - theorem
frame_index68 - theorem
frame_work70 - theorem
frame_scratch72 - theorem
frame_vertices74 - theorem
frame_darts76 - theorem
frame_emit78 - theorem
frame_output80 - theorem
update_frame_table83 - theorem
update_frame_n96 - theorem
update_frame_query109 - theorem
update_frame_fuel122 - theorem
update_frame_sum135 - theorem
update_frame_m148 - theorem
update_frame_index161 - theorem
update_frame_work174 - theorem
update_frame_scratch187 - theorem
update_frame_vertices200 - theorem
update_frame_darts213 - theorem
update_frame_emit226 - theorem
update_frame_output239 - inductive
Field252 - instance
256 - inductive
CopyPhase260 - instance
264 - inductive
Label268 - def
fieldTape278 - def
fieldExit282 - def
lookupSlots286 - theorem
lookupSlots_injective289 - def
copySource294 - def
copyDestination299 - def
copyExit303 - def
prefixView308 - theorem
prefixView_left312 - theorem
prefixView_right314 - theorem
prefixTapes318 - def
program329 - theorem
appendTrace359 - def
paddingTotal363 - def
vertexTotal366 - def
dartTotal369 - theorem
vertexTotal_eq371 - theorem
initStep376 - theorem
seedMStep385 - theorem
clearIndexStep394 - def
readTime403 - theorem
readTrace407