{"repo":"pvsnp","commit":{"oid":"3fc07c697bd3c08bd25c3bfbd35fedc0aa5234d1","tree":"07c806410f160cc23db3b3064d5054b665de22d7","parents":["4186ab2739015c0efa3783c76b4987259c8e34b7"],"author":{"name":"Claude","email":"noreply@anthropic.com","time_ms":1795945215000},"committer":{"name":"Claude","email":"noreply@anthropic.com","time_ms":1795945215000},"subject":"Add concrete one-step machines for first-symbol languages","message":"Add concrete one-step machines for first-symbol languages\n\nfirstSymbolMachine reads tape 0 once and halts, accepting when a test\non the first symbol passes, so every language decided by its first\nsymbol is in P. Instances over Bool: words starting with true, the empty\nword, and (by closure under complement) the non-empty words. An example\nruns the machine on [true, false] and checks that it accepts.\n\nCo-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>\n"},"diff":{"base":"4186ab2739015c0efa3783c76b4987259c8e34b7","head":"3fc07c697bd3c08bd25c3bfbd35fedc0aa5234d1","stat":{"files":2,"additions":81,"deletions":0},"files":[{"path":"PvsNP.lean","status":"modified","additions":1,"deletions":0,"binary":false,"patch":"--- a/PvsNP.lean\n+++ b/PvsNP.lean\n@@ -11,6 +11,7 @@\n import PvsNP.Complexity.NP\n import PvsNP.Complexity.Completeness\n import PvsNP.Open\n+import PvsNP.Examples.FirstSymbol\n \n /-! # P versus NP in Lean 4\n \n","truncated":false},{"path":"PvsNP/Examples/FirstSymbol.lean","status":"added","additions":80,"deletions":0,"binary":false,"patch":"--- /dev/null\n+++ b/PvsNP/Examples/FirstSymbol.lean\n@@ -0,0 +1,80 @@\n+import PvsNP.Complexity.P\n+\n+/-!\n+# Example: languages decided by the first symbol\n+\n+A concrete machine, not a construction from other machines: it reads the cell under the head of tape\n+`0` once and halts, accepting when a test `p` on that symbol passes. It decides\n+`{x | p x.head? = true}` in one step, so each such language is in P.\n+\n+Two instances over `Bool`: the words that start with `true`, and the empty word.\n+-/\n+\n+namespace PvsNP.Examples\n+\n+variable {α : Type}\n+\n+/-- The machine's three states. -/\n+inductive FirstSymbolState where\n+  | start\n+  | accept\n+  | reject\n+  deriving DecidableEq, Repr\n+\n+instance : IsFinite FirstSymbolState :=\n+  ⟨⟨[.start, .accept, .reject], by intro a; cases a <;> simp⟩⟩\n+\n+/-- The language of words whose first symbol (`none` for the empty word) passes `p`. -/\n+def FirstSymbol (p : Option α → Bool) : Language α := fun x => p x.head? = true\n+\n+/-- Read tape `0` once; accept if `p` holds of what is there. One step, one tape. -/\n+def firstSymbolMachine (p : Option α → Bool) : Machine α 0 where\n+  Q := FirstSymbolState\n+  finite := inferInstance\n+  start := .start\n+  halted\n+    | .start => false\n+    | _ => true\n+  accepting\n+    | .accept => true\n+    | _ => false\n+  δ _ r := (if p (r 0) then .accept else .reject, r, fun _ => .stay)\n+\n+/-- After one step the machine has halted, in `accept` exactly when `p` holds of the first symbol. -/\n+theorem firstSymbolMachine_run (p : Option α → Bool) (x : List α) :\n+    ((firstSymbolMachine p).run ((firstSymbolMachine p).init (inputTapes x)) 1).state =\n+      if p x.head? then .accept else .reject := by\n+  simp [Machine.run, Machine.step, Machine.init, firstSymbolMachine, Machine.reads, inputTapes,\n+    Tape.read_ofWord]\n+\n+/-- Every language decided by the first symbol is in P, within one step. -/\n+theorem firstSymbol_inP (p : Option α → Bool) : InP (FirstSymbol p) := by\n+  refine ⟨0, firstSymbolMachine p, fun _ => 1, PolyBounded.const 1, fun x => ?_⟩\n+  rw [firstSymbolMachine_run]\n+  cases h : p x.head? <;> simp [firstSymbolMachine, FirstSymbol, h]\n+\n+/-- Words over `Bool` that start with `true`. -/\n+def StartsWithTrue : Language Bool := FirstSymbol (· == some true)\n+\n+theorem startsWithTrue_iff (x : List Bool) : StartsWithTrue x ↔ x.head? = some true := by\n+  simp [StartsWithTrue, FirstSymbol]\n+\n+theorem startsWithTrue_inP : InP StartsWithTrue := firstSymbol_inP _\n+\n+/-- The language holding only the empty word. -/\n+def EmptyWord : Language Bool := FirstSymbol Option.isNone\n+\n+theorem emptyWord_iff (x : List Bool) : EmptyWord x ↔ x = [] := by\n+  cases x <;> simp [EmptyWord, FirstSymbol]\n+\n+theorem emptyWord_inP : InP EmptyWord := firstSymbol_inP _\n+\n+/-- Its complement, the non-empty words, is in P too, by closure under complement. -/\n+theorem nonEmpty_inP : InP EmptyWord.compl := emptyWord_inP.compl\n+\n+/-- The machine run in the kernel: on `[true, false]` it accepts after one step. -/\n+example : ((firstSymbolMachine (· == some true)).run\n+    ((firstSymbolMachine (· == some true)).init (inputTapes [true, false])) 1).state = .accept := by\n+  rw [firstSymbolMachine_run]; rfl\n+\n+end PvsNP.Examples\n","truncated":false}],"truncated":false},"jit":null,"api":"/v1/repos/pvsnp/commit?rev=3fc07c697bd3c08bd25c3bfbd35fedc0aa5234d1","api_url":"https://git.neoopensource.com/v1/repos/pvsnp/commit?rev=3fc07c697bd3c08bd25c3bfbd35fedc0aa5234d1"}