Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions LeanPool/KochenSpecker.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/-
Copyright (c) 2026 Zayn Blore. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zayn Blore
-/

module

public import LeanPool.KochenSpecker.Main

/-!
# The Kochen–Specker theorem in every finite dimension

Source: doi:10.1512/iumj.1968.17.17004, url:https://github.com/zblore/kochen-specker-lean/tree/a9f552a11188809b15ba14ef2db5a2a8ecd3c83b
Authors: Zayn Blore
Status: verified
Main declarations: `KochenSpecker.kochen_specker`, `KochenSpecker.not_isValuation`,
`KochenSpecker.kochen_specker_of_four_le`
Tags: contextuality, inner-product-spaces, finite-certificates
MSC: 81P13, 46C05
-/
125 changes: 125 additions & 0 deletions LeanPool/KochenSpecker/Cabello18.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/-
Copyright (c) 2026 Zayn Blore. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zayn Blore
-/
module

public import LeanPool.KochenSpecker.Valuation
public import Mathlib.Algebra.BigOperators.Group.Finset.Basic

/-!
# Dimension four: Cabello's 18 vectors, by parity

Cabello, Estebaranz and García-Alcaine (*Bell-Kochen-Specker theorem: A proof with 18 vectors*,
Phys. Lett. A 212 (1996) 183) gave 18 vectors in `ℝ⁴`, with integer coordinates, forming 9
orthogonal bases in which every vector appears exactly twice. A valuation would make each basis
contribute exactly one `true`, nine in all, while each `true` vector is counted twice, an even
number. This proof uses no computer search.

The parity argument is `no_assignment`; `not_isValuation_four` turns it into the theorem in `𝕜⁴`
for every `RCLike 𝕜`. The combinatorial core was first written for the author's csd-lean4
(`Empirical/QM/Contextuality/KS18.lean`); this is a standalone version.
-/

@[expose] public section

open Module

namespace KochenSpecker.Cabello

/-- The 18 vectors. -/
def vecs : Fin 18 → Fin 4 → ℤ :=
![![0, 0, 0, 1], ![0, 0, 1, 0], ![1, 1, 0, 0], ![1, -1, 0, 0], ![0, 1, 0, 0], ![1, 0, 1, 0],
![1, 0, -1, 0], ![1, -1, 1, -1], ![1, -1, -1, 1], ![0, 0, 1, 1], ![1, 1, 1, 1],
![0, 1, 0, -1], ![1, 0, 0, 1], ![1, 0, 0, -1], ![0, 1, -1, 0], ![1, 1, -1, 1],
![1, 1, 1, -1], ![-1, 1, 1, 1]]

/-- The 9 bases, as four vector indices each. -/
def bases : Fin 9 → Fin 4 → Fin 18 :=
![![0, 1, 2, 3], ![0, 4, 5, 6], ![2, 7, 8, 9], ![6, 7, 10, 11], ![1, 4, 12, 13],
![8, 10, 13, 14], ![3, 9, 15, 16], ![5, 11, 15, 17], ![12, 14, 16, 17]]

/-- The integer dot product. -/
def dot (x y : Fin 4 → ℤ) : ℤ := x 0 * y 0 + x 1 * y 1 + x 2 * y 2 + x 3 * y 3

theorem bases_orth : ∀ B : Fin 9, ∀ i j : Fin 4, i ≠ j →
dot (vecs (bases B i)) (vecs (bases B j)) = 0 := by decide

theorem dot_self_pos : ∀ n : Fin 18, 0 < dot (vecs n) (vecs n) := by decide

/-- Every vector appears in exactly two of the 36 basis slots. -/
theorem appears_twice : ∀ n : Fin 18,
(Finset.univ.filter (fun p : Fin 9 × Fin 4 => bases p.1 p.2 = n)).card = 2 := by decide

/-- **The parity argument.** No assignment gives exactly one `true` in each of the 9 bases. -/
theorem no_assignment (c : Fin 18 → Bool)
(h : ∀ B, (Finset.univ.filter (fun i : Fin 4 => c (bases B i) = true)).card = 1) : False := by
set S := Finset.univ.filter (fun p : Fin 9 × Fin 4 => c (bases p.1 p.2) = true)
set T := Finset.univ.filter (fun n : Fin 18 => c n = true)
-- Basis by basis, the `true` slots number nine.
have h9 : S.card = 9 := by
rw [Finset.card_filter, ← Finset.univ_product_univ, Finset.sum_product]
simp only [← Finset.card_filter, h]
simp
-- Vector by vector, each `true` vector fills two slots.
have h2 : S.card = 2 * T.card := by
rw [Finset.card_eq_sum_card_fiberwise (f := fun p : Fin 9 × Fin 4 => bases p.1 p.2) (t := T)
(fun p hp => by simpa [S, T] using hp)]
rw [Finset.sum_congr rfl (g := fun _ => 2) (fun n hn => ?_), Finset.sum_const, smul_eq_mul,
mul_comm]
have hn' : c n = true := by simpa [T] using hn
rw [← appears_twice n]
congr 1
ext p
simp only [S, Finset.mem_filter, Finset.mem_univ, true_and, and_iff_right_iff_imp]
intro hp
rw [hp]
exact hn'
omega

/-! ### From the vectors to unit vectors of `𝕜⁴` -/

variable {𝕜 : Type*} [RCLike 𝕜]

/-- A vector of `𝕜⁴` with integer coordinates. -/
def vec (x : Fin 4 → ℤ) : EuclideanSpace 𝕜 (Fin 4) := WithLp.toLp 2 (fun k => ((x k : ℤ) : 𝕜))

theorem inner_vec (x y : Fin 4 → ℤ) : inner 𝕜 (vec (𝕜 := 𝕜) x) (vec y) = ((dot x y : ℤ) : 𝕜) := by
simp only [vec, PiLp.inner_apply, RCLike.inner_apply', map_intCast, Fin.sum_univ_four, dot]
push_cast
ring

theorem vec_ne_zero (n : Fin 18) : vec (𝕜 := 𝕜) (vecs n) ≠ 0 := by
intro h0
have h := inner_vec (𝕜 := 𝕜) (vecs n) (vecs n)
rw [h0, inner_zero_left] at h
have : ((dot (vecs n) (vecs n) : ℤ) : 𝕜) ≠ 0 := by exact_mod_cast (dot_self_pos n).ne'
exact this h.symm

/-- The `n`-th vector, normalised. -/
noncomputable def unit (n : Fin 18) : EuclideanSpace 𝕜 (Fin 4) :=
(‖vec (𝕜 := 𝕜) (vecs n)‖⁻¹ : 𝕜) • vec (vecs n)

theorem norm_unit (n : Fin 18) : ‖unit (𝕜 := 𝕜) n‖ = 1 := norm_smul_inv_norm (vec_ne_zero n)

/-- Each of the 9 bases, normalised, is orthonormal. -/
theorem orthonormal_basis (B : Fin 9) : Orthonormal 𝕜 (fun i => unit (𝕜 := 𝕜) (bases B i)) := by
rw [orthonormal_iff_ite]
intro i j
split_ifs with hij
· subst hij
rw [inner_self_eq_norm_sq_to_K, norm_unit]
simp
· simp [unit, inner_smul_left, inner_smul_right, inner_vec, bases_orth B i j hij]

/-- **The Kochen–Specker theorem in `𝕜⁴`**, by Cabello's parity argument. -/
theorem not_isValuation_four (v : EuclideanSpace 𝕜 (Fin 4) → Bool) : ¬ IsValuation 𝕜 4 v := by
intro hv
refine no_assignment (fun n => v (unit n)) (fun B => ?_)
obtain ⟨i, hi, hu⟩ := hv.existsUnique_of_orthonormal (by simp) (orthonormal_basis B)
rw [Finset.card_eq_one]
exact ⟨i, by ext j; simp only [Finset.mem_filter, Finset.mem_univ, true_and,
Finset.mem_singleton]; exact ⟨hu j, fun e => e ▸ hi⟩⟩

end KochenSpecker.Cabello
125 changes: 125 additions & 0 deletions LeanPool/KochenSpecker/Checker.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/-
Copyright (c) 2026 Zayn Blore. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zayn Blore
-/
module

public import Mathlib.Data.List.Basic

/-!
# A checked case-split refutation of Kochen–Specker colourings

A *system* is a list of pairs and a list of triads of natural-number labels. A *colouring* of a
system gives each label a truth value so that no pair has both labels `true` and every triad has
exactly one label `true`.

A `Refutation` is a binary tree of case splits. `refutes S ρ r` evaluates it under a partial
assignment `ρ`: `close` succeeds when `ρ` already violates some constraint (two `true`s on a pair
or a triad, or three `false`s on a triad), and `branch v t f` requires `t` to succeed with `v` set
`true` and `f` with `v` set `false`. `no_colouring_of_refutes` shows that a refutation accepted
from the empty assignment rules out every colouring. Refutations are generated outside Lean
(`scripts/peres33.py`) and checked here by the kernel; nothing computed outside Lean is trusted.

The method, a case-split tree over a list-based partial assignment checked with `decide`, is the
one used by M. Kernaghan's `lean-ks` (github.com/michaelkernaghan/contextuality), which the author
read before writing this file. This file was written separately: the constraints are explicit
pair and triad lists rather than an orthogonality test, a single `close` searches for any
violated constraint rather than naming one, and triads require exactly one `true`.
-/

@[expose] public section

namespace KochenSpecker

/-- A partial assignment of truth values to labels; the first entry for a label wins. -/
abbrev Partial := List (ℕ × Bool)

/-- The value a partial assignment gives a label, if any. -/
def valueOf : Partial → ℕ → Option Bool
| [], _ => none
| (w, b) :: ρ, v => if w = v then some b else valueOf ρ v

/-- Pairs and triads of labels. -/
structure Constraints where
/-- Pairs that cannot both be true. -/
pairs : List (ℕ × ℕ)
/-- Triads in which exactly one label is true. -/
triads : List (ℕ × ℕ × ℕ)

/-- `c` colours `S`: no pair is all `true`, and each triad has exactly one `true`. -/
def Colours (S : Constraints) (c : ℕ → Bool) : Prop :=
(∀ p ∈ S.pairs, ¬ (c p.1 = true ∧ c p.2 = true)) ∧
(∀ t ∈ S.triads, (c t.1 && !c t.2.1 && !c t.2.2) || (!c t.1 && c t.2.1 && !c t.2.2) ||
(!c t.1 && !c t.2.1 && c t.2.2) = true)

/-- `c` extends the partial assignment `ρ`. -/
def Extends (c : ℕ → Bool) (ρ : Partial) : Prop := ∀ v b, valueOf ρ v = some b → c v = b

/-- The number of labels among three that `ρ` sets to `b`. -/
def countValue (ρ : Partial) (b : Bool) (t : ℕ × ℕ × ℕ) : ℕ :=
(if valueOf ρ t.1 = some b then 1 else 0) + (if valueOf ρ t.2.1 = some b then 1 else 0) +
(if valueOf ρ t.2.2 = some b then 1 else 0)

/-- `ρ` already violates a constraint of `S`. -/
def violated (S : Constraints) (ρ : Partial) : Bool :=
S.pairs.any (fun p => valueOf ρ p.1 = some true ∧ valueOf ρ p.2 = some true) ||
S.triads.any (fun t => 2 ≤ countValue ρ true t ∨ countValue ρ false t = 3)

/-- A case-split refutation. -/
inductive Refutation where
| close
| branch (v : ℕ) (t f : Refutation)

/-- Evaluate a refutation under a partial assignment. -/
def refutes (S : Constraints) : Partial → Refutation → Bool
| ρ, .close => violated S ρ
| ρ, .branch v t f => refutes S ((v, true) :: ρ) t && refutes S ((v, false) :: ρ) f

theorem Extends.cons {c : ℕ → Bool} {ρ : Partial} {v : ℕ} {b : Bool} (h : Extends c ρ)
(hv : c v = b) : Extends c ((v, b) :: ρ) := by
intro w b' hw
simp only [valueOf] at hw
split_ifs at hw with hvw
· cases hw
exact hvw ▸ hv
· exact h w b' hw

/-- What `ρ` says about a label agrees with the colouring. -/
theorem valueOf_eq {c : ℕ → Bool} {ρ : Partial} (h : Extends c ρ) (v : ℕ) :
valueOf ρ v = none ∨ valueOf ρ v = some (c v) := by
rcases hl : valueOf ρ v with _ | b
· exact Or.inl rfl
· exact Or.inr (by rw [h v b hl])

/-- No constraint is violated by a partial assignment that a colouring extends. -/
theorem violated_eq_false {S : Constraints} {c : ℕ → Bool} {ρ : Partial} (hc : Colours S c)
(h : Extends c ρ) : violated S ρ = false := by
simp only [violated, Bool.or_eq_false_iff, List.any_eq_false, decide_eq_true_eq]
refine ⟨fun p hp ⟨h1, h2⟩ => hc.1 p hp ⟨h p.1 true h1, h p.2 true h2⟩, fun t ht => ?_⟩
have h3 := hc.2 t ht
rcases valueOf_eq h t.1 with e1 | e1 <;> rcases valueOf_eq h t.2.1 with e2 | e2 <;>
rcases valueOf_eq h t.2.2 with e3 | e3 <;>
· simp only [countValue, e1, e2, e3]
cases hx : c t.1 <;> cases hy : c t.2.1 <;> cases hz : c t.2.2 <;> simp_all

/-- An accepted refutation leaves no colouring that extends `ρ`. -/
theorem not_extends_of_refutes (S : Constraints) {c : ℕ → Bool} (hc : Colours S c) :
∀ (cert : Refutation) (ρ : Partial), refutes S ρ cert = true → ¬ Extends c ρ
| .close, ρ, hchk, h => by
simp only [refutes] at hchk
rw [violated_eq_false hc h] at hchk
exact Bool.false_ne_true hchk
| .branch v t f, ρ, hchk, h => by
simp only [refutes, Bool.and_eq_true] at hchk
cases hv : c v
· exact not_extends_of_refutes S hc f _ hchk.2 (Extends.cons h hv)
· exact not_extends_of_refutes S hc t _ hchk.1 (Extends.cons h hv)

/-- A refutation accepted from the empty assignment rules out every colouring. -/
theorem no_colouring_of_refutes (S : Constraints) (cert : Refutation)
(h : refutes S [] cert = true) : ¬ ∃ c, Colours S c := by
rintro ⟨c, hc⟩
exact not_extends_of_refutes S hc cert [] h (fun _ _ hv => by simp [valueOf] at hv)

end KochenSpecker
14 changes: 14 additions & 0 deletions LeanPool/KochenSpecker/Imports.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/-
Copyright (c) 2026 Lean Pool contributors. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Lean Pool contributors
-/
module -- shake: keep-all --deprecated_module: ignore

-- Generated project imports; run `lake exe mk_all`.
public import LeanPool.KochenSpecker
public import LeanPool.KochenSpecker.Cabello18
public import LeanPool.KochenSpecker.Checker
public import LeanPool.KochenSpecker.Main
public import LeanPool.KochenSpecker.Peres33
public import LeanPool.KochenSpecker.Valuation
74 changes: 74 additions & 0 deletions LeanPool/KochenSpecker/Main.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/-
Copyright (c) 2026 Zayn Blore. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zayn Blore
-/
module

public import LeanPool.KochenSpecker.Peres33
public import LeanPool.KochenSpecker.Cabello18

/-!
# The Kochen–Specker theorem

Kochen and Specker’s original obstruction (Theorem 1 of *The Problem of Hidden Variables in
Quantum Mechanics*) constructs a finite partial Boolean algebra of subspaces of `ℝ³`
with no homomorphism to the two-element Boolean algebra.

This development proves a vector-valuation formulation over `ℝ` and `ℂ` in every finite
dimension `d ≥ 3`: no Boolean map on vectors marks exactly one vector of each orthonormal basis.

* Dimension three is `Peres.not_isValuation_three` (Peres's 33 rays, a kernel-checked case split).
* `IsValuation.exists_subspace` restricts a valuation in dimension `d + 1` to the orthogonal
complement of a unit vector where it is `false`; so `NoValuation.of_le` carries the theorem
from dimension three to every larger dimension, for every inner product space, not only `𝕜ᵈ`.
* `kochen_specker_of_four_le` proves the case `d ≥ 4` a second way, from Cabello's 18 vectors by
a parity count, with no computer search.
-/

@[expose] public section

open Module

namespace KochenSpecker

universe u

variable {𝕜 : Type*} [RCLike 𝕜]

/-- No inner product space of dimension three carries a valuation. -/
theorem noValuation_three : NoValuation.{u} 𝕜 3 := by
intro E _ _ hE v hv
have : FiniteDimensional 𝕜 E := Module.finite_of_finrank_pos (by omega)
set φ := ((stdOrthonormalBasis 𝕜 E).reindex (finCongr hE)).repr
exact Peres.not_isValuation_three _ (hv.map φ)

/-- No inner product space of dimension four carries a valuation (Cabello's parity argument). -/
theorem noValuation_four : NoValuation.{u} 𝕜 4 := by
intro E _ _ hE v hv
have : FiniteDimensional 𝕜 E := Module.finite_of_finrank_pos (by omega)
set φ := ((stdOrthonormalBasis 𝕜 E).reindex (finCongr hE)).repr
exact Cabello.not_isValuation_four _ (hv.map φ)

/-- The vector-valuation obstruction in every inner product space of dimension `d ≥ 3`
over `ℝ` or `ℂ` (any `RCLike 𝕜`). -/
theorem not_isValuation {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] {d : ℕ}
(hd : 3 ≤ d) (hE : finrank 𝕜 E = d) (v : E → Bool) : ¬ IsValuation 𝕜 d v :=
noValuation_three.of_le (by norm_num) hd E hE v

/-- The vector-valuation formulation of the Kochen–Specker theorem in `𝕜ᵈ`. For `d ≥ 3`
and `𝕜 = ℝ` or `ℂ`, every Boolean map fails to mark exactly one vector in some
orthonormal basis. -/
theorem kochen_specker {d : ℕ} (hd : 3 ≤ d) :
¬ ∃ v : EuclideanSpace 𝕜 (Fin d) → Bool,
∀ b : OrthonormalBasis (Fin d) 𝕜 (EuclideanSpace 𝕜 (Fin d)), ∃! i, v (b i) = true :=
fun ⟨v, hv⟩ => not_isValuation hd (by simp) v hv

/-- The case `d ≥ 4` of `kochen_specker`, proved from Cabello's 18 vectors by a parity count,
independently of Peres's rays and of any computer-generated certificate. -/
theorem kochen_specker_of_four_le {d : ℕ} (hd : 4 ≤ d) :
¬ ∃ v : EuclideanSpace 𝕜 (Fin d) → Bool,
∀ b : OrthonormalBasis (Fin d) 𝕜 (EuclideanSpace 𝕜 (Fin d)), ∃! i, v (b i) = true :=
fun ⟨v, hv⟩ => noValuation_four.of_le (by norm_num) hd _ (by simp) v hv

end KochenSpecker
Loading
Loading