, and -completeness over (§§5-6)
DefinitionBSSComplexitySize, the classes and , polynomial-time reductions and -completeness over , from §5 (pp. 23–26) and §6 (p. 26).
Over the height of every element is , so the size of is its length plus one, and the standard cost function coincides with the halting time . A machine is in class on a space of admissible inputs when it halts on every within steps for fixed . A machine solves when on each admissible input it halts with answer or and answers exactly on . The pairing of guesses with instances places the instance in the even coordinates and the guess in the odd ones.
follows the three clauses of the definition on p. 25: the values are and ; an answer of occurs only at members of ; and each member of has some guess on which the answer is within steps. A polynomial time reduction of to is a map computed on by a machine in class , landing in , whose value lies in exactly on ; and is -complete over when it is in and everything in so reduces to it.
import Definitions.Def_BSSMachine
/-!
# Complexity of machines over the reals (Blum–Shub–Smale, §§5–6)
Formalization of size, the classes `P` and `NP`, polynomial time reductions and
`NP`-completeness over `ℝ`, following
L. Blum, M. Shub, S. Smale, *On a theory of computation and complexity over the
real numbers: NP-completeness, recursive functions and universal machines*,
Bull. Amer. Math. Soc. **21** (1989), no. 1, 1–46, §5 (pp. 23–26) and §6 (p. 26).
Over `ℝ` the height of every element is `1` (BSS §5, p. 24), so the size of a
point of `ℝ^∞` is its length plus one and the standard cost function `C_M(y)`
equals the halting time `T_M(y)`.
-/
namespace BSS
/-- The size over `ℝ` of a point of `ℝ^∞`: its length plus its height, the height
over `ℝ` of a real number being `1` (BSS §5, p. 24). -/
noncomputable def sizeR (x : Rinf ℝ) : ℕ := lengthInf x + 1
/-- The pairing `ℝ^∞ × ℝ^∞ → ℝ^∞` used for the input space `Y × I` of a
nondeterministic machine (BSS §2, p. 13: `R^∞ = R^∞ + ⋯ + R^∞`): `y` is placed in
the even coordinates and `y'` in the odd ones. -/
noncomputable def pairInf (y y' : Rinf ℝ) : Rinf ℝ :=
Finsupp.onFinset (α := ℕ) (M := ℝ) ((y.support.image (fun i => 2 * i)) ∪ (y'.support.image (fun i => 2 * i + 1)))
(fun i : ℕ => if i % 2 = 0 then y (i / 2) else y' (i / 2))
(by
intro a ha
by_cases h : a % 2 = 0
· simp only [if_pos h] at ha
refine Finset.mem_union_left _ (Finset.mem_image.mpr ⟨a / 2, ?_, ?_⟩)
· exact Finsupp.mem_support_iff.mpr ha
· omega
· simp only [if_neg h] at ha
refine Finset.mem_union_right _ (Finset.mem_image.mpr ⟨a / 2, ?_, ?_⟩)
· exact Finsupp.mem_support_iff.mpr ha
· omega)
/-- The machine `M` is in class `P` on the space of admissible inputs `Y`:
its cost on every admissible input is bounded by a fixed polynomial in the size of
the input (BSS §5, p. 24). Over `ℝ` the cost is the halting time. -/
def InClassP (M : Machine ℝ) (Y : Set (Rinf ℝ)) : Prop :=
∃ c q : ℕ, ∀ y ∈ Y, M.Halts y ∧ M.haltingTime y ≤ c * (sizeR y) ^ q
/-- `M` solves the decision problem `(Y, Yyes)`: on every admissible input it halts
with answer `1` (yes) or `0` (no), and answers `1` exactly on `Yyes`
(BSS §5, p. 25). -/
def Solves (M : Machine ℝ) (Y Yyes : Set (Rinf ℝ)) : Prop :=
∀ y ∈ Y, M.Halts y ∧ (M.outputVal y = 1 ∨ M.outputVal y = 0) ∧
(M.outputVal y = 1 ↔ y ∈ Yyes)
/-- The decision problem `(Y, Yyes)` over `ℝ` is in class `P` (BSS §5, p. 25). -/
def DecisionInP (Y Yyes : Set (Rinf ℝ)) : Prop :=
∃ M : Machine ℝ, Solves M Y Yyes ∧ InClassP M Y
/-- The decision problem `(Y, Yyes)` over `ℝ` is in class `NP` (BSS §5, p. 25):
there is a machine on `Y × ℝ^∞` whose values are `0` and `1`, which answers `1`
only at members of `Yyes`, and which for every member of `Yyes` answers `1` on
some guess within time polynomial in the size of the instance. -/
def DecisionInNP (Y Yyes : Set (Rinf ℝ)) : Prop :=
∃ (M : Machine ℝ) (c q : ℕ),
(∀ y ∈ Y, ∀ y' : Rinf ℝ, M.Halts (pairInf y y') →
(M.outputVal (pairInf y y') = 1 ∨ M.outputVal (pairInf y y') = 0)) ∧
(∀ y ∈ Y, ∀ y' : Rinf ℝ, M.Halts (pairInf y y') →
M.outputVal (pairInf y y') = 1 → y ∈ Yyes) ∧
(∀ y ∈ Yyes, ∃ y' : Rinf ℝ, M.Halts (pairInf y y') ∧
M.outputVal (pairInf y y') = 1 ∧
M.haltingTime (pairInf y y') ≤ c * (sizeR y) ^ q)
/-- A polynomial time reduction of `(Z, Zyes)` to `(Y, Yyes)` (BSS §6, p. 26):
a map `ψ : Z → Y`, computed on `Z` by a machine in class `P`, with
`ψ z ∈ Yyes` if and only if `z ∈ Zyes`. -/
def PolyTimeReduces (Z Zyes Y Yyes : Set (Rinf ℝ)) : Prop :=
∃ M : Machine ℝ, InClassP M Z ∧ (∀ z ∈ Z, M.output z ∈ Y) ∧
(∀ z ∈ Z, M.output z ∈ Yyes ↔ z ∈ Zyes)
/-- The decision problem `(Y, Yyes)` is `NP`-complete over `ℝ` (BSS §6, p. 26):
it lies in `NP`, and every decision problem in `NP` over `ℝ` reduces to it in
polynomial time. -/
def NPCompleteOverReal (Y Yyes : Set (Rinf ℝ)) : Prop :=
DecisionInNP Y Yyes ∧
∀ Z Zyes : Set (Rinf ℝ), Zyes ⊆ Z → DecisionInNP Z Zyes →
PolyTimeReduces Z Zyes Y Yyes
end BSS
Read-back
What the Lean code literally says, in plain math · NON-BLIND: written by the drafting agent (Aristotle, Harmonic), not an independent auditor
⚠️ NON-BLIND READ-BACK — NOT INDEPENDENT TESTIMONY. This read-back was not written by an independent blind auditor. It was written by the same agent that drafted this item's Lean statement, at the explicit instruction of the proposal owner. The author therefore already knew what the statement was intended to say, which is exactly the bias a read-back exists to exclude. Treat this text as the author's own rendering of their own code, not as corroborating evidence, and obtain a genuinely independent audit before relying on it.
This file fixes the complexity vocabulary, specialized to the ring and to the machine model of the accompanying definition.
Size. For , , where the length is for and is for . So the size is a natural number and is always at least .
Pairing. Given , is the element of with
Class . A machine is in class on , for a set , when there exist natural numbers such that for every : halts on , and its halting time is at most . Both and are natural numbers, so is allowed; that choice would force halting time on all of . If is empty the condition holds for any .
Solving a decision problem. solves when for every : halts on ; its output value is or ; and its output value is if and only if . Here the output value is coordinate of the part of the halting state. Nothing constrains outside , and nothing forces : for no condition is imposed.
The class . is in when some machine both solves it and is in class on .
The class . is in when there exist a machine and natural numbers such that all three of the following hold.
- For every and every , if halts on then its output value there is or .
- For every and every , if halts on with output value , then .
- For every there exists such that halts on , its output value there is , and its halting time there is at most — the bound being in the size of the instance , not of the pair.
Clauses 1 and 2 are conditioned on and on halting; clause 3 quantifies over , which is not assumed to be contained in here.
Polynomial time reduction. reduces in polynomial time to when there is a machine that is in class on , whose output on every lies in , and for which, for every , the output lies in if and only if .
-completeness over . is -complete over when it is in , and for every pair of sets of with in , the pair reduces to in polynomial time. The quantifier ranges over all such pairs of sets, with no definability or effectivity restriction.