The graph , PC paths, and
DefinitionRhoMin_DefsLet be a permutation of ; a position carries the value . The graph on has two kinds of edges.
- P-edges: and are P-adjacent when they are consecutive positions, .
- V-edges: and are V-adjacent when their values are consecutive, .
A colour is a Boolean: false for P and true for V. A sequence of vertices alternates with first colour if its consecutive vertices are adjacent in colours in this order. A PC path (properly coloured path) is a sequence of distinct vertices that alternates for some first colour. Then
These are the objects of the whole mission: every statement about properly coloured paths in the union of two Hamiltonian paths is expressed through them.
Formalization Note A permutation is a term of Equiv.Perm (Fin n) and a path is a List (Fin n). A pair of vertices carrying both a P-edge and a V-edge can be used in either colour. The empty list and every one-vertex list are PC paths, so exactly when . is Nat.findGreatest over lengths ; the file contains an explicit enumeration pcs of alternating repetition-free lists of each length, with its correctness lemma, which makes computable. is the minimum of over the finite nonempty set of all permutations of Fin n.
import Mathlib.Data.Fintype.Perm
import Mathlib.Data.Fintype.Card
import Mathlib.Data.List.Nodup
import Mathlib.Data.Nat.Find
import Mathlib.Data.List.FinRange
import Mathlib.Data.Finset.Lattice.Fold
namespace RhoMin
variable {n : ℕ}
/-- P-edge: consecutive positions. -/
def PAdj (u v : Fin n) : Prop := u.val + 1 = v.val ∨ v.val + 1 = u.val
/-- V-edge: consecutive values, i.e. `{u, v} = {σ⁻¹ w, σ⁻¹ (w + 1)}` for some `w`. -/
def VAdj (σ : Equiv.Perm (Fin n)) (u v : Fin n) : Prop :=
(σ u).val + 1 = (σ v).val ∨ (σ v).val + 1 = (σ u).val
/-- Edges of colour `c`: `false` = P (position path), `true` = V (value path). -/
def Adj (σ : Equiv.Perm (Fin n)) : Bool → Fin n → Fin n → Prop
| false => PAdj
| true => VAdj σ
instance (u v : Fin n) : Decidable (PAdj u v) := by unfold PAdj; infer_instance
instance (σ : Equiv.Perm (Fin n)) (u v : Fin n) : Decidable (VAdj σ u v) := by
unfold VAdj; infer_instance
instance (σ : Equiv.Perm (Fin n)) (c : Bool) (u v : Fin n) : Decidable (Adj σ c u v) := by
cases c <;> unfold Adj <;> infer_instance
/-- `Alt σ c l`: the steps of `l` are edges of colours `c, !c, c, …`. -/
def Alt (σ : Equiv.Perm (Fin n)) : Bool → List (Fin n) → Prop
| _, [] => True
| _, [_] => True
| c, u :: v :: l => Adj σ c u v ∧ Alt σ (!c) (v :: l)
/-- A PC (properly coloured) path: distinct vertices, consecutive ones adjacent, colours alternating. -/
def IsPC (σ : Equiv.Perm (Fin n)) (l : List (Fin n)) : Prop := l.Nodup ∧ ∃ c, Alt σ c l
/-- Enumeration of all `(c, l)` with `Alt σ c l`, `l.Nodup`, `l.length = k` (paths grown at the head). -/
def pcs (σ : Equiv.Perm (Fin n)) : ℕ → List (Bool × List (Fin n))
| 0 => [(false, []), (true, [])]
| 1 => (List.finRange n).flatMap fun v => [(false, [v]), (true, [v])]
| k + 2 => (pcs σ (k + 1)).flatMap fun p =>
match p.2 with
| [] => []
| v :: _ => ((List.finRange n).filter fun u => decide (u ∉ p.2 ∧ Adj σ (!p.1) u v)).map
fun u => (!p.1, u :: p.2)
theorem mem_pcs (σ : Equiv.Perm (Fin n)) :
∀ k c l, (c, l) ∈ pcs σ k ↔ Alt σ c l ∧ l.Nodup ∧ l.length = k
| 0, c, l => by
cases c <;> cases l <;> simp [pcs, Alt]
| 1, c, l => by
rcases l with _ | ⟨v, _ | ⟨w, l⟩⟩ <;> cases c <;> simp [pcs, Alt]
| k + 2, c, l => by
constructor
· intro h
simp only [pcs, List.mem_flatMap] at h
obtain ⟨⟨c0, l0⟩, h0, h1⟩ := h
rw [mem_pcs σ (k + 1)] at h0
obtain ⟨ha, hnd, hlen⟩ := h0
rcases l0 with _ | ⟨v, rest⟩
· simp at hlen
· simp only [List.mem_map, List.mem_filter, List.mem_finRange, true_and,
decide_eq_true_eq] at h1
obtain ⟨u, ⟨hu, hadj⟩, he⟩ := h1
simp only [Prod.mk.injEq] at he
obtain ⟨rfl, rfl⟩ := he
refine ⟨⟨hadj, by simpa using ha⟩, List.nodup_cons.2 ⟨hu, hnd⟩, by simp at hlen ⊢; omega⟩
· rintro ⟨ha, hnd, hlen⟩
rcases l with _ | ⟨u, _ | ⟨v, rest⟩⟩
· simp at hlen
· simp at hlen
· simp only [pcs, List.mem_flatMap]
refine ⟨(!c, v :: rest), ?_, ?_⟩
· rw [mem_pcs σ (k + 1)]
exact ⟨ha.2, (List.nodup_cons.1 hnd).2, by simp at hlen ⊢; omega⟩
· simp only [Bool.not_not, List.mem_map, List.mem_filter, List.mem_finRange, true_and,
decide_eq_true_eq]
exact ⟨u, ⟨(List.nodup_cons.1 hnd).1, ha.1⟩, rfl⟩
theorem exists_pc_iff (σ : Equiv.Perm (Fin n)) (k : ℕ) :
(∃ l, IsPC σ l ∧ l.length = k) ↔ pcs σ k ≠ [] := by
constructor
· rintro ⟨l, ⟨hnd, c, ha⟩, hlen⟩ h
have := (mem_pcs σ k c l).2 ⟨ha, hnd, hlen⟩
simp [h] at this
· intro h
obtain ⟨⟨c, l⟩, hm⟩ := List.exists_mem_of_ne_nil _ h
obtain ⟨ha, hnd, hlen⟩ := (mem_pcs σ k c l).1 hm
exact ⟨l, ⟨hnd, c, ha⟩, hlen⟩
instance (σ : Equiv.Perm (Fin n)) : DecidablePred (fun k => ∃ l, IsPC σ l ∧ l.length = k) :=
fun k => decidable_of_iff _ (exists_pc_iff σ k).symm
/-- ρ(σ): the largest number of vertices of a PC path of H_σ. -/
def rho (σ : Equiv.Perm (Fin n)) : ℕ :=
Nat.findGreatest (fun k => ∃ l, IsPC σ l ∧ l.length = k) n
/-- ρ_min(n): the minimum of ρ over all permutations of `Fin n`. -/
def rhoMin (n : ℕ) : ℕ :=
(Finset.univ : Finset (Equiv.Perm (Fin n))).inf' Finset.univ_nonempty rho
end RhoMin
Read-back
What the Lean code literally says, in plain math · claude-fable-5-2
Throughout, is a natural number ( is allowed), denotes the type of natural numbers strictly less than (empty when ), and a "permutation of " is a bijection . In every declaration below except the last one, is an implicit parameter. "List" means a finite sequence, possibly empty, possibly with repetitions unless stated otherwise.
Definition PAdj (relation ). For , the proposition holds if and only if, as natural numbers,
No permutation is involved. The relation is symmetric and never holds for . For it never holds.
Definition VAdj (relation ). For a permutation of and , the proposition holds if and only if, as natural numbers,
The relation is symmetric and never holds for .
Definition Adj (relation ). For a permutation of and a Boolean , this is a binary relation on :
For the permutation is ignored. The two relations are not required to be disjoint: a pair may satisfy both and .
Three unnamed instances (decidability). They assert that each of the propositions (for all ), (for all permutations of and all ), and (for all permutations , Booleans , and ) is algorithmically decidable. They carry no further mathematical content.
Definition Alt (predicate ). For a permutation of , a Boolean , and a list of elements of , the proposition is defined by recursion on :
- if is empty, it is true (for either value of );
- if has exactly one element, it is true (for either value of );
- if has at least two elements, it holds if and only if holds and holds, where is with its first element removed.
Unfolded: for , holds if and only if for every index with , the pair satisfies when is even and when is odd. The definition does not require the entries of to be distinct. It requires only that step satisfy the relation of the prescribed kind; it does not forbid that step from also satisfying the other relation.
Definition IsPC (predicate ). For a permutation of and a list of elements of , holds if and only if
The empty list and every one-element list satisfy . The starting Boolean is existentially quantified, so the first step may be of either kind.
Definition pcs (the lists ). For a permutation of and a natural number , is a finite list of pairs , with a Boolean and a list of elements of , defined by recursion on :
- is the two-element list , where is the empty list;
- is obtained by going through in increasing order and contributing, for each , the two pairs and in that order (so it is empty when );
- is obtained by going through the pairs of in order and, for each: contributing nothing if is empty; and if has first element , contributing, for each in increasing order such that is not an entry of and holds, the pair .
Theorem mem_pcs. For every permutation of , every natural number , every Boolean , and every list of elements of :
The file contains a proof of this statement.
Theorem exists_pc_iff. For every permutation of and every natural number :
The file contains a proof of this statement.
Unnamed instance (decidability). For every permutation of , the predicate on natural numbers is algorithmically decidable; the decision is made by testing whether is non-empty, via the previous theorem.
Definition rho (). For a permutation of , is the natural number
defined to be if no has the property. Here "length" is the number of entries of the list (the number of vertices, not the number of steps). The search is capped at ; a list of elements of without repeated entries has length at most in any case. Since the empty list satisfies , the value always has the property, so the fallback value coincides with the maximum. For , ; for , one-element lists give .
Definition rhoMin (). For a natural number (here an explicit argument),
the minimum of over all permutations of . The set of permutations is finite and non-empty (it contains the identity, also when , where it is the unique permutation of the empty type), so the minimum is taken over a non-empty finite set. For the value is .