changes / #1 2223d32c5d1661da557e69b56124a9a1
Examples: concrete one-step machines for first-symbol languages
openjp_ee76fd26… →
mainrev 2+163 -356d agoCopy for your agent
Needs attention
auto-land refusedthe reasons are under Landing, below
Roadmap milestone 2. Adds `PvsNP/Examples/FirstSymbol.lean`: a three-state, one-tape machine that reads the cell under the head once and halts, accepting when a test `p` on that symbol passes. Proved: it decides `{x | p x.head? = true}` in one step, so every such language is in P (`Examples.firstSymbol_inP`). Instances over `Bool`: words starting with `true`, the empty word, and the non-empty words (via closure under complement). An `example` runs the machine on `[true, false]` and checks it accepts. Also: the theorem joins the axiom audit, and README/ROADMAP mark the milestone done. Checked: `lake build` passes on the head (library + axiom audit); no `sorry`; `firstSymbol_inP` depends only on `propext`, `Classical.choice`, `Quot.sound`.
Landing
auto-land refusedby rule
examples-first-symbolrev 26d agothis change was opened without a branch; the rule takes only changes pushed from examples/first-symbol
Landing rules
examples-first-symbolrefused: the reasons are under Landing, abovelake-build passedlands by itselfmodified
Audit/Axioms.leanmodified PvsNP.leanmodified PvsNP/Complexity/NP.leanmodified PvsNP/Complexity/P.leanmodified PvsNP/Complexity/Reduction.leanadded PvsNP/Examples/FirstSymbol.leanmodified PvsNP/Machine/Defs.leanmodified PvsNP/Machine/Lift.leanmodified README.mdmodified ROADMAP.mdreported by jp_72b535ee9c73365d4010be4167c0754535b843c26c52baa6b06489303691f0c7GET https://git.neoopensource.com/v1/repos/pvsnp/landing-rulesChecks
passedindependent-reviewrev 2Codex gpt-6.2-astra, 2 rounds: 1 HIGH fixed, 1 HIGH refuted, 2 MEDIUM fixed; approve
passedlake-buildrev 2exit 0 in 6.4 s
Reviews
No reviews yet.
Revisions (2)
Diff · rev 2
10 files changed +163 -35
| @@ -63,3 +63,9 @@ | ||
| 63 | 63 | /-- info: 'PvsNP.Machine.run_seq' depends on axioms: [propext, Quot.sound] -/ |
| 64 | 64 | #guard_msgs in |
| 65 | 65 | #print axioms PvsNP.Machine.run_seq |
| 66 | + | |
| 67 | +/-- | |
| 68 | +info: 'PvsNP.Examples.firstSymbol_inP' depends on axioms: [propext, Classical.choice, Quot.sound] | |
| 69 | +-/ | |
| 70 | +#guard_msgs in | |
| 71 | +#print axioms PvsNP.Examples.firstSymbol_inP | |
| @@ -3,12 +3,17 @@ | ||
| 3 | 3 | /-! |
| 4 | 4 | # The class NP |
| 5 | 5 | |
| 6 | -`InNP L`: some machine verifies `L` in polynomial time. The input `x` is on tape `0` and a certificate | |
| 6 | +`InNP L`: the alphabet is finite and some machine verifies `L` in polynomial time. The input `x` is on tape `0` and a certificate | |
| 7 | 7 | `w` on tape `1`; the verifier halts within `T |x|` steps whatever the certificate, and `x ∈ L` exactly |
| 8 | 8 | when some certificate makes it accept. Because the time bound depends on `|x|` alone, only the first |
| 9 | 9 | `T |x|` symbols of a certificate can matter, so certificates are polynomially short in effect |
| 10 | 10 | (Sipser, *Introduction to the Theory of Computation*, Definition 7.18). |
| 11 | 11 | |
| 12 | +Certificates are written over the input alphabet. For finite alphabets with at least two symbols this | |
| 13 | +is the usual NP. Over a one-symbol alphabet a certificate carries only its length: certificates are | |
| 14 | +unary rather than binary, so `InNP` there uses a different certificate model from the usual one for | |
| 15 | +unary languages. The open problem is stated over `Bool`. | |
| 16 | + | |
| 12 | 17 | Proved here: |
| 13 | 18 | - `InP.inNP`: **P ⊆ NP**. A decider, run with tape `1` left alone, is a verifier that ignores its |
| 14 | 19 | certificate. |
| @@ -22,27 +27,27 @@ | ||
| 22 | 27 | |
| 23 | 28 | /-- `L ∈ NP`: a machine verifies `L` in polynomial time. -/ |
| 24 | 29 | def InNP (L : Language α) : Prop := |
| 25 | - ∃ (k : Nat) (M : Machine α k) (T : Nat → Nat), PolyBounded T ∧ VerifiesIn M L T | |
| 30 | + IsFinite α ∧ ∃ (k : Nat) (M : Machine α k) (T : Nat → Nat), PolyBounded T ∧ VerifiesIn M L T | |
| 26 | 31 | |
| 27 | 32 | namespace InNP |
| 28 | 33 | |
| 29 | 34 | /-- The time bound of a verifier can be taken of the form `c * (n + 1) ^ d`, hence monotone. -/ |
| 30 | 35 | theorem polyBound {L : Language α} (h : InNP L) : |
| 31 | 36 | ∃ (k : Nat) (M : Machine α k) (c d : Nat), VerifiesIn M L (PvsNP.polyBound c d) := by |
| 32 | - obtain ⟨k, M, T, ⟨c, d, hT⟩, hM⟩ := h | |
| 37 | + obtain ⟨_, k, M, T, ⟨c, d, hT⟩, hM⟩ := h | |
| 33 | 38 | exact ⟨k, M, c, d, hM.mono hT⟩ |
| 34 | 39 | |
| 35 | 40 | end InNP |
| 36 | 41 | |
| 37 | 42 | /-- **P ⊆ NP.** -/ |
| 38 | 43 | theorem InP.inNP {L : Language α} (h : InP L) : InNP L := by |
| 39 | - obtain ⟨k, M, T, hT, hM⟩ := h | |
| 44 | + obtain ⟨hα, k, M, T, hT, hM⟩ := h | |
| 40 | 45 | let E := Embedding.skipOne (Nat.le_refl (k + 1)) |
| 41 | 46 | have e : ∀ x w, (M.lift E).init (verifierTapes x w) = |
| 42 | 47 | M.liftCfg E (verifierTapes x w) (M.init (inputTapes x)) := by |
| 43 | 48 | intro x w |
| 44 | 49 | simp only [Machine.init, Machine.liftCfg, E, liftTapes_skipOne_inputTapes]; rfl |
| 45 | - refine ⟨k + 1, M.lift E, T, hT, fun x w => ?_, fun x => ?_⟩ | |
| 50 | + refine ⟨hα, k + 1, M.lift E, T, hT, fun x w => ?_, fun x => ?_⟩ | |
| 46 | 51 | · rw [e, Machine.run_lift]; exact (hM x).1 |
| 47 | 52 | · simp only [e, Machine.run_lift] |
| 48 | 53 | exact ⟨fun hx => ⟨[], (hM x).2.mpr hx⟩, fun ⟨_, hw⟩ => (hM x).2.mp hw⟩ |
| @@ -93,7 +98,7 @@ | ||
| 93 | 98 | (PvsNP.polyBound c₂ d₂ (f x).length)) := fun x w => |
| 94 | 99 | Machine.run_seq_verifier M₁ hk₁ V' hM₁ x w _ _ (hV'.1 (f x) w) |
| 95 | 100 | (Nat.add_le_add_left (polyBound.mono c₂ d₂ (hB x)) _) |
| 96 | - refine ⟨k₁ + k₂ + 1, (M₁.lift (Embedding.skipOne hk₁)).seq V', T, ?_, fun x w => ?_, fun x => ?_⟩ | |
| 101 | + refine ⟨hf.1, k₁ + k₂ + 1, (M₁.lift (Embedding.skipOne hk₁)).seq V', T, ?_, fun x w => ?_, fun x => ?_⟩ | |
| 97 | 102 | · exact ((PolyBounded.polyBound c₁ d₁).add (PolyBounded.const 1)).add |
| 98 | 103 | ((PolyBounded.polyBound c₂ d₂).comp (PolyBounded.polyBound b e)) |
| 99 | 104 | · rw [key]; exact hV'.1 (f x) w |
| @@ -4,7 +4,10 @@ | ||
| 4 | 4 | /-! |
| 5 | 5 | # The class P |
| 6 | 6 | |
| 7 | -`InP L`: some multi-tape machine decides `L` within a polynomial number of steps. | |
| 7 | +`InP L`: the alphabet is finite and some multi-tape machine decides `L` within a polynomial number | |
| 8 | +of steps. Finiteness of the alphabet is part of the definition: over an infinite alphabet a single | |
| 9 | +symbol carries unbounded information (a machine reading one `Nat` could test membership in the | |
| 10 | +halting set), so P is empty there by definition rather than meaningless. | |
| 8 | 11 | |
| 9 | 12 | Proved here: the full and the empty language are in P, and P is closed under complement. |
| 10 | 13 | -/ |
| @@ -13,9 +16,9 @@ | ||
| 13 | 16 | |
| 14 | 17 | variable {α : Type} |
| 15 | 18 | |
| 16 | -/-- `L ∈ P`: a machine decides `L` in polynomial time. -/ | |
| 19 | +/-- `L ∈ P`: over a finite alphabet, a machine decides `L` in polynomial time. -/ | |
| 17 | 20 | def InP (L : Language α) : Prop := |
| 18 | - ∃ (k : Nat) (M : Machine α k) (T : Nat → Nat), PolyBounded T ∧ DecidesIn M L T | |
| 21 | + IsFinite α ∧ ∃ (k : Nat) (M : Machine α k) (T : Nat → Nat), PolyBounded T ∧ DecidesIn M L T | |
| 19 | 22 | |
| 20 | 23 | /-- A machine that halts at once, accepting or not as `b` says, touching nothing. -/ |
| 21 | 24 | def Machine.const (α : Type) (k : Nat) (b : Bool) : Machine α k where |
| @@ -31,21 +34,24 @@ | ||
| 31 | 34 | /-- The time bound of a language in P can be taken of the form `c * (n + 1) ^ d`, hence monotone. -/ |
| 32 | 35 | theorem polyBound {L : Language α} (h : InP L) : |
| 33 | 36 | ∃ (k : Nat) (M : Machine α k) (c d : Nat), DecidesIn M L (PvsNP.polyBound c d) := by |
| 34 | - obtain ⟨k, M, T, ⟨c, d, hT⟩, hM⟩ := h | |
| 37 | + obtain ⟨_, k, M, T, ⟨c, d, hT⟩, hM⟩ := h | |
| 35 | 38 | exact ⟨k, M, c, d, hM.mono hT⟩ |
| 36 | 39 | |
| 37 | -theorem univ : InP (Language.univ : Language α) := | |
| 38 | - ⟨0, Machine.const α 0 true, fun _ => 0, PolyBounded.const 0, fun _ => | |
| 40 | +/-- Only languages over finite alphabets are in P. -/ | |
| 41 | +theorem isFinite {L : Language α} (h : InP L) : IsFinite α := h.1 | |
| 42 | + | |
| 43 | +theorem univ [IsFinite α] : InP (Language.univ : Language α) := | |
| 44 | + ⟨inferInstance, 0, Machine.const α 0 true, fun _ => 0, PolyBounded.const 0, fun _ => | |
| 39 | 45 | ⟨rfl, by simp [Machine.const, Language.univ, Machine.init]⟩⟩ |
| 40 | 46 | |
| 41 | -theorem empty : InP (Language.empty : Language α) := | |
| 42 | - ⟨0, Machine.const α 0 false, fun _ => 0, PolyBounded.const 0, fun _ => | |
| 47 | +theorem empty [IsFinite α] : InP (Language.empty : Language α) := | |
| 48 | + ⟨inferInstance, 0, Machine.const α 0 false, fun _ => 0, PolyBounded.const 0, fun _ => | |
| 43 | 49 | ⟨rfl, by simp [Machine.const, Language.empty, Machine.init]⟩⟩ |
| 44 | 50 | |
| 45 | 51 | /-- **P is closed under complement**: swap accepting and rejecting halted states. -/ |
| 46 | 52 | theorem compl {L : Language α} (h : InP L) : InP L.compl := by |
| 47 | - obtain ⟨k, M, T, hT, hM⟩ := h | |
| 48 | - refine ⟨k, M.withAccepting (fun q => !M.accepting q), T, hT, fun x => ?_⟩ | |
| 53 | + obtain ⟨hα, k, M, T, hT, hM⟩ := h | |
| 54 | + refine ⟨hα, k, M.withAccepting (fun q => !M.accepting q), T, hT, fun x => ?_⟩ | |
| 49 | 55 | have e : (M.withAccepting (fun q => !M.accepting q)).init (inputTapes x) = M.init (inputTapes x) := |
| 50 | 56 | rfl |
| 51 | 57 | rw [e, Machine.run_withAccepting] |
| @@ -54,8 +60,8 @@ | ||
| 54 | 60 | ← (hM x).2, Bool.not_eq_true] |
| 55 | 61 | |
| 56 | 62 | theorem of_compl {L : Language α} (h : InP L.compl) : InP L := by |
| 57 | - obtain ⟨k, M, T, hT, hM⟩ := h.compl | |
| 58 | - exact ⟨k, M, T, hT, fun x => ⟨(hM x).1, by rw [(hM x).2, Language.compl_compl]⟩⟩ | |
| 63 | + obtain ⟨hα, k, M, T, hT, hM⟩ := h.compl | |
| 64 | + exact ⟨hα, k, M, T, hT, fun x => ⟨(hM x).1, by rw [(hM x).2, Language.compl_compl]⟩⟩ | |
| 59 | 65 | |
| 60 | 66 | theorem compl_iff {L : Language α} : InP L.compl ↔ InP L := ⟨of_compl, compl⟩ |
| 61 | 67 | |
| @@ -3,7 +3,7 @@ | ||
| 3 | 3 | /-! |
| 4 | 4 | # Polynomial-time reductions |
| 5 | 5 | |
| 6 | -`PolyTimeComputable f`: a machine computes `f` in polynomial time, and `|f x|` is polynomially bounded | |
| 6 | +`PolyTimeComputable f`: the alphabet is finite and a machine computes `f` in polynomial time, and `|f x|` is polynomially bounded | |
| 7 | 7 | in `|x|`. (The output bound follows from the time bound in any reasonable model; we state it rather |
| 8 | 8 | than derive it. Deriving it is on the roadmap.) |
| 9 | 9 | |
| @@ -19,7 +19,7 @@ | ||
| 19 | 19 | |
| 20 | 20 | /-- `f` is computable in polynomial time, with polynomially bounded output. -/ |
| 21 | 21 | def PolyTimeComputable (f : List α → List α) : Prop := |
| 22 | - ∃ (k : Nat) (M : Machine α k) (T B : Nat → Nat), PolyBounded T ∧ PolyBounded B ∧ | |
| 22 | + IsFinite α ∧ ∃ (k : Nat) (M : Machine α k) (T B : Nat → Nat), PolyBounded T ∧ PolyBounded B ∧ | |
| 23 | 23 | ComputesIn M f T ∧ ∀ x, (f x).length ≤ B x.length |
| 24 | 24 | |
| 25 | 25 | /-- `L` many-one reduces to `L'` in polynomial time. -/ |
| @@ -83,12 +83,12 @@ | ||
| 83 | 83 | theorem normalize {f : List α → List α} (h : PolyTimeComputable f) : |
| 84 | 84 | ∃ (k : Nat) (M : Machine α k) (c d b e : Nat), ComputesIn M f (polyBound c d) ∧ |
| 85 | 85 | ∀ x, (f x).length ≤ polyBound b e x.length := by |
| 86 | - obtain ⟨k, M, T, B, ⟨c, d, hT⟩, ⟨b, e, hB⟩, hM, hfB⟩ := h | |
| 86 | + obtain ⟨_, k, M, T, B, ⟨c, d, hT⟩, ⟨b, e, hB⟩, hM, hfB⟩ := h | |
| 87 | 87 | exact ⟨k, M, c, d, b, e, hM.mono hT, fun x => Nat.le_trans (hfB x) (hB _)⟩ |
| 88 | 88 | |
| 89 | 89 | /-- The identity: the machine that halts at once. -/ |
| 90 | -theorem id : PolyTimeComputable (fun x : List α => x) := | |
| 91 | - ⟨0, Machine.const α 0 true, fun _ => 0, fun n => n, PolyBounded.const 0, PolyBounded.id, | |
| 90 | +theorem id [IsFinite α] : PolyTimeComputable (fun x : List α => x) := | |
| 91 | + ⟨inferInstance, 0, Machine.const α 0 true, fun _ => 0, fun n => n, PolyBounded.const 0, PolyBounded.id, | |
| 92 | 92 | fun _ => ⟨rfl, rfl⟩, fun _ => Nat.le_refl _⟩ |
| 93 | 93 | |
| 94 | 94 | /-- **Polynomial-time functions compose.** -/ |
| @@ -98,7 +98,7 @@ | ||
| 98 | 98 | obtain ⟨k₂, M₂, c₂, d₂, b₂, e₂, hM₂, hB₂⟩ := hg.normalize |
| 99 | 99 | have hl₁ := hM₁.lift (Nat.le_add_right k₁ k₂) |
| 100 | 100 | have hl₂ := hM₂.lift (Nat.le_add_left k₂ k₁) |
| 101 | - refine ⟨k₁ + k₂, _, _, fun n => polyBound b₂ e₂ (polyBound b₁ e₁ n), | |
| 101 | + refine ⟨hf.1, k₁ + k₂, _, _, fun n => polyBound b₂ e₂ (polyBound b₁ e₁ n), | |
| 102 | 102 | ?_, ?_, hl₁.seq hB₁ hl₂, fun x => ?_⟩ |
| 103 | 103 | · exact ((PolyBounded.polyBound c₁ d₁).add (PolyBounded.const 1)).add |
| 104 | 104 | ((PolyBounded.polyBound c₂ d₂).comp (PolyBounded.polyBound b₁ e₁)) |
| @@ -110,7 +110,7 @@ | ||
| 110 | 110 | namespace Reduces |
| 111 | 111 | |
| 112 | 112 | /-- `≤ₚ` is reflexive. -/ |
| 113 | -theorem refl (L : Language α) : L ≤ₚ L := ⟨_, PolyTimeComputable.id, fun _ => Iff.rfl⟩ | |
| 113 | +theorem refl [IsFinite α] (L : Language α) : L ≤ₚ L := ⟨_, PolyTimeComputable.id, fun _ => Iff.rfl⟩ | |
| 114 | 114 | |
| 115 | 115 | /-- **Reductions compose**: `≤ₚ` is transitive. -/ |
| 116 | 116 | theorem trans {L₁ L₂ L₃ : Language α} (h₁₂ : L₁ ≤ₚ L₂) (h₂₃ : L₂ ≤ₚ L₃) : L₁ ≤ₚ L₃ := by |
| @@ -131,7 +131,7 @@ | ||
| 131 | 131 | obtain ⟨k₁, M₁, c₁, d₁, b, e, hM₁, hB⟩ := hf.normalize |
| 132 | 132 | obtain ⟨k₂, M₂, c₂, d₂, hM₂⟩ := hL'.polyBound |
| 133 | 133 | have hd := DecidesIn.seq (hM₁.lift (Nat.le_add_right k₁ k₂)) hB (hM₂.lift (Nat.le_add_left k₂ k₁)) |
| 134 | - refine ⟨k₁ + k₂, | |
| 134 | + refine ⟨hL'.1, k₁ + k₂, | |
| 135 | 135 | (M₁.lift (Embedding.castLE (Nat.le_add_right k₁ k₂))).seq |
| 136 | 136 | (M₂.lift (Embedding.castLE (Nat.le_add_left k₂ k₁))), |
| 137 | 137 | fun n => PvsNP.polyBound c₁ d₁ n + 1 + PvsNP.polyBound c₂ d₂ (PvsNP.polyBound b e n), ?_, ?_⟩ |
| @@ -0,0 +1,81 @@ | ||
| 1 | +import PvsNP.Complexity.P | |
| 2 | + | |
| 3 | +/-! | |
| 4 | +# Example: languages decided by the first symbol | |
| 5 | + | |
| 6 | +A concrete machine, not a construction from other machines: it reads the cell under the head of tape | |
| 7 | +`0` once and halts, accepting when a test `p` on that symbol passes. It decides | |
| 8 | +`{x | p x.head? = true}` in one step, so each such language is in P. | |
| 9 | + | |
| 10 | +The machine and its one-step run work over any alphabet; only the conclusion `InP` needs a finite | |
| 11 | +one (over `Nat`, a test on one symbol could be the halting problem). Two instances over `Bool`: the words that start with `true`, and the empty word. | |
| 12 | +-/ | |
| 13 | + | |
| 14 | +namespace PvsNP.Examples | |
| 15 | + | |
| 16 | +variable {α : Type} | |
| 17 | + | |
| 18 | +/-- The machine's three states. -/ | |
| 19 | +inductive FirstSymbolState where | |
| 20 | + | start | |
| 21 | + | accept | |
| 22 | + | reject | |
| 23 | + deriving DecidableEq, Repr | |
| 24 | + | |
| 25 | +instance : IsFinite FirstSymbolState := | |
| 26 | + ⟨⟨[.start, .accept, .reject], by intro a; cases a <;> simp⟩⟩ | |
| 27 | + | |
| 28 | +/-- The language of words whose first symbol (`none` for the empty word) passes `p`. -/ | |
| 29 | +def FirstSymbol (p : Option α → Bool) : Language α := fun x => p x.head? = true | |
| 30 | + | |
| 31 | +/-- Read tape `0` once; accept if `p` holds of what is there. One step, one tape. -/ | |
| 32 | +def firstSymbolMachine (p : Option α → Bool) : Machine α 0 where | |
| 33 | + Q := FirstSymbolState | |
| 34 | + finite := inferInstance | |
| 35 | + start := .start | |
| 36 | + halted | |
| 37 | + | .start => false | |
| 38 | + | _ => true | |
| 39 | + accepting | |
| 40 | + | .accept => true | |
| 41 | + | _ => false | |
| 42 | + δ _ r := (if p (r 0) then .accept else .reject, r, fun _ => .stay) | |
| 43 | + | |
| 44 | +/-- After one step the machine has halted, in `accept` exactly when `p` holds of the first symbol. -/ | |
| 45 | +theorem firstSymbolMachine_run (p : Option α → Bool) (x : List α) : | |
| 46 | + ((firstSymbolMachine p).run ((firstSymbolMachine p).init (inputTapes x)) 1).state = | |
| 47 | + if p x.head? then .accept else .reject := by | |
| 48 | + simp [Machine.run, Machine.step, Machine.init, firstSymbolMachine, Machine.reads, inputTapes, | |
| 49 | + Tape.read_ofWord] | |
| 50 | + | |
| 51 | +/-- Every language decided by the first symbol is in P, within one step. -/ | |
| 52 | +theorem firstSymbol_inP [IsFinite α] (p : Option α → Bool) : InP (FirstSymbol p) := by | |
| 53 | + refine ⟨inferInstance, 0, firstSymbolMachine p, fun _ => 1, PolyBounded.const 1, fun x => ?_⟩ | |
| 54 | + rw [firstSymbolMachine_run] | |
| 55 | + cases h : p x.head? <;> simp [firstSymbolMachine, FirstSymbol, h] | |
| 56 | + | |
| 57 | +/-- Words over `Bool` that start with `true`. -/ | |
| 58 | +def StartsWithTrue : Language Bool := FirstSymbol (· == some true) | |
| 59 | + | |
| 60 | +theorem startsWithTrue_iff (x : List Bool) : StartsWithTrue x ↔ x.head? = some true := by | |
| 61 | + simp [StartsWithTrue, FirstSymbol] | |
| 62 | + | |
| 63 | +theorem startsWithTrue_inP : InP StartsWithTrue := firstSymbol_inP _ | |
| 64 | + | |
| 65 | +/-- The language holding only the empty word. -/ | |
| 66 | +def EmptyWord : Language Bool := FirstSymbol Option.isNone | |
| 67 | + | |
| 68 | +theorem emptyWord_iff (x : List Bool) : EmptyWord x ↔ x = [] := by | |
| 69 | + cases x <;> simp [EmptyWord, FirstSymbol] | |
| 70 | + | |
| 71 | +theorem emptyWord_inP : InP EmptyWord := firstSymbol_inP _ | |
| 72 | + | |
| 73 | +/-- Its complement, the non-empty words, is in P too, by closure under complement. -/ | |
| 74 | +theorem nonEmpty_inP : InP EmptyWord.compl := emptyWord_inP.compl | |
| 75 | + | |
| 76 | +/-- The machine run in the kernel: on `[true, false]` it accepts after one step. -/ | |
| 77 | +example : ((firstSymbolMachine (· == some true)).run | |
| 78 | + ((firstSymbolMachine (· == some true)).init (inputTapes [true, false])) 1).state = .accept := by | |
| 79 | + rw [firstSymbolMachine_run]; rfl | |
| 80 | + | |
| 81 | +end PvsNP.Examples | |
| @@ -16,8 +16,9 @@ | ||
| 16 | 16 | - The tape alphabet is `Option α`: machines have no extra work symbols. For `|α| ≥ 2` this changes |
| 17 | 17 | running times only polynomially; it keeps machines over one alphabet composable without re-encoding |
| 18 | 18 | tapes. |
| 19 | -- Finiteness of `Q` is part of the structure (`finite`). Without it a state could store the whole input | |
| 20 | - and the model would decide anything in one step. | |
| 19 | +- Finiteness of `Q` is part of the structure (`finite`). Without it a machine could scan its input | |
| 20 | + once, accumulating it in the state, and then apply an arbitrary predicate: every language would be | |
| 21 | + decidable in linear time. The alphabet's finiteness is required by the complexity classes. | |
| 21 | 22 | -/ |
| 22 | 23 | |
| 23 | 24 | namespace PvsNP |
| @@ -18,11 +18,14 @@ | ||
| 18 | 18 | namespace PvsNP |
| 19 | 19 | |
| 20 | 20 | /-- How the tapes of a `k + 1`-tape machine sit among `k' + 1` tapes: `emb` places each small tape, |
| 21 | -and `back` recognises the places (`none` for a tape the small machine does not use). -/ | |
| 21 | +and `back` recognises the places (`none` for a tape the small machine does not use). The two laws | |
| 22 | +make `back` exactly the inverse of `emb` on its image, so `emb` is injective and every tape outside | |
| 23 | +the image is left alone. -/ | |
| 22 | 24 | structure Embedding (k k' : Nat) where |
| 23 | 25 | emb : Fin (k + 1) → Fin (k' + 1) |
| 24 | 26 | back : Fin (k' + 1) → Option (Fin (k + 1)) |
| 25 | 27 | back_emb : ∀ i, back (emb i) = some i |
| 28 | + emb_back : ∀ j i, back j = some i → emb i = j | |
| 26 | 29 | |
| 27 | 30 | namespace Embedding |
| 28 | 31 | |
| @@ -31,6 +34,10 @@ | ||
| 31 | 34 | emb i := ⟨i.val, by omega⟩ |
| 32 | 35 | back j := if hj : j.val < k + 1 then some ⟨j.val, hj⟩ else none |
| 33 | 36 | back_emb i := by simp [i.isLt] |
| 37 | + emb_back j i h := by | |
| 38 | + split at h | |
| 39 | + · cases h; rfl | |
| 40 | + · cases h | |
| 34 | 41 | |
| 35 | 42 | /-- Tape `0` stays; tape `i + 1` becomes tape `i + 2`. Tape `1` is not used. -/ |
| 36 | 43 | def skipOne {k k' : Nat} (h : k + 1 ≤ k') : Embedding k k' where |
| @@ -48,6 +55,19 @@ | ||
| 48 | 55 | have h3 : i.val + 1 - 1 < k + 1 := by omega |
| 49 | 56 | simp only [hi, h1, h2, h3, ↓reduceIte, ↓reduceDIte, Option.some.injEq] |
| 50 | 57 | exact Fin.ext (by simp) |
| 58 | + emb_back j i h := by | |
| 59 | + apply Fin.ext | |
| 60 | + by_cases h0 : j.val = 0 | |
| 61 | + · simp only [h0, ↓reduceIte, Option.some.injEq] at h | |
| 62 | + subst h; simp [h0] | |
| 63 | + · by_cases h1 : j.val = 1 | |
| 64 | + · simp [h1] at h | |
| 65 | + · simp only [h0, h1, ↓reduceIte] at h | |
| 66 | + split at h | |
| 67 | + · cases h | |
| 68 | + have : j.val - 1 ≠ 0 := by omega | |
| 69 | + simp [this]; omega | |
| 70 | + · cases h | |
| 51 | 71 | |
| 52 | 72 | end Embedding |
| 53 | 73 | |
| @@ -36,6 +36,7 @@ | ||
| 36 | 36 | | For NP-complete `L`: P ≠ NP ↔ `L ∉ P` | `NPComplete.pNeNP_iff` | [`Open.lean`](PvsNP/Open.lean) | |
| 37 | 37 | | Running a machine on more tapes is a faithful simulation | `Machine.run_lift` | [`Machine/Lift.lean`](PvsNP/Machine/Lift.lean) | |
| 38 | 38 | | Running two machines in sequence | `Machine.run_seq` | [`Machine/Compose.lean`](PvsNP/Machine/Compose.lean) | |
| 39 | +| A concrete one-step machine: first-symbol languages are in P | `Examples.firstSymbol_inP` | [`Examples/FirstSymbol.lean`](PvsNP/Examples/FirstSymbol.lean) | | |
| 39 | 40 | |
| 40 | 41 | The statement of the open problem, verbatim from [`PvsNP/Open.lean`](PvsNP/Open.lean): |
| 41 | 42 | |
| @@ -78,6 +79,7 @@ | ||
| 78 | 79 | Complexity/NP.lean the class NP; P ⊆ NP; closure under reductions |
| 79 | 80 | Complexity/Completeness.lean NP-hardness and NP-completeness |
| 80 | 81 | Open.lean the P vs NP statement (open) |
| 82 | + Examples/FirstSymbol.lean concrete machines: languages decided by the first symbol | |
| 81 | 83 | Audit/Axioms.lean build-time axiom audit |
| 82 | 84 | ``` |
| 83 | 85 | |
| @@ -105,8 +107,10 @@ | ||
| 105 | 107 | These are deliberate, and each is a place where a reader should check that the definitions mean what |
| 106 | 108 | they claim: |
| 107 | 109 | |
| 108 | -- **Finite control.** A machine's state type must be finite (`IsFinite`). Without that, one state | |
| 109 | - could store the whole input and every language would be decidable in one step. | |
| 110 | +- **Finite control, finite alphabet.** A machine's state type must be finite (`IsFinite`): otherwise | |
| 111 | + it could read its input into its state and then apply any predicate at all. P, NP and | |
| 112 | + polynomial-time functions also require a finite alphabet: over `Nat`, a machine reading a single | |
| 113 | + symbol could test membership in the halting set. | |
| 110 | 114 | - **Tape alphabet `Option α`.** Machines write input symbols or blanks, nothing else. For alphabets with |
| 111 | 115 | at least two symbols this costs only a polynomial slowdown, and it lets machines over the same |
| 112 | 116 | alphabet run one after another with no re-encoding. |
| @@ -115,7 +119,9 @@ | ||
| 115 | 119 | a literal hand-over. |
| 116 | 120 | - **Verifiers in the style of Sipser.** The verifier's time bound depends on `|x|` only, and |
| 117 | 121 | `x ∈ L ↔ ∃ w, V accepts (x, w)`. A verifier running `T |x|` steps can read at most `T |x|` |
| 118 | - certificate symbols, so certificates are polynomially short in effect. | |
| 122 | + certificate symbols, so certificates are polynomially short in effect. Certificates use the input | |
| 123 | + alphabet: the usual NP over a finite alphabet of two or more symbols, while over a one-symbol | |
| 124 | + alphabet certificates are unary rather than binary. | |
| 119 | 125 | - **Output bound stated, not derived.** `PolyTimeComputable f` asks for `|f x|` to be polynomially |
| 120 | 126 | bounded. That follows from the time bound in any reasonable model; deriving it is on the roadmap. |
| 121 | 127 | |
| @@ -124,7 +130,7 @@ | ||
| 124 | 130 | The milestones, in order; details and acceptance criteria are in [`ROADMAP.md`](ROADMAP.md). |
| 125 | 131 | |
| 126 | 132 | 1. **Done:** machines, P, NP, reductions, P ⊆ NP, closure properties, NP-completeness, the open statement. |
| 127 | -2. Examples: concrete machines for small languages, run in the kernel. | |
| 133 | +2. **Done:** examples: concrete machines for small languages, run in the kernel. | |
| 128 | 134 | 3. Derive the output-length bound from the time bound. |
| 129 | 135 | 4. Short certificates suffice: verifiers only ever need certificates of length `≤ T |x|`. |
| 130 | 136 | 5. Boolean formulas, CNF and an encoding into `List Bool`. |
| @@ -11,13 +11,15 @@ | ||
| 11 | 11 | statement. Proved: P ⊆ NP, P closed under complement, reductions reflexive and transitive, P and NP |
| 12 | 12 | closed under reductions, an NP-complete language is in P iff P = NP. |
| 13 | 13 | |
| 14 | -## 2. Examples | |
| 14 | +## 2. Examples — done | |
| 15 | 15 | |
| 16 | 16 | Concrete machines for small languages over `Bool` (the empty word, "starts with `true`"), with their |
| 17 | 17 | time bounds proved by running them. Shows the definitions are inhabited by real machines, not only by |
| 18 | 18 | constructions. |
| 19 | 19 | |
| 20 | -Done when: at least two concrete languages are proved in P by explicit machines. | |
| 20 | +Done when: at least two concrete languages are proved in P by explicit machines. Done in | |
| 21 | +[`PvsNP/Examples/FirstSymbol.lean`](PvsNP/Examples/FirstSymbol.lean): "starts with `true`", the | |
| 22 | +empty word and the non-empty words, all from one machine that reads a single cell. | |
| 21 | 23 | |
| 22 | 24 | ## 3. Output length from running time |
| 23 | 25 | |