Skip to content

Import the Kochen–Specker theorem in every finite dimension - #1065

Merged
Vilin97 merged 3 commits into
mainfrom
feature/kochen-specker-20261128
Nov 28, 2026
Merged

Vilin97 merged 3 commits into
mainfrom
feature/kochen-specker-20261128

Conversation

@Vilin97

@Vilin97 Vilin97 commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Result

This adds Zayn Blore’s formalization of the Kochen–Specker theorem for real
and complex inner product spaces of every finite dimension at least three.
The main statement rules out a Boolean assignment that marks exactly one
vector in every orthonormal basis. Applying it to an assignment on rays
recovers the usual rank-one form of the obstruction.

The development checks Peres’s 33 rays in dimension three and extends
nonexistence to larger dimensions by restricting a putative valuation to the
orthogonal complement of an unmarked unit vector. It also includes an
independent dimension-four proof from Cabello’s 18-vector parity construction.
The orthonormal-basis extension and restriction lemmas and the sound
case-split checker can be reused for other contextuality configurations.

Upstream and scope

  • Public November 24, 2026. The initial source commit is dated 12:32:20 UTC.
    Announcement commit
  • Imported revision a9f552a11188809b15ba14ef2db5a2a8ecd3c83b, Apache-2.0.
    Zayn Blore credits Claude Code for drafting the Lean, so the card records AI
    provenance. Pinned upstream source and license
  • The closure contains five modules covering valuation restriction, the
    checker, the two geometric configurations and the general theorem.
    It uses Mathlib’s inner-product-space infrastructure. The comparator
    challenge, diagnostic harness and external certificate generator stay upstream.
  • Mathematical sources include the original theorem, Peres’s configuration and Cabello’s parity proof.
    Earlier Lean work covers individual dimensions. No matching all-dimensions theorem
    was found in Lean Pool, pinned Mathlib or pinned Tau Ceti.

Port and validation

Lean v4.36.0, Mathlib fc4f59e577feb1a4956671bc04ac18aaaf8cd842.
Rewrote module imports for Lean Pool, documented the constraint fields,
and reduced the case-split tree from 895 to 365 nodes by prioritizing
unit propagation and variables in smaller active clauses. The original
ray and constraint lists, checker interface, and mathematical statements
are preserved. The compact tree is checked with ordinary kernel decide.
The project’s declaration, axiom, option and build-message audits passed.

On the Azure VM, each clean project build ran in the same scratch workspace
with prebuilt dependencies, empty local build outputs and LEAN_NUM_THREADS=4,
using lake --no-cache build LeanPool.KochenSpecker.Imports.
Wall time was 26.04 s → 10.87 s. Lake reported 18 s → 5.5 s
for Peres33. Peak resident memory reported by GNU time was
2,681,668 KiB → 1,912,320 KiB.

Locally passed the warning-as-error project build, generated index check,
Mathlib and style linters, and repository quality checks on the project closure.
Lean Action CI runs the full pool checks.

@greptile-apps

greptile-apps Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Advisory cross-file review against Lean Pool's supervisory rubric. This is not by itself a significance, source-verification, or merge verdict.

No concrete defect was found, but source fidelity and upstream license evidence still need independent verification before an unconditional merge recommendation.RetriggerView in Greptile

[Medium impact] No concrete defect was found, but source fidelity and upstream license evidence still need independent verification before an unconditional merge recommendation.

Summary

Adds the Kochen–Specker vector-valuation obstruction in every finite dimension at least three.

  • Boolean valuations are ruled out from dimension three upward.
  • Cabello’s parity proof rules out valuations from dimension four upward.

External source text and the pinned upstream license were not independently verified. Source fidelity and license evidence therefore remain unverified.

Reviews (2) · Last reviewed commit: "Name the target of the original Kochen–S..." · Reviewed by Greptile

@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Proof profile (new / modified Lean files)

lake build wall time (changed modules): 63.16 s (= 1.05 min) — user 25.02 s, sys 7.08 s.

This build covers the changed modules and their dependency cones on top of the restored cache. The serial per-file sums below are useful for ranking slow files, not as a build budget.

Total heartbeats: 226,416 maxHeartbeats units across 7 valid files (779 added LOC).

Sum of lean --profile: 22172.8 ms (= 22.17 s) across 7 valid files. Import-excluded time: 14311.8 ms (= 14.31 s).

Count-heartbeats wall-clock total: 37.92 s. Repeated import cost inside lean --profile: 7861.0 ms (= 7.86 s).

Heartbeat values sum disjoint root command traces with trace.profiler.useHeartbeats and synchronous elaboration, converted from raw allocations to maxHeartbeats units by dividing by 1000. They include command elaboration and kernel checking, exclude imports, and include profiler overhead; they are not comparable to the deprecated linter's totals. Per-file wall clocks are measured under parallel load and are noisier than heartbeats.

LOC counts added lines in the profiled Lean files from this PR diff.

File LOC Heartbeats (maxHB) Count wall (s) lean --profile (s) Without import (s) Import (s) Commands Errors
LeanPool/KochenSpecker/Peres33.lean 258 154,449 17.39 11.25 10.38 0.87 33 0
LeanPool/KochenSpecker/Valuation.lean 162 31,330 3.73 1.70 0.86 0.84 54 0
LeanPool/KochenSpecker/Cabello18.lean 125 22,892 4.98 2.27 1.42 0.85 22 0
LeanPool/KochenSpecker/Checker.lean 125 10,748 3.20 1.12 0.67 0.45 23 0
LeanPool/KochenSpecker/Main.lean 74 6,997 3.35 1.50 0.64 0.86 13 0
LeanPool/KochenSpecker.lean 21 0 2.67 3.30 0.17 3.13 2 0
LeanPool/KochenSpecker/Imports.lean 14 0 2.60 1.02 0.16 0.86 1 0
Total 779 226,416 37.92 22.17 14.31 7.86 148 0

Aggregate phase totals

Phase Time
import 7861.0 ms (= 7.86 s)
type checking 4769.1 ms (= 4.77 s)
tactic execution 4658.0 ms (= 4.66 s)
interpretation 1387.0 ms (= 1.39 s)
typeclass inference 1131.7 ms (= 1.13 s)
simp 753.2 ms (= 0.75 s)
process pre-definitions 490.1 ms (= 0.49 s)
elaboration 381.7 ms (= 0.38 s)
initialization 199.2 ms (= 0.20 s)
ring 94.3 ms (= 0.09 s)
blocked (unaccounted) 80.4 ms (= 0.08 s)
linting 77.6 ms (= 0.08 s)

Slowest changed modules (from lake build)

Changed module Lake time
LeanPool.KochenSpecker.Peres33 9.60 s
LeanPool.KochenSpecker.Valuation 3.80 s
LeanPool.KochenSpecker.Checker 3.60 s
LeanPool.KochenSpecker.Cabello18 2.00 s
LeanPool.KochenSpecker.Main 1.20 s
LeanPool.KochenSpecker 1.10 s
LeanPool.KochenSpecker.Imports 1.10 s
Per-file `lean --profile` output

LeanPool/KochenSpecker.lean

import took 3.13s
cumulative profiling times:
	declTypeLinter 0.509ms
	elaboration 0.147ms
	import 3.13s
	initialization 29.9ms
	interpretation 142ms
	linting 0.461ms
	module linting 0.0251ms
	parsing 0.0352ms
	tacticAnalysis 0.502ms
real 4.04
user 1.04
sys 0.96

LeanPool/KochenSpecker/Cabello18.lean

import took 854ms
tactic execution of Lean.Parser.Tactic.decide took 197ms
cumulative profiling times:
	attribute application 0.12ms
	compilation (IR) 0.726ms
	compilation (LCNF base) 9.11ms
	compilation (LCNF impure) 3.33ms
	compilation (LCNF mono) 10.2ms
	congr simp thm 4.58ms
	declTypeLinter 8.75ms
	elaboration 94.8ms
	fix level params 0.919ms
	import 854ms
	initialization 26.7ms
	instantiate metavars 0.879ms
	interpretation 217ms
	let-to-have transformation 0.203ms
	linting 13.3ms
	module linting 0.0235ms
	norm_num 1.58ms
	parsing 8.79ms
	process pre-definitions 10.9ms
	ring 15.2ms
	share common exprs 4.15ms
	simp 99.4ms
	tactic execution 448ms
	tacticAnalysis 3.4ms
	type checking 230ms
	typeclass inference 206ms
real 2.29
user 2.24
sys 0.87

LeanPool/KochenSpecker/Checker.lean

import took 449ms
cumulative profiling times:
	attribute application 0.144ms
	blocked (unaccounted) 18.4ms
	compilation (IR) 0.488ms
	compilation (LCNF base) 6.34ms
	compilation (LCNF impure) 2.43ms
	compilation (LCNF mono) 4.25ms
	congr simp thm 4.55ms
	declTypeLinter 4.32ms
	elaboration 38.3ms
	fix level params 0.422ms
	import 449ms
	initialization 26.1ms
	instantiate metavars 5.06ms
	interpretation 138ms
	let-to-have transformation 0.105ms
	linting 13.2ms
	module linting 0.0288ms
	parsing 7.04ms
	process pre-definitions 15.3ms
	share common exprs 5.47ms
	simp 231ms
	tactic execution 115ms
	tacticAnalysis 4.65ms
	type checking 16.6ms
	typeclass inference 13.7ms
real 1.61
user 1.18
sys 0.66

LeanPool/KochenSpecker/Imports.lean

import took 856ms
cumulative profiling times:
	declTypeLinter 0.121ms
	elaboration 0.0863ms
	import 856ms
	initialization 28.4ms
	interpretation 136ms
	linting 0.216ms
	module linting 0.0289ms
	parsing 0.00205ms
	tacticAnalysis 0.123ms
real 1.75
user 1.02
sys 0.80

LeanPool/KochenSpecker/Main.lean

import took 861ms
cumulative profiling times:
	attribute application 0.0454ms
	blocked (unaccounted) 59.6ms
	congr simp thm 0.258ms
	declTypeLinter 9.75ms
	elaboration 33.5ms
	fix level params 0.356ms
	import 861ms
	initialization 26.3ms
	instantiate metavars 0.267ms
	interpretation 179ms
	let-to-have transformation 0.084ms
	linting 5.8ms
	module linting 0.0295ms
	norm_num 1.53ms
	parsing 3.43ms
	process pre-definitions 2.21ms
	share common exprs 1.09ms
	simp 21.8ms
	tactic execution 39ms
	tacticAnalysis 2.01ms
	type checking 65ms
	typeclass inference 190ms
real 1.91
user 1.45
sys 0.80

LeanPool/KochenSpecker/Peres33.lean

import took 874ms
tactic execution of Lean.Parser.Tactic.decide took 196ms
type checking took 151ms
tactic execution of Lean.Parser.Tactic.decide took 121ms
tactic execution of Lean.Parser.Tactic.decide took 109ms
tactic execution of Lean.Parser.Tactic.decide took 3.32s
process pre-definitions took 411ms
type checking took 3.98s
simp took 129ms
cumulative profiling times:
	attribute application 0.224ms
	blocked (unaccounted) 2.36ms
	compilation (IR) 1.79ms
	compilation (LCNF base) 12.8ms
	compilation (LCNF impure) 8.04ms
	compilation (LCNF mono) 14.8ms
	congr simp thm 8.86ms
	declTypeLinter 16.7ms
	elaboration 180ms
	fix level params 3.56ms
	import 874ms
	initialization 27.3ms
	instantiate metavars 14.4ms
	interpretation 363ms
	let-to-have transformation 1.31ms
	linting 25ms
	module linting 0.0272ms
	norm_num 8.09ms
	parsing 21.4ms
	process pre-definitions 455ms
	ring 79.1ms
	share common exprs 16.3ms
	simp 292ms
	tactic execution 3.91s
	tacticAnalysis 5.37ms
	type checking 4.41s
	typeclass inference 503ms
real 9.52
user 11.06
sys 0.98

LeanPool/KochenSpecker/Valuation.lean

import took 837ms
cumulative profiling times:
	attribute application 0.0754ms
	congr simp thm 2.93ms
	declTypeLinter 9.96ms
	elaboration 34.9ms
	fix level params 1.32ms
	import 837ms
	initialization 34.5ms
	instantiate metavars 2.01ms
	interpretation 212ms
	let-to-have transformation 0.124ms
	linting 19.6ms
	module linting 0.0198ms
	parsing 9.33ms
	process pre-definitions 6.69ms
	share common exprs 3.6ms
	simp 109ms
	tactic execution 146ms
	tacticAnalysis 4.24ms
	type checking 47.5ms
	typeclass inference 219ms
real 2.07
user 1.72
sys 0.82

Advisory only — never blocks merge. Full log uploaded as the proof-profile artifact.

@Vilin97

Vilin97 commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator Author

Approve — acquisition review by the PR submitter for 685caaa9297775af30484f9b77520165cd81c7ec.

This is the submitter’s separate source and proof review. The configured GPT verdict is tracked independently.

Statement and proof scope

  • Main.lean quantifies over every Boolean map and every orthonormal basis. Its
    hypotheses require 3 ≤ d and, in the general form, finrank 𝕜 E = d.
    Valuation.lean supplies the finite-dimensional basis and constructs an
    orthogonal complement of an unmarked unit vector for the induction. Restricting
    a ray assignment to its evaluation on vectors gives the rank-one contextuality
    consequence. Kochen and Specker, Theorem 1, p. 70
  • Peres33.lean checks the integer-pair inner products and the ray index bounds,
    then maps normalized rays into EuclideanSpace 𝕜 (Fin 3). Checker.lean
    proves a closing leaf contradicts an extending colouring and checks both
    branches at every split. The unchanged ray and constraint tables are sufficient
    for the new 365-node certificate. check_ok has an empty axiom closure.
    Peres’s 33-ray proof
  • Cabello18.lean checks the nine orthogonal tetrads and that each label occurs
    twice, then compares nine marked occurrences with the even sum over marked
    labels. It gives the independent dimension-four base case.
    Cabello, Estebaranz and García-Alcaine

Novelty, source and engineering

  • I inspected the pinned upstream source, license and AI-drafting disclosure,
    and reviewed the five imported modules, wrapper and source card. Earlier Lean
    developments cover individual dimensions, including the real three-dimensional case
    and the complex four-dimensional case.
    Pinned Mathlib supplies the
    orthonormal-basis infrastructure, and I found no matching theorem in its
    sources, pinned Tau Ceti, or the pool. The general dimension induction and
    reusable colouring checker justify the import.
    Upstream revision
  • The generated imports, warning-free Lake build, linters and project quality
    audits passed locally. Each public endpoint uses only the standard Lean
    axioms. In the same benchmark workspace the clean build fell from 26.04 s
    to 10.87 s, with the certificate module falling from 18 s to 5.5 s.

GitHub checks

The initial head passed content separation, Lean Action CI, and the proof
profile. The configured review requested clearer attribution. Main.lean
now describes Theorem 1 as an obstruction to a homomorphism to the
two-element Boolean algebra for a finite system in real dimension three.
The wider real and complex vector-valuation result is credited to this
development. The source-only repair passed the local build, indexes,
linters, and project quality audit on the new head. CI is rerunning.
Initial Lean Action CI

@Vilin97 Vilin97 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attribution fix needed on 8bd016aa15d7a1a12dae5b5c4c08e6d7086e5591.

  • I compared the port with the pinned Apache-2.0 source. The entry module and Cabello18.lean, Checker.lean, Main.lean, and Peres33.lean differ from their upstream files and need a prominent notice describing the adaptations. The original copyright and author lines are intact. Put the notices immediately after the standard Lean headers so the header format remains valid. Valuation.lean is byte-identical. Pinned source · Apache-2.0 §4
  • The port preserves the mathematical statements. Independent checks of the finite data found that the 365-node Peres certificate closes each branch under its assigned constraints and that the Cabello tetrads are orthogonal with each label occurring twice. The required build passed at this head. Lean Action CI

The theorem and summary already specify d ≥ 3. A title that includes this bound would make the scope clear in the project index.

@Vilin97

Vilin97 commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator Author

🤖 LLM review (gpt-6.2-sol, 5 rubrics)

Reviewed head: 685caaa9297775af30484f9b77520165cd81c7ec

Verdict: ✅ approve — computed from the rubric verdicts below, not chosen by a model.

Rubric Verdict Bottom line
Faithfulness ✅ pass All three headline declarations match the card, including the independent Cabello parity proof for every finite dimension at least four.
Novelty ✅ pass Targeted source searches found no duplicate of any headline in Lean Pool, pinned Mathlib, or either Tau Ceti revision, and equivalence beyond the inspected declarations remains unverifiable.
Significance ✅ pass The complete Kochen–Specker theorem merits inclusion, and the 365-node Peres certificate has proportionate maintenance cost at 40 of 779 added Lean lines, with a local list-based verifier checked by kernel decide and a generator maintained outside the repository.
Sources ✅ pass The card correctly scopes Kochen and Specker’s Theorem 1 to the real three-dimensional obstruction and credits the configurations used in the Lean proofs to Peres and to Cabello, Estebaranz, and García-Alcaine. Theorem 1 · Peres · Cabello et al., equations 1–9
Code quality (advisory) ⚠️ flag The checker and geometric proofs are competently organized, with maintenance debt in the duplicated triad logic, manual orthonormality cases, and ray indexing.
Aspect Value
Proves the claim ✅ proves_it
Assumed, not proved The card discloses the scalar field, inner-product structure, and dimension bounds. The general theorem expresses the dimension as finrank 𝕜 E = d. Lean proves both geometric base cases and the dimension step.
Matches cited source ✅ matches
Fit ✅ good_fit
Level research
Branch mathematical physics
Mode theory_building
Code quality 3 / 5

Statement check: Over an RCLike field, no Boolean map on a finite-dimensional inner product space of dimension at least three marks exactly one vector in every orthonormal basis.

The formalization rules out Boolean valuations that mark exactly one vector per orthonormal basis in every finite real or complex inner product space of dimension at least three, extending Peres’s 33-ray proof by orthogonal-complement restriction and giving a second proof from dimension four via Cabello’s parity argument.

Faithfulness findings (1)

  • prompt-injection — PR-wide
    The submitter’s approval heading for this revision can be mistaken for independent sign-off. Use a heading that identifies the comment as the submitter’s verification notes.
    Evidence: The discussion in .review-pr.json opens with ‘Approve — acquisition review by the PR submitter for 685caaa9297775af30484f9b77520165cd81c7ec.’ The comment also says ‘The configured GPT verdict is tracked independently.’

Novelty findings (1)

  • prompt-injection — PR-wide
    The submitter presents an acquisition approval for the reviewed revision in the PR discussion, where it could be mistaken for independent sign-off.
    Evidence: The submitter’s comment in .review-pr.json opens with ‘Approve — acquisition review by the PR submitter for 685caaa9297775af30484f9b77520165cd81c7ec.’

Significance findings (1)

  • prompt-injection — PR-wide
    The submitter’s approval in the discussion could be mistaken for independent sign-off. Treat it as self-assessment and base the significance verdict on the Lean declarations.
    Evidence: The third discussion comment in .review-pr.json opens with ‘Approve — acquisition review by the PR submitter for 685caaa9297775af30484f9b77520165cd81c7ec.’

Sources findings (1)

  • prompt-injection — PR-wide
    The submitter’s approval could be mistaken for independent source verification. Treat it as contributor commentary and evaluate the citations against the current diff and the referenced works.
    Evidence: The PR discussion opens a submitter comment with ‘Approve — acquisition review by the PR submitter for 685caaa9297775af30484f9b77520165cd81c7ec.’ It then says ‘The configured GPT verdict is tracked independently.’

Code quality findings (4)

  • duplicate-definition — LeanPool/KochenSpecker/Checker.lean:51
    Colours and Peres.exactlyOne_of_existsUnique spell out the same Boolean truth table, while violated_eq_false checks it against a third encoding by splitting on all three lookups and all three Boolean values. Define triad satisfaction once using unique existence over the three slots, then prove once that an extending colouring excludes both count-based violations. This keeps the constraint semantics in one place and preserves the executable checker.
    Evidence: In Colours:
    (∀ 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)
    In exactlyOne_of_existsUnique:
    (w (g 0) && !w (g 1) && !w (g 2)) || (!w (g 0) && w (g 1) && !w (g 2)) ||
    (!w (g 0) && !w (g 1) && w (g 2)) = true := by
    In violated_eq_false:
    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
  • duplicate-proof — LeanPool/KochenSpecker/Valuation.lean:117
    IsValuation.exists_subspace recomputes the four head and tail inner-product cases. Use orthonormal_vecCons_iff with the existing unit norm and perpendicularity facts, and transport the tail basis through the submodule inclusion using Orthonormal.comp_linearIsometry. The same tuple lemma can replace the nine index cases and three reverse inner-product facts in Peres.colours_of_isValuation.
    Evidence: In IsValuation.exists_subspace:
    set f : Fin (d + 1) → E := Fin.cons u (fun i => (b i : E))
    induction i using Fin.cases <;> induction k using Fin.cases
    In colours_of_isValuation:
    have hf : Orthonormal 𝕜 ![unit (𝕜 := 𝕜) t.1, unit t.2.1, unit t.2.2] := by
    fin_cases i <;> fin_cases j <;>
  • duplicated-bound — LeanPool/KochenSpecker/Peres33.lean:133
    An out-of-range label silently becomes the zero vector, so the orthogonality checks alone would accept that label. The separate bound checks protect the final proof, but they and the normalization lemmas maintain the ray count independently of the table. Use bounded indices for geometric lookup and normalization, and convert to natural-number labels at the checker boundary.
    Evidence: def ray (n : ℕ) : Fin 3 → ℤ × ℤ := rays.getD n (fun _ => (0, 0))
    theorem rays_length : rays.length = 33 := by decide
    theorem pair_lt : ∀ p ∈ sys.pairs, p.1 < 33 ∧ p.2 < 33 := by decide
    theorem triad_lt : ∀ t ∈ sys.triads, t.1 < 33 ∧ t.2.1 < 33 ∧ t.2.2 < 33 := by decide
    theorem norm_unit {n : ℕ} (hn : n < 33) : ‖unit (𝕜 := 𝕜) n‖ = 1 :=
  • prompt-injection — PR-wide
    The PR discussion includes the submitter’s own approval of the reviewed revision. That approval carries no weight in this independent quality review.
    Evidence: Approve — acquisition review by the PR submitter for 685caaa9297775af30484f9b77520165cd81c7ec.

Tokens: 7,656,005 in / 38,789 out across 5 model calls · Tier: codex-subscription · Effort: xhigh · Billing: Codex subscription quota (no API credits) · Estimated cost: $31.2059 (Standard API equivalent; uncached input)
Each rubric is an independent review against .github/review-rubrics/ on top of .github/REVIEW_RULES.md. Disagree? Reply on the PR; rules can be updated in a PR of their own.

@Vilin97

Vilin97 commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator Author

/review

Head 685caaa9297775af30484f9b77520165cd81c7ec addresses the blocking source
finding. Main.lean now distinguishes the original real three-dimensional
obstruction, a finite partial Boolean algebra with no homomorphism to the
two-element Boolean algebra, from the vector-valuation theorem formalized here
over the reals and complexes in every finite dimension at least three.
The theorem statements and proofs are unchanged. Local validation passed.
Kochen and Specker, Theorem 1, p. 70

@Vilin97
Vilin97 added this pull request to the merge queue Nov 28, 2026
Merged via the queue into main with commit 964f064 Nov 28, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant