Download data/lean/OAI/Computability/Interspersed/Machines.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 2.34 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/Interspersed/Machines.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/Interspersed/Machines.lean
-
curl -L -o Machines.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/Interspersed/Machines.lean
2.34 kB
| import Mathlib | |
| namespace OAI | |
| /-! Finite transition tables and two-sided machine executions. -/ | |
| noncomputable section | |
| open scoped ContDiff | |
| namespace PrefixFlows | |
| inductive Move where | |
| | stay | right | left | |
| deriving DecidableEq, Repr | |
| def Move.displacement : Move β β€ | |
| | .stay => 0 | |
| | .right => 1 | |
| | .left => -1 | |
| def Move.code : Move β β | |
| | .stay => 0 | |
| | .right => 1 | |
| | .left => 2 | |
| structure Instruction where | |
| nextState : β | |
| writeSymbol : β | |
| motion : Move | |
| deriving DecidableEq, Repr | |
| structure Machine where | |
| alphabetSize : β | |
| blank : β | |
| initialState : β | |
| haltStates : List β | |
| table : List (List (Option Instruction)) | |
| deriving DecidableEq, Repr | |
| namespace Machine | |
| def WellFormed (M : Machine) : Prop := | |
| 0 < M.alphabetSize β§ M.blank < M.alphabetSize β§ | |
| M.initialState < M.table.length β§ | |
| (β q β M.haltStates, q < M.table.length) β§ | |
| (β row β M.table, row.length = M.alphabetSize β§ | |
| β instruction β row, β a, instruction = some a β | |
| a.nextState < M.table.length β§ a.writeSymbol < M.alphabetSize) | |
| def ValidInput (M : Machine) (w : List β) : Prop := | |
| β a β w, a < M.alphabetSize | |
| def code (M : Machine) : β := | |
| Encodable.encode (M.alphabetSize, M.blank, M.initialState, M.haltStates, | |
| M.table.map (List.map (Option.map fun a => | |
| (a.nextState, a.writeSymbol, a.motion.code)))) | |
| def instruction (M : Machine) (q a : β) : Option Instruction := | |
| (M.table[q]?).bind fun row => (row[a]?).join | |
| structure Configuration where | |
| state : β | |
| head : β€ | |
| tape : β€ β β | |
| def initial (M : Machine) (w : List β) : Configuration where | |
| state := M.initialState | |
| head := 0 | |
| tape := fun j => if 0 β€ j then (w[j.toNat]?).getD M.blank else M.blank | |
| def step (M : Machine) (c : Configuration) : Option Configuration := | |
| if c.state β M.haltStates then none else | |
| (M.instruction c.state (c.tape c.head)).map fun a => | |
| { state := a.nextState | |
| head := c.head + a.motion.displacement | |
| tape := Function.update c.tape c.head a.writeSymbol } | |
| def run (M : Machine) (w : List β) : β β Option Configuration | |
| | 0 => some (M.initial w) | |
| | n + 1 => (M.run w n).bind M.step | |
| def Halts (M : Machine) (w : List β) : Prop := | |
| β n c, M.run w n = some c β§ M.step c = none | |
| end Machine | |
| end PrefixFlows | |
| end | |
| end OAI | |