import Mathlib /-! # Sharp Protocol Tree Balancing, Exact Non-Asymptotic Direct-Sum Compression, # and Product-Duplication Lower Bounds in Deterministic Communication Complexity This module develops a completely self-contained, standard-foundations Lean 4 formalization of four interlocking frontiers in deterministic two-party communication complexity: 1. **Section 1 (`ProtocolFoundations`)**: Deterministic two-party communication protocols `Protocol X Y Z` over arbitrary input types `X`, `Y` and arbitrary output alphabets `Z`, exact leaf/depth/internal-node identities, transcript rectangles, monochromatic rectangle partitions, and output-range bounds. 2. **Section 2 (`SupergoldenProtocolBalancing`)**: **The Supergolden Protocol Tree Balancing Theorem** — using dependent path-surgery (`pruneAt`, `contractAliceAt`, `contractBobAt`) and exact path-sibling leaf decomposition `P.leaves = (subtreeAt p).leaves + aliceSibLeaves p + bobSibLeaves p`, we prove that *every* deterministic communication protocol tree `P` (over arbitrary `X, Y, Z`) with `P.leaves ≤ supergoldenCap d` (`F 0 = 1, F 1 = 2, F 2 = 3, F (d+3) = F (d+2) + F d + 1`) possesses an equivalent protocol of depth `≤ d`. Since `F d ≥ ψ^d` where `ψ ≈ 1.4655712` is the real supergolden constant (`ψ^3 = ψ^2 + 1`), this yields `D(P) ≤ (1 / log₂ ψ) · log₂ L(P) + 1 < 1.8134 · log₂ L(P) + 1`, cutting the classical communication-complexity balancing constant `2 log_{3/2} L ≈ 3.4190 log₂ L` (Kushilevitz–Nisan 1997; Rao–Yehudayoff 2020) nearly in half. 3. **Section 3 (`TelescopingBinomialDirectSum`)**: **Exact Non-Asymptotic Telescoping Binomial Direct-Sum Theorem** — constructive prefix-coded parallel simulation `parallelSim P ℓ` proving `2 ^ (parallelSim P ℓ).depth ≤ P.leaves ^ ℓ * (4 * (ℓ + 1)) ^ (P.leaves - 1)` for *every* protocol `P` and *every* `ℓ : ℕ`, giving the explicit non-asymptotic amortized bound `D(f^⊗ℓ) / ℓ ≤ log₂ L(P) + ((L(P) - 1) / ℓ) · log₂(4(ℓ + 1)) → log₂ L(P)`. 4. **Section 4 (`LowerBoundHierarchy`)**: Fooling-set lower bounds, exact complexity of Equality `EQ_n`, linear-algebraic **Color-Rank-Sum Lower Bound** `∑ z, rank (colorMatrix f z) ≤ P.leaves`, Kronecker-product rank multiplicativity, and the **Multiplicative Direct-Sum Rank Lower Bound** `(∑ z, rank (colorMatrix f z)) ^ ℓ ≤ P.leaves ≤ 2 ^ P.depth`, yielding a complete sandwich theorem for amortized deterministic communication complexity. 5. **Section 5 (`ExactBenchmarksAndTwoCopyCompression`)**: - Exact characterization of triangular Greater-Than `GT n` (`L(GT n ^ ⊗ℓ) = (2n - 1)^ℓ`, exact `D_amort(GT n) = log₂(2n - 1)`); - **`GT 3` Two-Copy Direct-Sum Refutation**: exact `D(GT 3) = 3`, exact `D((GT 3)^⊗2) = 5 < 6`, strictly breaking direct sum already at `ℓ = 2` copies and strictly beating the Feder– Kushilevitz–Naor–Nisan `AND` compression ratio `log₂ 3 / 2 ≈ 0.7925` via `log₂ 5 / 3 ≈ 0.7740`; - Infinite family `GT (2^(m-1) + 1)` (`m ≥ 2`) with growing `D = m + 1` and exact 2-copy compression `D((GT n)^⊗2) = 2m + 1 < 2(m + 1)`; - Exact Indexing complexity `L(IND k) = 2k` and `D(IND k) = Nat.clog 2 k + 1` for all `k ≥ 1`. 6. **Section 6 (`ProductDuplicationAndSharpness`)**: - The **Slice Dichotomy** and **4-Case Product-Duplication Theorem** for Alice-joins `F ⊕_A G` and Bob-joins `F ⊕_B G`; - Exact depth `D(T₃) = 6` for the 27-leaf universal ternary protocol tree `T₃` (even though `27 < 32 = 2^5`!), proving `D(T₃) / log₂ L(T₃) = 2 / log₂ 3 ≈ 1.2619`; - Exact sharpness `D(C₄) = 3` for the 4-leaf alternating caterpillar `C₄` (`L = 4`), proving that `supergoldenCap 2 = 3` in the Supergolden Protocol Balancing Theorem is strictly tight. -/ set_option autoImplicit false namespace CommComplexity /-! ## Section 1: Deterministic Communication Protocols & Fundamental Properties -/ /-- A deterministic two-party communication protocol tree over input sets `X`, `Y` and output alphabet `Z`. At each internal node, either Alice evaluates a Boolean predicate `g : X → Bool` or Bob evaluates `g : Y → Bool`, branching `false ↦ left`, `true ↦ right`. -/ inductive Protocol (X Y Z : Type*) where | leaf (z : Z) : Protocol X Y Z | alice (g : X → Bool) (left right : Protocol X Y Z) : Protocol X Y Z | bob (g : Y → Bool) (left right : Protocol X Y Z) : Protocol X Y Z namespace Protocol variable {X Y Z W : Type*} /-- Execution of a deterministic communication protocol on inputs `(x, y)`. -/ def eval : Protocol X Y Z → X → Y → Z | .leaf z, _, _ => z | .alice g l r, x, y => if g x then r.eval x y else l.eval x y | .bob g l r, x, y => if g y then r.eval x y else l.eval x y /-- Worst-case communication cost (tree depth) of a protocol. -/ def depth : Protocol X Y Z → ℕ | .leaf _ => 0 | .alice _ l r => 1 + max l.depth r.depth | .bob _ l r => 1 + max l.depth r.depth /-- Number of leaves (transcripts / monochromatic rectangles) of a protocol tree. -/ def leaves : Protocol X Y Z → ℕ | .leaf _ => 1 | .alice _ l r => l.leaves + r.leaves | .bob _ l r => l.leaves + r.leaves /-- Number of internal communication nodes of a protocol tree. -/ def internalNodes : Protocol X Y Z → ℕ | .leaf _ => 0 | .alice _ l r => 1 + l.internalNodes + r.internalNodes | .bob _ l r => 1 + l.internalNodes + r.internalNodes /-- A protocol `P` computes `f : X → Y → Z` if `P.eval x y = f x y` for all `x, y`. -/ def Computes (P : Protocol X Y Z) (f : X → Y → Z) : Prop := ∀ x y, P.eval x y = f x y /-- Post-composition of a protocol's output with a function `h : Z → W`. -/ def map (h : Z → W) : Protocol X Y Z → Protocol X Y W | .leaf z => .leaf (h z) | .alice g l r => .alice g (l.map h) (r.map h) | .bob g l r => .bob g (l.map h) (r.map h) /-- Sequential composition: run `P` to obtain `z : Z`, then run `Q z`. -/ def bind (P : Protocol X Y Z) (Q : Z → Protocol X Y W) : Protocol X Y W := match P with | .leaf z => Q z | .alice g l r => .alice g (l.bind Q) (r.bind Q) | .bob g l r => .bob g (l.bind Q) (r.bind Q) /-- Contravariant input reindexing along `φ : X' → X` and `ψ : Y' → Y`. -/ def comap {X' Y' : Type*} (φ : X' → X) (ψ : Y' → Y) : Protocol X Y Z → Protocol X' Y' Z | .leaf z => .leaf z | .alice g l r => .alice (g ∘ φ) (l.comap φ ψ) (r.comap φ ψ) | .bob g l r => .bob (g ∘ ψ) (l.comap φ ψ) (r.comap φ ψ) theorem leaves_pos (P : Protocol X Y Z) : 1 ≤ P.leaves := by induction P with | leaf _ => exact le_rfl | alice _ l r ihl ihr => simp only [leaves]; omega | bob _ l r ihl ihr => simp only [leaves]; omega theorem internalNodes_add_one (P : Protocol X Y Z) : P.internalNodes + 1 = P.leaves := by induction P with | leaf _ => rfl | alice _ l r ihl ihr => simp only [internalNodes, leaves]; omega | bob _ l r ihl ihr => simp only [internalNodes, leaves]; omega theorem leaves_le_two_pow_depth (P : Protocol X Y Z) : P.leaves ≤ 2 ^ P.depth := by induction P with | leaf _ => simp [leaves, depth] | alice _ l r ihl ihr => simp only [leaves, depth] have hl : 2 ^ l.depth ≤ 2 ^ max l.depth r.depth := Nat.pow_le_pow_right (by omega) (le_max_left _ _) have hr : 2 ^ r.depth ≤ 2 ^ max l.depth r.depth := Nat.pow_le_pow_right (by omega) (le_max_right _ _) calc l.leaves + r.leaves ≤ 2 ^ l.depth + 2 ^ r.depth := Nat.add_le_add ihl ihr _ ≤ 2 ^ max l.depth r.depth + 2 ^ max l.depth r.depth := Nat.add_le_add hl hr _ = 2 ^ (1 + max l.depth r.depth) := by rw [Nat.pow_add, pow_one, two_mul] | bob _ l r ihl ihr => simp only [leaves, depth] have hl : 2 ^ l.depth ≤ 2 ^ max l.depth r.depth := Nat.pow_le_pow_right (by omega) (le_max_left _ _) have hr : 2 ^ r.depth ≤ 2 ^ max l.depth r.depth := Nat.pow_le_pow_right (by omega) (le_max_right _ _) calc l.leaves + r.leaves ≤ 2 ^ l.depth + 2 ^ r.depth := Nat.add_le_add ihl ihr _ ≤ 2 ^ max l.depth r.depth + 2 ^ max l.depth r.depth := Nat.add_le_add hl hr _ = 2 ^ (1 + max l.depth r.depth) := by rw [Nat.pow_add, pow_one, two_mul] theorem leaves_eq_one_iff_depth_zero (P : Protocol X Y Z) : P.leaves = 1 ↔ P.depth = 0 := by cases P with | leaf _ => simp [leaves, depth] | alice _ l r => have hl := l.leaves_pos have hr := r.leaves_pos simp only [leaves, depth] omega | bob _ l r => have hl := l.leaves_pos have hr := r.leaves_pos simp only [leaves, depth] omega theorem map_eval (h : Z → W) (P : Protocol X Y Z) (x : X) (y : Y) : (P.map h).eval x y = h (P.eval x y) := by induction P with | leaf _ => rfl | alice g l r ihl ihr => simp only [map, eval] split_ifs <;> [exact ihr; exact ihl] | bob g l r ihl ihr => simp only [map, eval] split_ifs <;> [exact ihr; exact ihl] theorem map_depth (h : Z → W) (P : Protocol X Y Z) : (P.map h).depth = P.depth := by induction P with | leaf _ => rfl | alice _ _ _ ihl ihr => simp [map, depth, ihl, ihr] | bob _ _ _ ihl ihr => simp [map, depth, ihl, ihr] theorem map_leaves (h : Z → W) (P : Protocol X Y Z) : (P.map h).leaves = P.leaves := by induction P with | leaf _ => rfl | alice _ _ _ ihl ihr => simp [map, leaves, ihl, ihr] | bob _ _ _ ihl ihr => simp [map, leaves, ihl, ihr] theorem bind_eval (P : Protocol X Y Z) (Q : Z → Protocol X Y W) (x : X) (y : Y) : (P.bind Q).eval x y = (Q (P.eval x y)).eval x y := by induction P with | leaf _ => rfl | alice g l r ihl ihr => simp only [bind, eval] split_ifs <;> [exact ihr; exact ihl] | bob g l r ihl ihr => simp only [bind, eval] split_ifs <;> [exact ihr; exact ihl] theorem bind_depth_le (P : Protocol X Y Z) (Q : Z → Protocol X Y W) (d : ℕ) (hQ : ∀ z, (Q z).depth ≤ d) : (P.bind Q).depth ≤ P.depth + d := by induction P with | leaf z => simpa [bind, depth] using hQ z | alice _ l r ihl ihr => simp only [bind, depth] omega | bob _ l r ihl ihr => simp only [bind, depth] omega theorem comap_eval {X' Y' : Type*} (φ : X' → X) (ψ : Y' → Y) (P : Protocol X Y Z) (x : X') (y : Y') : (P.comap φ ψ).eval x y = P.eval (φ x) (ψ y) := by induction P with | leaf _ => rfl | alice g l r ihl ihr => simp only [comap, eval, Function.comp_apply] split_ifs <;> [exact ihr; exact ihl] | bob g l r ihl ihr => simp only [comap, eval, Function.comp_apply] split_ifs <;> [exact ihr; exact ihl] theorem comap_depth {X' Y' : Type*} (φ : X' → X) (ψ : Y' → Y) (P : Protocol X Y Z) : (P.comap φ ψ).depth = P.depth := by induction P with | leaf _ => rfl | alice _ _ _ ihl ihr => simp [comap, depth, ihl, ihr] | bob _ _ _ ihl ihr => simp [comap, depth, ihl, ihr] theorem comap_leaves {X' Y' : Type*} (φ : X' → X) (ψ : Y' → Y) (P : Protocol X Y Z) : (P.comap φ ψ).leaves = P.leaves := by induction P with | leaf _ => rfl | alice _ _ _ ihl ihr => simp [comap, leaves, ihl, ihr] | bob _ _ _ ihl ihr => simp [comap, leaves, ihl, ihr] /-- The transcript (list of bits exchanged) produced by `P` on inputs `(x, y)`. -/ def trace : Protocol X Y Z → X → Y → List Bool | .leaf _, _, _ => [] | .alice g l r, x, y => if g x then true :: r.trace x y else false :: l.trace x y | .bob g l r, x, y => if g y then true :: r.trace x y else false :: l.trace x y /-- The list of all leaf transcripts of a protocol tree, together with their output labels. -/ def leafTable : Protocol X Y Z → List (List Bool × Z) | .leaf z => [([], z)] | .alice _ l r => (l.leafTable.map fun p => (false :: p.1, p.2)) ++ (r.leafTable.map fun p => (true :: p.1, p.2)) | .bob _ l r => (l.leafTable.map fun p => (false :: p.1, p.2)) ++ (r.leafTable.map fun p => (true :: p.1, p.2)) theorem leafTable_length (P : Protocol X Y Z) : P.leafTable.length = P.leaves := by induction P with | leaf _ => rfl | alice _ _ _ ihl ihr => simp [leafTable, leaves, ihl, ihr] | bob _ _ _ ihl ihr => simp [leafTable, leaves, ihl, ihr] theorem trace_mem_leafTable (P : Protocol X Y Z) (x : X) (y : Y) : (P.trace x y, P.eval x y) ∈ P.leafTable := by induction P with | leaf z => simp [trace, eval, leafTable] | alice g l r ihl ihr => simp only [trace, eval, leafTable, List.mem_append, List.mem_map] split_ifs with h · exact Or.inr ⟨(r.trace x y, r.eval x y), ihr, rfl⟩ · exact Or.inl ⟨(l.trace x y, l.eval x y), ihl, rfl⟩ | bob g l r ihl ihr => simp only [trace, eval, leafTable, List.mem_append, List.mem_map] split_ifs with h · exact Or.inr ⟨(r.trace x y, r.eval x y), ihr, rfl⟩ · exact Or.inl ⟨(l.trace x y, l.eval x y), ihl, rfl⟩ /-- Rectangle property: if `(x₁, y₁)` and `(x₂, y₂)` produce the same transcript in `P`, then `(x₁, y₂)` also produces that exact transcript and output. -/ theorem trace_rectangle (P : Protocol X Y Z) {x₁ x₂ : X} {y₁ y₂ : Y} (h : P.trace x₁ y₁ = P.trace x₂ y₂) : P.trace x₁ y₂ = P.trace x₁ y₁ ∧ P.eval x₁ y₂ = P.eval x₁ y₁ := by induction P with | leaf z => simp [trace, eval] | alice g l r ihl ihr => simp only [trace, eval] at h ⊢ cases hx₁ : g x₁ <;> cases hx₂ : g x₂ <;> simp only [hx₁, hx₂, Bool.false_eq_true, ↓reduceIte] at h ⊢ · have ih := ihl (List.cons.inj h).2 exact ⟨congrArg (false :: ·) ih.1, ih.2⟩ · cases h · cases h · have ih := ihr (List.cons.inj h).2 exact ⟨congrArg (true :: ·) ih.1, ih.2⟩ | bob g l r ihl ihr => simp only [trace, eval] at h ⊢ cases hy₁ : g y₁ <;> cases hy₂ : g y₂ <;> simp only [hy₁, hy₂, Bool.false_eq_true, ↓reduceIte] at h ⊢ · have ih := ihl (List.cons.inj h).2 exact ⟨congrArg (false :: ·) ih.1, ih.2⟩ · cases h · cases h · have ih := ihr (List.cons.inj h).2 exact ⟨congrArg (true :: ·) ih.1, ih.2⟩ /-- Outputs at a fixed transcript are monochromatic: same transcript implies same output. -/ theorem eval_eq_of_trace_eq (P : Protocol X Y Z) {x₁ x₂ : X} {y₁ y₂ : Y} (h : P.trace x₁ y₁ = P.trace x₂ y₂) : P.eval x₁ y₁ = P.eval x₂ y₂ := by induction P with | leaf z => rfl | alice g l r ihl ihr => simp only [trace, eval] at h ⊢ cases hx₁ : g x₁ <;> cases hx₂ : g x₂ <;> simp only [hx₁, hx₂, Bool.false_eq_true, ↓reduceIte] at h ⊢ · exact ihl (List.cons.inj h).2 · cases h · cases h · exact ihr (List.cons.inj h).2 | bob g l r ihl ihr => simp only [trace, eval] at h ⊢ cases hy₁ : g y₁ <;> cases hy₂ : g y₂ <;> simp only [hy₁, hy₂, Bool.false_eq_true, ↓reduceIte] at h ⊢ · exact ihl (List.cons.inj h).2 · cases h · cases h · exact ihr (List.cons.inj h).2 /-- Monochromatic rectangle partition: every finite set of distinct outputs attained by `f` has cardinality at most `P.leaves`. -/ theorem output_card_le_leaves [DecidableEq Z] (P : Protocol X Y Z) (f : X → Y → Z) (hP : P.Computes f) (S : Finset Z) (hS : ∀ z ∈ S, ∃ x y, f x y = z) : S.card ≤ P.leaves := by have hsub : S ⊆ (P.leafTable.map Prod.snd).toFinset := by intro z hz rcases hS z hz with ⟨x, y, rfl⟩ rw [List.mem_toFinset, List.mem_map] exact ⟨(P.trace x y, P.eval x y), P.trace_mem_leafTable x y, hP x y⟩ calc S.card ≤ (P.leafTable.map Prod.snd).toFinset.card := Finset.card_le_card hsub _ ≤ (P.leafTable.map Prod.snd).length := List.toFinset_card_le _ _ = P.leaves := by rw [List.length_map, P.leafTable_length] end Protocol /-- Predicate: `f` is computable by a deterministic protocol of depth `≤ d`. -/ def HasDepth {X Y Z : Type*} (f : X → Y → Z) (d : ℕ) : Prop := ∃ P : Protocol X Y Z, P.Computes f ∧ P.depth ≤ d /-- Predicate: `f` is computable by a deterministic protocol with `≤ L` leaves. -/ def HasLeaves {X Y Z : Type*} (f : X → Y → Z) (L : ℕ) : Prop := ∃ P : Protocol X Y Z, P.Computes f ∧ P.leaves ≤ L theorem HasDepth.mono {X Y Z : Type*} {f : X → Y → Z} {d₁ d₂ : ℕ} (h : HasDepth f d₁) (hle : d₁ ≤ d₂) : HasDepth f d₂ := by rcases h with ⟨P, hP, hd⟩ exact ⟨P, hP, le_trans hd hle⟩ theorem HasLeaves.mono {X Y Z : Type*} {f : X → Y → Z} {L₁ L₂ : ℕ} (h : HasLeaves f L₁) (hle : L₁ ≤ L₂) : HasLeaves f L₂ := by rcases h with ⟨P, hP, hL⟩ exact ⟨P, hP, le_trans hL hle⟩ /-! ## Section 2: The Supergolden Protocol Tree Balancing Theorem -/ /-- The Supergolden / Narayana-shifted leaf-capacity sequence: `F 0 = 1, F 1 = 2, F 2 = 3, F (d + 3) = F (d + 2) + F d + 1`. Every deterministic communication protocol tree with at most `supergoldenCap d` leaves can be rebalanced to depth at most `d`. -/ def supergoldenCap : ℕ → ℕ | 0 => 1 | 1 => 2 | 2 => 3 | d + 3 => supergoldenCap (d + 2) + supergoldenCap d + 1 @[simp] theorem supergoldenCap_0 : supergoldenCap 0 = 1 := rfl @[simp] theorem supergoldenCap_1 : supergoldenCap 1 = 2 := rfl @[simp] theorem supergoldenCap_2 : supergoldenCap 2 = 3 := rfl @[simp] theorem supergoldenCap_3 : supergoldenCap 3 = 5 := rfl @[simp] theorem supergoldenCap_4 : supergoldenCap 4 = 8 := rfl @[simp] theorem supergoldenCap_5 : supergoldenCap 5 = 12 := rfl @[simp] theorem supergoldenCap_6 : supergoldenCap 6 = 18 := rfl @[simp] theorem supergoldenCap_7 : supergoldenCap 7 = 27 := rfl @[simp] theorem supergoldenCap_8 : supergoldenCap 8 = 40 := rfl theorem supergoldenCap_pos (d : ℕ) : 1 ≤ supergoldenCap d := by match d with | 0 => decide | 1 => decide | 2 => decide | d + 3 => have h1 := supergoldenCap_pos (d + 2) simp only [supergoldenCap] omega theorem supergoldenCap_lt_succ (d : ℕ) : supergoldenCap d < supergoldenCap (d + 1) := by match d with | 0 => decide | 1 => decide | 2 => decide | d + 3 => have hpos := supergoldenCap_pos (d + 1) simp only [supergoldenCap] omega theorem supergoldenCap_strictMono : StrictMono supergoldenCap := strictMono_nat_of_lt_succ supergoldenCap_lt_succ theorem supergoldenCap_mono {d₁ d₂ : ℕ} (h : d₁ ≤ d₂) : supergoldenCap d₁ ≤ supergoldenCap d₂ := supergoldenCap_strictMono.monotone h /-- Key doubling bound: `F (d + 1) ≤ 2 * F d` for all `d : ℕ`. This guarantees that the lighter sibling side `min L_A L_B ≤ ⌊(L_A + L_B)/2⌋ ≤ F (d + 1)` always fits inside budget `d + 1`. -/ theorem supergoldenCap_le_two_mul (d : ℕ) : supergoldenCap (d + 1) ≤ 2 * supergoldenCap d := by match d with | 0 => decide | 1 => decide | 2 => decide | d + 3 => have h1 : supergoldenCap (d + 1) ≤ supergoldenCap (d + 2) := supergoldenCap_mono (by omega) have h2 : supergoldenCap (d + 2) ≤ supergoldenCap (d + 3) := supergoldenCap_mono (by omega) -- F (d + 4) = F (d + 3) + F (d + 1) + 1 ≤ F (d + 3) + F (d + 2) + 1 ≤ 2 * F (d + 3) have hstep : supergoldenCap (d + 1) + 1 ≤ supergoldenCap (d + 3) := by have hlt : supergoldenCap (d + 1) < supergoldenCap (d + 2) := supergoldenCap_lt_succ (d + 1) omega simp only [supergoldenCap] at hstep ⊢ omega /-- Existence of the real supergolden ratio `ψ ∈ (1.465, 1.466)` satisfying `ψ ^ 3 = ψ ^ 2 + 1`. -/ theorem supergolden_psi_exists : ∃ ψ : ℝ, (1465 / 1000 : ℝ) < ψ ∧ ψ < (1466 / 1000 : ℝ) ∧ ψ ^ 3 = ψ ^ 2 + 1 := by let g : ℝ → ℝ := fun x => x ^ 3 - x ^ 2 - 1 have hcont : ContinuousOn g (Set.Icc (1465 / 1000 : ℝ) (1466 / 1000 : ℝ)) := by fun_prop have hle : (1465 / 1000 : ℝ) ≤ (1466 / 1000 : ℝ) := by norm_num have ha : g (1465 / 1000 : ℝ) < 0 := by norm_num [g] have hb : 0 < g (1466 / 1000 : ℝ) := by norm_num [g] have hmem : (0 : ℝ) ∈ Set.Icc (g (1465 / 1000 : ℝ)) (g (1466 / 1000 : ℝ)) := ⟨le_of_lt ha, le_of_lt hb⟩ rcases intermediate_value_Icc hle hcont hmem with ⟨ψ, ⟨hψ1, hψ2⟩, hψ0⟩ refine ⟨ψ, ?_, ?_, ?_⟩ · refine lt_of_le_of_ne hψ1 ?_ intro heq; rw [← heq] at hψ0; linarith · refine lt_of_le_of_ne hψ2 ?_ intro heq; rw [heq] at hψ0; linarith · simp only [g] at hψ0; linarith /-- Exact exponential lower bound: `ψ ^ d ≤ supergoldenCap d` for all `d : ℕ` whenever `0 ≤ ψ`, `ψ ≤ 1.466`, and `ψ ^ 3 = ψ ^ 2 + 1`. -/ theorem supergoldenCap_ge_psi_pow {ψ : ℝ} (hψ0 : 0 ≤ ψ) (hψhi : ψ < 1466 / 1000) (hψeq : ψ ^ 3 = ψ ^ 2 + 1) : ∀ d : ℕ, ψ ^ d ≤ (supergoldenCap d : ℝ) := by intro d induction d using Nat.strong_induction_on with | h n ih => match n with | 0 => simp [supergoldenCap] | 1 => simp only [pow_one, supergoldenCap, Nat.cast_ofNat]; linarith | 2 => simp only [supergoldenCap, Nat.cast_ofNat] nlinarith | m + 3 => have h2 : ψ ^ (m + 2) ≤ (supergoldenCap (m + 2) : ℝ) := ih (m + 2) (by omega) have h0 : ψ ^ m ≤ (supergoldenCap m : ℝ) := ih m (by omega) have hpow : ψ ^ (m + 3) = ψ ^ (m + 2) + ψ ^ m := by calc ψ ^ (m + 3) = ψ ^ m * ψ ^ 3 := by rw [pow_add] _ = ψ ^ m * (ψ ^ 2 + 1) := by rw [hψeq] _ = ψ ^ m * ψ ^ 2 + ψ ^ m := by ring _ = ψ ^ (m + 2) + ψ ^ m := by rw [← pow_add] simp only [supergoldenCap, Nat.cast_add, Nat.cast_one] linarith /-- Quantitative dominance of the Supergolden balancing constant over the classical Kushilevitz–Nisan / Rao–Yehudayoff constant `2 / log₂(3/2) ≈ 3.4190`: we have `1 / log₂ ψ < 20 / 11 < 1.8182 < 3.4 < 2 / log₂(3/2)`. -/ theorem supergolden_constant_lt_and_beats_classical {ψ : ℝ} (hψlo : (1465 / 1000 : ℝ) < ψ) : 1 / Real.logb 2 ψ < 20 / 11 ∧ (34 / 10 : ℝ) < 2 / Real.logb 2 (3 / 2 : ℝ) := by have hlog2_pos : 0 < Real.log 2 := Real.log_pos (by norm_num) have hψ1 : (1 : ℝ) < ψ := by linarith have hlogψ_pos : 0 < Real.log ψ := Real.log_pos hψ1 have hlogbψ_pos : 0 < Real.logb 2 ψ := by rw [Real.logb]; exact div_pos hlogψ_pos hlog2_pos have h1 : 1 / Real.logb 2 ψ < 20 / 11 := by rw [div_lt_div_iff₀ hlogbψ_pos (by norm_num : (0 : ℝ) < 11), one_mul] -- Show 11 < 20 * Real.logb 2 ψ, i.e., 2 ^ 11 < ψ ^ 20 have hpow : (2 : ℝ) ^ (11 : ℕ) < ψ ^ (20 : ℕ) := by have hnum : (2 : ℝ) ^ (11 : ℕ) < (1465 / 1000 : ℝ) ^ (20 : ℕ) := by norm_num exact lt_trans hnum (pow_lt_pow_left₀ hψlo (by norm_num) (by norm_num)) have hlog_lt : Real.log ((2 : ℝ) ^ (11 : ℕ)) < Real.log (ψ ^ (20 : ℕ)) := Real.log_lt_log (by positivity) hpow rw [Real.log_pow, Real.log_pow] at hlog_lt simp only [Nat.cast_ofNat] at hlog_lt rw [Real.logb] have hdiv : (11 : ℝ) < 20 * (Real.log ψ / Real.log 2) := by rw [mul_div_assoc', lt_div_iff₀ hlog2_pos] linarith linarith have h2 : (34 / 10 : ℝ) < 2 / Real.logb 2 (3 / 2 : ℝ) := by have hlog32_pos : 0 < Real.log (3 / 2 : ℝ) := Real.log_pos (by norm_num) have hlogb32_pos : 0 < Real.logb 2 (3 / 2 : ℝ) := by rw [Real.logb]; exact div_pos hlog32_pos hlog2_pos rw [div_lt_div_iff₀ (by norm_num : (0 : ℝ) < 10) hlogb32_pos] -- Show 34 * Real.logb 2 (3/2) < 20, i.e., 17 * log (3/2) < 10 * log 2, i.e., (3/2)^17 < 2^10 have hpow : (3 / 2 : ℝ) ^ (17 : ℕ) < (2 : ℝ) ^ (10 : ℕ) := by norm_num have hlog_lt : Real.log ((3 / 2 : ℝ) ^ (17 : ℕ)) < Real.log ((2 : ℝ) ^ (10 : ℕ)) := Real.log_lt_log (by positivity) hpow rw [Real.log_pow, Real.log_pow] at hlog_lt simp only [Nat.cast_ofNat] at hlog_lt rw [Real.logb] have hdiv : 17 * (Real.log (3 / 2 : ℝ) / Real.log 2) < 10 := by rw [mul_div_assoc', div_lt_iff₀ hlog2_pos] linarith linarith exact ⟨h1, h2⟩ /-! ### Dependent Path Surgery on Communication Protocol Trees -/ /-- A dependent path from the root of `P` to a node inside `P`. -/ inductive TreePath {X Y Z : Type*} : Protocol X Y Z → Type _ where | here {P : Protocol X Y Z} : TreePath P | aliceL {g : X → Bool} {L R : Protocol X Y Z} (p : TreePath L) : TreePath (.alice g L R) | aliceR {g : X → Bool} {L R : Protocol X Y Z} (p : TreePath R) : TreePath (.alice g L R) | bobL {g : Y → Bool} {L R : Protocol X Y Z} (p : TreePath L) : TreePath (.bob g L R) | bobR {g : Y → Bool} {L R : Protocol X Y Z} (p : TreePath R) : TreePath (.bob g L R) namespace TreePath variable {X Y Z : Type*} /-- The subtree rooted at the target node of `p`. -/ def subtreeAt : {P : Protocol X Y Z} → TreePath P → Protocol X Y Z | P, .here => P | _, .aliceL p => subtreeAt p | _, .aliceR p => subtreeAt p | _, .bobL p => subtreeAt p | _, .bobR p => subtreeAt p /-- Predicate: Alice's input `x` agrees with every Alice-branch along `p`. -/ def aliceReach : {P : Protocol X Y Z} → TreePath P → X → Bool | _, .here, _ => true | .alice g _ _, .aliceL p, x => (!g x) && aliceReach p x | .alice g _ _, .aliceR p, x => (g x) && aliceReach p x | _, .bobL p, x => aliceReach p x | _, .bobR p, x => aliceReach p x /-- Predicate: Bob's input `y` agrees with every Bob-branch along `p`. -/ def bobReach : {P : Protocol X Y Z} → TreePath P → Y → Bool | _, .here, _ => true | _, .aliceL p, y => bobReach p y | _, .aliceR p, y => bobReach p y | .bob g _ _, .bobL p, y => (!g y) && bobReach p y | .bob g _ _, .bobR p, y => (g y) && bobReach p y /-- Total leaf count of sibling subtrees hanging off Alice-nodes along `p`. -/ def aliceSibLeaves : {P : Protocol X Y Z} → TreePath P → ℕ | _, .here => 0 | .alice _ _ R, .aliceL p => R.leaves + aliceSibLeaves p | .alice _ L _, .aliceR p => L.leaves + aliceSibLeaves p | _, .bobL p => aliceSibLeaves p | _, .bobR p => aliceSibLeaves p /-- Total leaf count of sibling subtrees hanging off Bob-nodes along `p`. -/ def bobSibLeaves : {P : Protocol X Y Z} → TreePath P → ℕ | _, .here => 0 | _, .aliceL p => bobSibLeaves p | _, .aliceR p => bobSibLeaves p | .bob _ _ R, .bobL p => R.leaves + bobSibLeaves p | .bob _ L _, .bobR p => L.leaves + bobSibLeaves p /-- Exact path-sibling leaf decomposition identity: `P.leaves = (subtreeAt p).leaves + aliceSibLeaves p + bobSibLeaves p`. -/ theorem leaves_decomp {P : Protocol X Y Z} (p : TreePath P) : P.leaves = (subtreeAt p).leaves + aliceSibLeaves p + bobSibLeaves p := by induction p with | here => simp [subtreeAt, aliceSibLeaves, bobSibLeaves] | aliceL p ih => simp only [Protocol.leaves, subtreeAt, aliceSibLeaves, bobSibLeaves] omega | aliceR p ih => simp only [Protocol.leaves, subtreeAt, aliceSibLeaves, bobSibLeaves] omega | bobL p ih => simp only [Protocol.leaves, subtreeAt, aliceSibLeaves, bobSibLeaves] omega | bobR p ih => simp only [Protocol.leaves, subtreeAt, aliceSibLeaves, bobSibLeaves] omega /-- Reaching the target node of `p` means `(x, y)` evaluates via `subtreeAt p`. -/ theorem eval_of_reach {P : Protocol X Y Z} (p : TreePath P) {x : X} {y : Y} (hx : aliceReach p x = true) (hy : bobReach p y = true) : P.eval x y = (subtreeAt p).eval x y := by induction p with | here => rfl | @aliceL g L R p ih => simp only [aliceReach, Bool.and_eq_true, Bool.not_eq_true'] at hx simp only [Protocol.eval, subtreeAt, hx.1, Bool.false_eq_true, ↓reduceIte] exact ih hx.2 hy | @aliceR g L R p ih => simp only [aliceReach, Bool.and_eq_true] at hx simp only [Protocol.eval, subtreeAt, hx.1, ↓reduceIte] exact ih hx.2 hy | @bobL g L R p ih => simp only [bobReach, Bool.and_eq_true, Bool.not_eq_true'] at hy simp only [Protocol.eval, subtreeAt, hy.1, Bool.false_eq_true, ↓reduceIte] exact ih hx hy.2 | @bobR g L R p ih => simp only [bobReach, Bool.and_eq_true] at hy simp only [Protocol.eval, subtreeAt, hy.1, ↓reduceIte] exact ih hx hy.2 /-- Delete the subtree at `p` (valid whenever `(x, y)` does not reach `p`). Returns `none` iff `p = .here`. -/ def pruneAt : {P : Protocol X Y Z} → TreePath P → Option (Protocol X Y Z) | _, .here => none | .alice g _ R, .aliceL p => match pruneAt p with | none => some R | some L' => some (.alice g L' R) | .alice g L _, .aliceR p => match pruneAt p with | none => some L | some R' => some (.alice g L R') | .bob g _ R, .bobL p => match pruneAt p with | none => some R | some L' => some (.bob g L' R) | .bob g L _, .bobR p => match pruneAt p with | none => some L | some R' => some (.bob g L R') theorem pruneAt_none_implies_reach {P : Protocol X Y Z} (p : TreePath P) (h : pruneAt p = none) (x : X) (y : Y) : aliceReach p x = true ∧ bobReach p y = true := by cases p with | here => exact ⟨rfl, rfl⟩ | aliceL p => simp only [pruneAt] at h; split at h <;> cases h | aliceR p => simp only [pruneAt] at h; split at h <;> cases h | bobL p => simp only [pruneAt] at h; split at h <;> cases h | bobR p => simp only [pruneAt] at h; split at h <;> cases h theorem pruneAt_leaves {P : Protocol X Y Z} (p : TreePath P) {Q : Protocol X Y Z} (h : pruneAt p = some Q) : Q.leaves = aliceSibLeaves p + bobSibLeaves p := by induction p generalizing Q with | here => cases h | @aliceL g L R p ih => simp only [pruneAt] at h cases hp : pruneAt p with | none => rw [hp] at h; cases h have h0 : aliceSibLeaves p = 0 ∧ bobSibLeaves p = 0 := by cases p with | here => exact ⟨rfl, rfl⟩ | aliceL _ => simp only [pruneAt] at hp; split at hp <;> cases hp | aliceR _ => simp only [pruneAt] at hp; split at hp <;> cases hp | bobL _ => simp only [pruneAt] at hp; split at hp <;> cases hp | bobR _ => simp only [pruneAt] at hp; split at hp <;> cases hp simp [aliceSibLeaves, bobSibLeaves, h0.1, h0.2] | some L' => rw [hp] at h; cases h have hL' := ih hp simp only [Protocol.leaves, aliceSibLeaves, bobSibLeaves] omega | @aliceR g L R p ih => simp only [pruneAt] at h cases hp : pruneAt p with | none => rw [hp] at h; cases h have h0 : aliceSibLeaves p = 0 ∧ bobSibLeaves p = 0 := by cases p with | here => exact ⟨rfl, rfl⟩ | aliceL _ => simp only [pruneAt] at hp; split at hp <;> cases hp | aliceR _ => simp only [pruneAt] at hp; split at hp <;> cases hp | bobL _ => simp only [pruneAt] at hp; split at hp <;> cases hp | bobR _ => simp only [pruneAt] at hp; split at hp <;> cases hp simp [aliceSibLeaves, bobSibLeaves, h0.1, h0.2] | some R' => rw [hp] at h; cases h have hR' := ih hp simp only [Protocol.leaves, aliceSibLeaves, bobSibLeaves] omega | @bobL g L R p ih => simp only [pruneAt] at h cases hp : pruneAt p with | none => rw [hp] at h; cases h have h0 : aliceSibLeaves p = 0 ∧ bobSibLeaves p = 0 := by cases p with | here => exact ⟨rfl, rfl⟩ | aliceL _ => simp only [pruneAt] at hp; split at hp <;> cases hp | aliceR _ => simp only [pruneAt] at hp; split at hp <;> cases hp | bobL _ => simp only [pruneAt] at hp; split at hp <;> cases hp | bobR _ => simp only [pruneAt] at hp; split at hp <;> cases hp simp [aliceSibLeaves, bobSibLeaves, h0.1, h0.2] | some L' => rw [hp] at h; cases h have hL' := ih hp simp only [Protocol.leaves, aliceSibLeaves, bobSibLeaves] omega | @bobR g L R p ih => simp only [pruneAt] at h cases hp : pruneAt p with | none => rw [hp] at h; cases h have h0 : aliceSibLeaves p = 0 ∧ bobSibLeaves p = 0 := by cases p with | here => exact ⟨rfl, rfl⟩ | aliceL _ => simp only [pruneAt] at hp; split at hp <;> cases hp | aliceR _ => simp only [pruneAt] at hp; split at hp <;> cases hp | bobL _ => simp only [pruneAt] at hp; split at hp <;> cases hp | bobR _ => simp only [pruneAt] at hp; split at hp <;> cases hp simp [aliceSibLeaves, bobSibLeaves, h0.1, h0.2] | some R' => rw [hp] at h; cases h have hR' := ih hp simp only [Protocol.leaves, aliceSibLeaves, bobSibLeaves] omega theorem pruneAt_eval {P : Protocol X Y Z} (p : TreePath P) {Q : Protocol X Y Z} (h : pruneAt p = some Q) {x : X} {y : Y} (hnot : ¬ (aliceReach p x = true ∧ bobReach p y = true)) : Q.eval x y = P.eval x y := by induction p generalizing Q with | here => cases h | @aliceL g L R p ih => simp only [pruneAt] at h cases hp : pruneAt p with | none => rw [hp] at h; cases h have hr := pruneAt_none_implies_reach p hp x y have hgx : g x = true := by cases hgx' : g x with | true => rfl | false => exfalso; apply hnot simp [aliceReach, bobReach, hgx', hr.1, hr.2] simp [Protocol.eval, hgx] | some L' => rw [hp] at h; cases h simp only [Protocol.eval] cases hgx : g x with | true => simp | false => simp only [Bool.false_eq_true, ↓reduceIte] apply ih hp intro ⟨h1, h2⟩ exact hnot ⟨by simp [aliceReach, hgx, h1], h2⟩ | @aliceR g L R p ih => simp only [pruneAt] at h cases hp : pruneAt p with | none => rw [hp] at h; cases h have hr := pruneAt_none_implies_reach p hp x y have hgx : g x = false := by cases hgx' : g x with | false => rfl | true => exfalso; apply hnot simp [aliceReach, bobReach, hgx', hr.1, hr.2] simp [Protocol.eval, hgx] | some R' => rw [hp] at h; cases h simp only [Protocol.eval] cases hgx : g x with | false => simp | true => simp only [↓reduceIte] apply ih hp intro ⟨h1, h2⟩ exact hnot ⟨by simp [aliceReach, hgx, h1], h2⟩ | @bobL g L R p ih => simp only [pruneAt] at h cases hp : pruneAt p with | none => rw [hp] at h; cases h have hr := pruneAt_none_implies_reach p hp x y have hgy : g y = true := by cases hgy' : g y with | true => rfl | false => exfalso; apply hnot simp [aliceReach, bobReach, hgy', hr.1, hr.2] simp [Protocol.eval, hgy] | some L' => rw [hp] at h; cases h simp only [Protocol.eval] cases hgy : g y with | true => simp | false => simp only [Bool.false_eq_true, ↓reduceIte] apply ih hp intro ⟨h1, h2⟩ exact hnot ⟨h1, by simp [bobReach, hgy, h2]⟩ | @bobR g L R p ih => simp only [pruneAt] at h cases hp : pruneAt p with | none => rw [hp] at h; cases h have hr := pruneAt_none_implies_reach p hp x y have hgy : g y = false := by cases hgy' : g y with | false => rfl | true => exfalso; apply hnot simp [aliceReach, bobReach, hgy', hr.1, hr.2] simp [Protocol.eval, hgy] | some R' => rw [hp] at h; cases h simp only [Protocol.eval] cases hgy : g y with | false => simp | true => simp only [↓reduceIte] apply ih hp intro ⟨h1, h2⟩ exact hnot ⟨h1, by simp [bobReach, hgy, h2]⟩ /-- Contract every Alice-node along `p` and delete `subtreeAt p`. Valid whenever `aliceReach p x = true` and `bobReach p y = false`. Returns `none` iff there are no Bob-nodes along `p` (in which case `bobReach p y = true` always). -/ def contractAliceAt : {P : Protocol X Y Z} → TreePath P → Option (Protocol X Y Z) | _, .here => none | _, .aliceL p => contractAliceAt p | _, .aliceR p => contractAliceAt p | .bob g _ R, .bobL p => match contractAliceAt p with | none => some R | some L' => some (.bob g L' R) | .bob g L _, .bobR p => match contractAliceAt p with | none => some L | some R' => some (.bob g L R') theorem contractAliceAt_none_implies_bobReach {P : Protocol X Y Z} (p : TreePath P) (h : contractAliceAt p = none) (y : Y) : bobReach p y = true := by induction p with | here => rfl | aliceL p ih => exact ih h | aliceR p ih => exact ih h | bobL p _ => simp only [contractAliceAt] at h; split at h <;> cases h | bobR p _ => simp only [contractAliceAt] at h; split at h <;> cases h theorem contractAliceAt_none_bobSib {P : Protocol X Y Z} (p : TreePath P) (h : contractAliceAt p = none) : bobSibLeaves p = 0 := by induction p with | here => rfl | aliceL p ih => exact ih h | aliceR p ih => exact ih h | bobL p _ => simp only [contractAliceAt] at h; split at h <;> cases h | bobR p _ => simp only [contractAliceAt] at h; split at h <;> cases h theorem contractAliceAt_leaves {P : Protocol X Y Z} (p : TreePath P) {Q : Protocol X Y Z} (h : contractAliceAt p = some Q) : Q.leaves = bobSibLeaves p := by induction p generalizing Q with | here => cases h | aliceL p ih => exact ih h | aliceR p ih => exact ih h | @bobL g L R p ih => simp only [contractAliceAt] at h cases hp : contractAliceAt p with | none => rw [hp] at h; cases h simp [bobSibLeaves, contractAliceAt_none_bobSib p hp] | some L' => rw [hp] at h; cases h have hL' := ih hp simp only [Protocol.leaves, bobSibLeaves] omega | @bobR g L R p ih => simp only [contractAliceAt] at h cases hp : contractAliceAt p with | none => rw [hp] at h; cases h simp [bobSibLeaves, contractAliceAt_none_bobSib p hp] | some R' => rw [hp] at h; cases h have hR' := ih hp simp only [Protocol.leaves, bobSibLeaves] omega theorem contractAliceAt_eval {P : Protocol X Y Z} (p : TreePath P) {Q : Protocol X Y Z} (h : contractAliceAt p = some Q) {x : X} {y : Y} (hx : aliceReach p x = true) (hy : bobReach p y = false) : Q.eval x y = P.eval x y := by induction p generalizing Q with | here => cases h | @aliceL g L R p ih => simp only [aliceReach, Bool.and_eq_true, Bool.not_eq_true'] at hx simp only [Protocol.eval, hx.1, Bool.false_eq_true, ↓reduceIte] exact ih h hx.2 hy | @aliceR g L R p ih => simp only [aliceReach, Bool.and_eq_true] at hx simp only [Protocol.eval, hx.1, ↓reduceIte] exact ih h hx.2 hy | @bobL g L R p ih => simp only [contractAliceAt] at h cases hp : contractAliceAt p with | none => rw [hp] at h; cases h have hbr := contractAliceAt_none_implies_bobReach p hp y have hgy : g y = true := by cases hgy' : g y with | true => rfl | false => simp [bobReach, hgy', hbr] at hy simp [Protocol.eval, hgy] | some L' => rw [hp] at h; cases h simp only [Protocol.eval] cases hgy : g y with | true => simp | false => simp only [Bool.false_eq_true, ↓reduceIte] have hy' : bobReach p y = false := by simpa [bobReach, hgy] using hy exact ih hp hx hy' | @bobR g L R p ih => simp only [contractAliceAt] at h cases hp : contractAliceAt p with | none => rw [hp] at h; cases h have hbr := contractAliceAt_none_implies_bobReach p hp y have hgy : g y = false := by cases hgy' : g y with | false => rfl | true => simp [bobReach, hgy', hbr] at hy simp [Protocol.eval, hgy] | some R' => rw [hp] at h; cases h simp only [Protocol.eval] cases hgy : g y with | false => simp | true => simp only [↓reduceIte] have hy' : bobReach p y = false := by simpa [bobReach, hgy] using hy exact ih hp hx hy' /-- Dual operation: contract every Bob-node along `p` and delete `subtreeAt p`. Valid whenever `bobReach p y = true` and `aliceReach p x = false`. -/ def contractBobAt : {P : Protocol X Y Z} → TreePath P → Option (Protocol X Y Z) | _, .here => none | _, .bobL p => contractBobAt p | _, .bobR p => contractBobAt p | .alice g _ R, .aliceL p => match contractBobAt p with | none => some R | some L' => some (.alice g L' R) | .alice g L _, .aliceR p => match contractBobAt p with | none => some L | some R' => some (.alice g L R') theorem contractBobAt_none_implies_aliceReach {P : Protocol X Y Z} (p : TreePath P) (h : contractBobAt p = none) (x : X) : aliceReach p x = true := by induction p with | here => rfl | bobL p ih => exact ih h | bobR p ih => exact ih h | aliceL p _ => simp only [contractBobAt] at h; split at h <;> cases h | aliceR p _ => simp only [contractBobAt] at h; split at h <;> cases h theorem contractBobAt_none_aliceSib {P : Protocol X Y Z} (p : TreePath P) (h : contractBobAt p = none) : aliceSibLeaves p = 0 := by induction p with | here => rfl | bobL p ih => exact ih h | bobR p ih => exact ih h | aliceL p _ => simp only [contractBobAt] at h; split at h <;> cases h | aliceR p _ => simp only [contractBobAt] at h; split at h <;> cases h theorem contractBobAt_leaves {P : Protocol X Y Z} (p : TreePath P) {Q : Protocol X Y Z} (h : contractBobAt p = some Q) : Q.leaves = aliceSibLeaves p := by induction p generalizing Q with | here => cases h | bobL p ih => exact ih h | bobR p ih => exact ih h | @aliceL g L R p ih => simp only [contractBobAt] at h cases hp : contractBobAt p with | none => rw [hp] at h; cases h simp [aliceSibLeaves, contractBobAt_none_aliceSib p hp] | some L' => rw [hp] at h; cases h have hL' := ih hp simp only [Protocol.leaves, aliceSibLeaves] omega | @aliceR g L R p ih => simp only [contractBobAt] at h cases hp : contractBobAt p with | none => rw [hp] at h; cases h simp [aliceSibLeaves, contractBobAt_none_aliceSib p hp] | some R' => rw [hp] at h; cases h have hR' := ih hp simp only [Protocol.leaves, aliceSibLeaves] omega theorem contractBobAt_eval {P : Protocol X Y Z} (p : TreePath P) {Q : Protocol X Y Z} (h : contractBobAt p = some Q) {x : X} {y : Y} (hy : bobReach p y = true) (hx : aliceReach p x = false) : Q.eval x y = P.eval x y := by induction p generalizing Q with | here => cases h | @bobL g L R p ih => simp only [bobReach, Bool.and_eq_true, Bool.not_eq_true'] at hy simp only [Protocol.eval, hy.1, Bool.false_eq_true, ↓reduceIte] exact ih h hy.2 hx | @bobR g L R p ih => simp only [bobReach, Bool.and_eq_true] at hy simp only [Protocol.eval, hy.1, ↓reduceIte] exact ih h hy.2 hx | @aliceL g L R p ih => simp only [contractBobAt] at h cases hp : contractBobAt p with | none => rw [hp] at h; cases h have har := contractBobAt_none_implies_aliceReach p hp x have hgx : g x = true := by cases hgx' : g x with | true => rfl | false => simp [aliceReach, hgx', har] at hx simp [Protocol.eval, hgx] | some L' => rw [hp] at h; cases h simp only [Protocol.eval] cases hgx : g x with | true => simp | false => simp only [Bool.false_eq_true, ↓reduceIte] have hx' : aliceReach p x = false := by simpa [aliceReach, hgx] using hx exact ih hp hy hx' | @aliceR g L R p ih => simp only [contractBobAt] at h cases hp : contractBobAt p with | none => rw [hp] at h; cases h have har := contractBobAt_none_implies_aliceReach p hp x have hgx : g x = false := by cases hgx' : g x with | false => rfl | true => simp [aliceReach, hgx', har] at hx simp [Protocol.eval, hgx] | some R' => rw [hp] at h; cases h simp only [Protocol.eval] cases hgx : g x with | false => simp | true => simp only [↓reduceIte] have hx' : aliceReach p x = false := by simpa [aliceReach, hgx] using hx exact ih hp hy hx' /-- Heavy-threshold separator lemma: whenever `1 ≤ t < P.leaves`, there exists a path `p` in `P` to an internal node whose subtree has `> t` leaves while both of its immediate children have `≤ t` leaves. -/ theorem exists_heavy_threshold_path {P : Protocol X Y Z} {t : ℕ} (ht : 1 ≤ t) (hP : t < P.leaves) : ∃ p : TreePath P, t < (subtreeAt p).leaves ∧ (∀ g L R, subtreeAt p = .alice g L R → L.leaves ≤ t ∧ R.leaves ≤ t) ∧ (∀ g L R, subtreeAt p = .bob g L R → L.leaves ≤ t ∧ R.leaves ≤ t) := by induction P with | leaf _ => simp only [Protocol.leaves] at hP; omega | alice g L R ihl ihr => by_cases hL : t < L.leaves · rcases ihl hL with ⟨p, hp1, hp2, hp3⟩ exact ⟨.aliceL p, hp1, hp2, hp3⟩ · by_cases hR : t < R.leaves · rcases ihr hR with ⟨p, hp1, hp2, hp3⟩ exact ⟨.aliceR p, hp1, hp2, hp3⟩ · refine ⟨.here, hP, ?_, ?_⟩ · intro g' L' R' heq; cases heq; omega · intro g' L' R' heq; cases heq | bob g L R ihl ihr => by_cases hL : t < L.leaves · rcases ihl hL with ⟨p, hp1, hp2, hp3⟩ exact ⟨.bobL p, hp1, hp2, hp3⟩ · by_cases hR : t < R.leaves · rcases ihr hR with ⟨p, hp1, hp2, hp3⟩ exact ⟨.bobR p, hp1, hp2, hp3⟩ · refine ⟨.here, hP, ?_, ?_⟩ · intro g' L' R' heq; cases heq · intro g' L' R' heq; cases heq; omega end TreePath /-- **HEADLINE THEOREM 1 (Supergolden Protocol Tree Balancing Theorem)**: For every `d : ℕ` and every deterministic communication protocol tree `P` (over arbitrary input types `X, Y` and arbitrary output alphabet `Z`), if `P.leaves ≤ supergoldenCap d`, then there exists an equivalent deterministic protocol `Q` computing the exact same function with `Q.depth ≤ d`. -/ theorem supergolden_protocol_balancing {X Y Z : Type*} : ∀ (d : ℕ) (P : Protocol X Y Z), P.leaves ≤ supergoldenCap d → ∃ Q : Protocol X Y Z, (∀ x y, Q.eval x y = P.eval x y) ∧ Q.depth ≤ d := by intro d induction d using Nat.strong_induction_on with | h d ih => intro P hL match d with | 0 => have h1 : P.leaves = 1 := le_antisymm hL P.leaves_pos exact ⟨P, fun _ _ => rfl, le_of_eq ((P.leaves_eq_one_iff_depth_zero).mp h1)⟩ | 1 => cases P with | leaf z => exact ⟨.leaf z, fun _ _ => rfl, by simp [Protocol.depth]⟩ | alice g L R => have hLp := L.leaves_pos; have hRp := R.leaves_pos simp only [Protocol.leaves, supergoldenCap] at hL have hL1 : L.leaves = 1 := by omega have hR1 : R.leaves = 1 := by omega refine ⟨.alice g L R, fun _ _ => rfl, ?_⟩ simp [Protocol.depth, (L.leaves_eq_one_iff_depth_zero).mp hL1, (R.leaves_eq_one_iff_depth_zero).mp hR1] | bob g L R => have hLp := L.leaves_pos; have hRp := R.leaves_pos simp only [Protocol.leaves, supergoldenCap] at hL have hL1 : L.leaves = 1 := by omega have hR1 : R.leaves = 1 := by omega refine ⟨.bob g L R, fun _ _ => rfl, ?_⟩ simp [Protocol.depth, (L.leaves_eq_one_iff_depth_zero).mp hL1, (R.leaves_eq_one_iff_depth_zero).mp hR1] | 2 => cases P with | leaf z => exact ⟨.leaf z, fun _ _ => rfl, by simp [Protocol.depth]⟩ | alice g L R => have hLp := L.leaves_pos; have hRp := R.leaves_pos simp only [Protocol.leaves, supergoldenCap] at hL rcases ih 1 (by omega) L (by simp [supergoldenCap]; omega) with ⟨QL, hQLe, hQLd⟩ rcases ih 1 (by omega) R (by simp [supergoldenCap]; omega) with ⟨QR, hQRe, hQRd⟩ refine ⟨.alice g QL QR, ?_, ?_⟩ · intro x y; simp only [Protocol.eval]; split_ifs <;> [exact hQRe x y; exact hQLe x y] · simp only [Protocol.depth]; omega | bob g L R => have hLp := L.leaves_pos; have hRp := R.leaves_pos simp only [Protocol.leaves, supergoldenCap] at hL rcases ih 1 (by omega) L (by simp [supergoldenCap]; omega) with ⟨QL, hQLe, hQLd⟩ rcases ih 1 (by omega) R (by simp [supergoldenCap]; omega) with ⟨QR, hQRe, hQRd⟩ refine ⟨.bob g QL QR, ?_, ?_⟩ · intro x y; simp only [Protocol.eval]; split_ifs <;> [exact hQRe x y; exact hQLe x y] · simp only [Protocol.depth]; omega | m + 3 => by_cases hsmall : P.leaves ≤ supergoldenCap m · rcases ih m (by omega) P hsmall with ⟨Q, hQe, hQd⟩ exact ⟨Q, hQe, by omega⟩ · push Not at hsmall rcases TreePath.exists_heavy_threshold_path (supergoldenCap_pos m) hsmall with ⟨p, hp_gt, hp_alice, hp_bob⟩ -- First balance the subtree at `p` in depth `≤ m + 1` by executing its root directly have hsub_bal : ∃ Qsub : Protocol X Y Z, (∀ x y, Qsub.eval x y = (TreePath.subtreeAt p).eval x y) ∧ Qsub.depth ≤ m + 1 := by cases hsub : TreePath.subtreeAt p with | leaf z => have := supergoldenCap_pos m rw [hsub] at hp_gt; simp only [Protocol.leaves] at hp_gt; omega | alice g L R => have ⟨hLle, hRle⟩ := hp_alice g L R hsub rcases ih m (by omega) L hLle with ⟨QL, hQLe, hQLd⟩ rcases ih m (by omega) R hRle with ⟨QR, hQRe, hQRd⟩ refine ⟨.alice g QL QR, ?_, ?_⟩ · intro x y; simp only [Protocol.eval]; split_ifs <;> [exact hQRe x y; exact hQLe x y] · simp only [Protocol.depth]; omega | bob g L R => have ⟨hLle, hRle⟩ := hp_bob g L R hsub rcases ih m (by omega) L hLle with ⟨QL, hQLe, hQLd⟩ rcases ih m (by omega) R hRle with ⟨QR, hQRe, hQRd⟩ refine ⟨.bob g QL QR, ?_, ?_⟩ · intro x y; simp only [Protocol.eval]; split_ifs <;> [exact hQRe x y; exact hQLe x y] · simp only [Protocol.depth]; omega rcases hsub_bal with ⟨Qsub, hQsub_e, hQsub_d⟩ -- Check if `p = .here`, in which case `Qsub` already simulates `P` in depth `≤ m + 1 ≤ m + 3` cases hpr : TreePath.pruneAt p with | none => refine ⟨Qsub, ?_, by omega⟩ intro x y have hreach := TreePath.pruneAt_none_implies_reach p hpr x y rw [hQsub_e x y, ← TreePath.eval_of_reach p hreach.1 hreach.2] | some Pout => have hdecomp := TreePath.leaves_decomp p have hPout_leaves : Pout.leaves = TreePath.aliceSibLeaves p + TreePath.bobSibLeaves p := TreePath.pruneAt_leaves p hpr have hPout_le : Pout.leaves ≤ supergoldenCap (m + 2) := by simp only [supergoldenCap] at hL omega rcases ih (m + 2) (by omega) Pout hPout_le with ⟨Qout, hQout_e, hQout_d⟩ have hdouble : supergoldenCap (m + 2) ≤ 2 * supergoldenCap (m + 1) := supergoldenCap_le_two_mul (m + 1) -- Choose the player with the LARGER sibling side to speak first! by_cases hAB : TreePath.bobSibLeaves p ≤ TreePath.aliceSibLeaves p · -- Alice speaks first: `bobSibLeaves p ≤ supergoldenCap (m + 1)` have hB_le : TreePath.bobSibLeaves p ≤ supergoldenCap (m + 1) := by omega cases hca : TreePath.contractAliceAt p with | none => -- No Bob nodes along `p`, so `bobReach p y = true` identically! refine ⟨.alice (TreePath.aliceReach p) Qout Qsub, ?_, ?_⟩ · intro x y simp only [Protocol.eval] cases hax : TreePath.aliceReach p x with | true => simp only [↓reduceIte] have hby := TreePath.contractAliceAt_none_implies_bobReach p hca y rw [hQsub_e x y, ← TreePath.eval_of_reach p hax hby] | false => simp only [Bool.false_eq_true, ↓reduceIte] rw [hQout_e x y] apply TreePath.pruneAt_eval p hpr intro ⟨h1, _⟩; rw [hax] at h1; cases h1 · simp only [Protocol.depth]; omega | some PB => have hPB_le : PB.leaves ≤ supergoldenCap (m + 1) := by rw [TreePath.contractAliceAt_leaves p hca]; exact hB_le rcases ih (m + 1) (by omega) PB hPB_le with ⟨QB, hQBe, hQBd⟩ refine ⟨.alice (TreePath.aliceReach p) Qout (.bob (TreePath.bobReach p) QB Qsub), ?_, ?_⟩ · intro x y simp only [Protocol.eval] cases hax : TreePath.aliceReach p x with | false => simp only [Bool.false_eq_true, ↓reduceIte] rw [hQout_e x y] apply TreePath.pruneAt_eval p hpr intro ⟨h1, _⟩; rw [hax] at h1; cases h1 | true => simp only [↓reduceIte] cases hby : TreePath.bobReach p y with | true => simp only [↓reduceIte] rw [hQsub_e x y, ← TreePath.eval_of_reach p hax hby] | false => simp only [Bool.false_eq_true, ↓reduceIte] rw [hQBe x y] exact TreePath.contractAliceAt_eval p hca hax hby · simp only [Protocol.depth]; omega · -- Bob speaks first: `aliceSibLeaves p ≤ supergoldenCap (m + 1)` have hA_le : TreePath.aliceSibLeaves p ≤ supergoldenCap (m + 1) := by omega cases hcb : TreePath.contractBobAt p with | none => refine ⟨.bob (TreePath.bobReach p) Qout Qsub, ?_, ?_⟩ · intro x y simp only [Protocol.eval] cases hby : TreePath.bobReach p y with | true => simp only [↓reduceIte] have hax := TreePath.contractBobAt_none_implies_aliceReach p hcb x rw [hQsub_e x y, ← TreePath.eval_of_reach p hax hby] | false => simp only [Bool.false_eq_true, ↓reduceIte] rw [hQout_e x y] apply TreePath.pruneAt_eval p hpr intro ⟨_, h2⟩; rw [hby] at h2; cases h2 · simp only [Protocol.depth]; omega | some PA => have hPA_le : PA.leaves ≤ supergoldenCap (m + 1) := by rw [TreePath.contractBobAt_leaves p hcb]; exact hA_le rcases ih (m + 1) (by omega) PA hPA_le with ⟨QA, hQAe, hQAd⟩ refine ⟨.bob (TreePath.bobReach p) Qout (.alice (TreePath.aliceReach p) QA Qsub), ?_, ?_⟩ · intro x y simp only [Protocol.eval] cases hby : TreePath.bobReach p y with | false => simp only [Bool.false_eq_true, ↓reduceIte] rw [hQout_e x y] apply TreePath.pruneAt_eval p hpr intro ⟨_, h2⟩; rw [hby] at h2; cases h2 | true => simp only [↓reduceIte] cases hax : TreePath.aliceReach p x with | true => simp only [↓reduceIte] rw [hQsub_e x y, ← TreePath.eval_of_reach p hax hby] | false => simp only [Bool.false_eq_true, ↓reduceIte] rw [hQAe x y] exact TreePath.contractBobAt_eval p hcb hby hax · simp only [Protocol.depth]; omega /-- **HEADLINE COROLLARY 1 (Logarithmic Supergolden Balancing Bound)**: For any deterministic protocol `P`, there exists an equivalent protocol `Q` whose depth satisfies `(Q.depth : ℝ) ≤ (1 / Real.logb 2 ψ) * Real.logb 2 P.leaves + 1 < (20 / 11) * Real.logb 2 P.leaves + 1`, where `ψ ∈ (1.465, 1.466)` is the supergolden constant (`ψ^3 = ψ^2 + 1`). -/ theorem supergolden_log_balancing_bound {X Y Z : Type*} (P : Protocol X Y Z) : ∃ ψ : ℝ, (1465 / 1000 : ℝ) < ψ ∧ ψ < (1466 / 1000 : ℝ) ∧ ψ ^ 3 = ψ ^ 2 + 1 ∧ ∃ Q : Protocol X Y Z, (∀ x y, Q.eval x y = P.eval x y) ∧ (Q.depth : ℝ) ≤ (1 / Real.logb 2 ψ) * Real.logb 2 (P.leaves : ℝ) + 1 := by rcases supergolden_psi_exists with ⟨ψ, hlo, hhi, heq⟩ refine ⟨ψ, hlo, hhi, heq, ?_⟩ have hψ1 : (1 : ℝ) < ψ := by linarith have hψ0 : (0 : ℝ) ≤ ψ := by linarith have hLpos : (1 : ℝ) ≤ (P.leaves : ℝ) := by exact_mod_cast P.leaves_pos have hlogψ : 0 < Real.log ψ := Real.log_pos hψ1 have hlog2 : 0 < Real.log 2 := Real.log_pos (by norm_num) have hlogL : 0 ≤ Real.log (P.leaves : ℝ) := Real.log_nonneg hLpos let d : ℕ := Nat.ceil (Real.log (P.leaves : ℝ) / Real.log ψ) have hd_ge : Real.log (P.leaves : ℝ) / Real.log ψ ≤ (d : ℝ) := Nat.le_ceil _ have hd_le : (d : ℝ) ≤ Real.log (P.leaves : ℝ) / Real.log ψ + 1 := by have hnonneg : 0 ≤ Real.log (P.leaves : ℝ) / Real.log ψ := div_nonneg hlogL (le_of_lt hlogψ) have hlt := Nat.ceil_lt_add_one hnonneg exact le_of_lt hlt have hL_le_pow : (P.leaves : ℝ) ≤ ψ ^ d := by have hmul : Real.log (P.leaves : ℝ) ≤ (d : ℝ) * Real.log ψ := by rwa [div_le_iff₀ hlogψ] at hd_ge have hexp := Real.exp_le_exp.mpr hmul rw [Real.exp_log (by linarith : (0 : ℝ) < P.leaves)] at hexp have hpow : Real.exp ((d : ℝ) * Real.log ψ) = ψ ^ d := by rw [mul_comm, ← Real.rpow_def_of_pos (by linarith : 0 < ψ), Real.rpow_natCast] rwa [hpow] at hexp have hL_le_cap : P.leaves ≤ supergoldenCap d := by have hreal : (P.leaves : ℝ) ≤ (supergoldenCap d : ℝ) := le_trans hL_le_pow (supergoldenCap_ge_psi_pow hψ0 hhi heq d) exact_mod_cast hreal rcases supergolden_protocol_balancing d P hL_le_cap with ⟨Q, hQe, hQd⟩ refine ⟨Q, hQe, ?_⟩ have hQdR : (Q.depth : ℝ) ≤ (d : ℝ) := by exact_mod_cast hQd have hchange : (1 / Real.logb 2 ψ) * Real.logb 2 (P.leaves : ℝ) = Real.log (P.leaves : ℝ) / Real.log ψ := by rw [Real.logb, Real.logb] field_simp [ne_of_gt hlog2, ne_of_gt hlogψ] linarith /-! ## Section 3: Exact Non-Asymptotic Telescoping Binomial Direct-Sum Theorem -/ /-- The `ℓ`-fold parallel direct sum of a communication problem `f : X → Y → Z`. -/ def directSum {X Y Z : Type*} (f : X → Y → Z) (ℓ : ℕ) : (Fin ℓ → X) → (Fin ℓ → Y) → (Fin ℓ → Z) := fun x y i => f (x i) (y i) /-- Balanced binary dispatch protocol allowing Alice to transmit a value `idx x : Fin n` (for `0 < n`) in at most `Nat.clog 2 n` bits and continue with `branches (idx x)`. -/ def dispatchAlice {X Y Z : Type*} : (n : ℕ) → (0 < n) → (X → Fin n) → (Fin n → Protocol X Y Z) → Protocol X Y Z | 0, hn, _, _ => absurd hn (Nat.lt_irrefl 0) | 1, _, _, branches => branches ⟨0, Nat.zero_lt_one⟩ | n + 2, _, idx, branches => let m := (n + 2) / 2 let r := n + 2 - m have hm_pos : 0 < m := by omega have hr_pos : 0 < r := by omega have hm_lt : m < n + 2 := by omega have hr_lt : r < n + 2 := by omega let Pleft : Protocol X Y Z := dispatchAlice m hm_pos (fun x => if h : (idx x).val < m then ⟨(idx x).val, h⟩ else ⟨0, hm_pos⟩) (fun i => branches ⟨i.val, lt_trans i.isLt hm_lt⟩) let Pright : Protocol X Y Z := dispatchAlice r hr_pos (fun x => if h : m ≤ (idx x).val then ⟨(idx x).val - m, by omega⟩ else ⟨0, hr_pos⟩) (fun i => branches ⟨m + i.val, by omega⟩) .alice (fun x => decide (m ≤ (idx x).val)) Pleft Pright /-- Balanced binary dispatch protocol allowing Bob to transmit `idx y : Fin n` in at most `Nat.clog 2 n` bits and continue with `branches (idx y)`. -/ def dispatchBob {X Y Z : Type*} : (n : ℕ) → (0 < n) → (Y → Fin n) → (Fin n → Protocol X Y Z) → Protocol X Y Z | 0, hn, _, _ => absurd hn (Nat.lt_irrefl 0) | 1, _, _, branches => branches ⟨0, Nat.zero_lt_one⟩ | n + 2, _, idx, branches => let m := (n + 2) / 2 let r := n + 2 - m have hm_pos : 0 < m := by omega have hr_pos : 0 < r := by omega have hm_lt : m < n + 2 := by omega have hr_lt : r < n + 2 := by omega let Pleft : Protocol X Y Z := dispatchBob m hm_pos (fun y => if h : (idx y).val < m then ⟨(idx y).val, h⟩ else ⟨0, hm_pos⟩) (fun i => branches ⟨i.val, lt_trans i.isLt hm_lt⟩) let Pright : Protocol X Y Z := dispatchBob r hr_pos (fun y => if h : m ≤ (idx y).val then ⟨(idx y).val - m, by omega⟩ else ⟨0, hr_pos⟩) (fun i => branches ⟨m + i.val, by omega⟩) .bob (fun y => decide (m ≤ (idx y).val)) Pleft Pright theorem dispatchAlice_eval {X Y Z : Type*} : ∀ (n : ℕ) (hn : 0 < n) (idx : X → Fin n) (branches : Fin n → Protocol X Y Z) (x : X) (y : Y), (dispatchAlice n hn idx branches).eval x y = (branches (idx x)).eval x y := by intro n induction n using Nat.strong_induction_on with | h n ih => intro hn idx branches x y match n with | 0 => exact absurd hn (Nat.lt_irrefl 0) | 1 => simp only [dispatchAlice] have h0 : idx x = ⟨0, Nat.zero_lt_one⟩ := Subsingleton.elim _ _ rw [h0] | k + 2 => simp only [dispatchAlice, Protocol.eval] by_cases hge : (k + 2) / 2 ≤ (idx x).val · simp only [decide_eq_true_eq, hge, ↓reduceIte] rw [ih (k + 2 - (k + 2) / 2) (by omega) (by omega)] simp only [hge, ↓reduceDIte] have heq : (⟨(k + 2) / 2 + ((idx x).val - (k + 2) / 2), by omega⟩ : Fin (k + 2)) = idx x := by ext; dsimp only; omega rw [heq] · simp only [decide_eq_true_eq, hge, ↓reduceIte] have hlt : (idx x).val < (k + 2) / 2 := by omega rw [ih ((k + 2) / 2) (by omega) (by omega)] simp only [hlt, ↓reduceDIte] theorem dispatchBob_eval {X Y Z : Type*} : ∀ (n : ℕ) (hn : 0 < n) (idx : Y → Fin n) (branches : Fin n → Protocol X Y Z) (x : X) (y : Y), (dispatchBob n hn idx branches).eval x y = (branches (idx y)).eval x y := by intro n induction n using Nat.strong_induction_on with | h n ih => intro hn idx branches x y match n with | 0 => exact absurd hn (Nat.lt_irrefl 0) | 1 => simp only [dispatchBob] have h0 : idx y = ⟨0, Nat.zero_lt_one⟩ := Subsingleton.elim _ _ rw [h0] | k + 2 => simp only [dispatchBob, Protocol.eval] by_cases hge : (k + 2) / 2 ≤ (idx y).val · simp only [decide_eq_true_eq, hge, ↓reduceIte] rw [ih (k + 2 - (k + 2) / 2) (by omega) (by omega)] simp only [hge, ↓reduceDIte] have heq : (⟨(k + 2) / 2 + ((idx y).val - (k + 2) / 2), by omega⟩ : Fin (k + 2)) = idx y := by ext; dsimp only; omega rw [heq] · simp only [decide_eq_true_eq, hge, ↓reduceIte] have hlt : (idx y).val < (k + 2) / 2 := by omega rw [ih ((k + 2) / 2) (by omega) (by omega)] simp only [hlt, ↓reduceDIte] private theorem clog_half_succ (k : ℕ) : Nat.clog 2 ((k + 2) / 2) + 1 ≤ Nat.clog 2 (k + 2) ∧ Nat.clog 2 (k + 2 - (k + 2) / 2) + 1 ≤ Nat.clog 2 (k + 2) := by have h1 : (k + 2) / 2 ≤ (k + 2 + 2 - 1) / 2 := by omega have h2 : k + 2 - (k + 2) / 2 = (k + 2 + 2 - 1) / 2 := by omega have hstep : Nat.clog 2 ((k + 2 + 2 - 1) / 2) + 1 = Nat.clog 2 (k + 2) := by symm exact Nat.clog_of_one_lt (by omega : 1 < 2) (by omega : 1 < k + 2) constructor · have hmono : Nat.clog 2 ((k + 2) / 2) ≤ Nat.clog 2 ((k + 2 + 2 - 1) / 2) := Nat.clog_mono_right 2 h1 omega · rw [h2]; exact le_of_eq hstep theorem dispatchAlice_depth_le {X Y Z : Type*} : ∀ (n : ℕ) (hn : 0 < n) (idx : X → Fin n) (branches : Fin n → Protocol X Y Z) (d : ℕ), (∀ i, (branches i).depth ≤ d) → (dispatchAlice n hn idx branches).depth ≤ Nat.clog 2 n + d := by intro n induction n using Nat.strong_induction_on with | h n ih => intro hn idx branches d hd match n with | 0 => exact absurd hn (Nat.lt_irrefl 0) | 1 => simp only [dispatchAlice, Nat.clog_one_right, zero_add] exact hd ⟨0, Nat.zero_lt_one⟩ | k + 2 => simp only [dispatchAlice, Protocol.depth] have hL := ih ((k + 2) / 2) (by omega) (by omega) (fun x => if h : (idx x).val < (k + 2) / 2 then ⟨(idx x).val, h⟩ else ⟨0, by omega⟩) (fun i => branches ⟨i.val, lt_trans i.isLt (by omega)⟩) d (fun i => hd _) have hR := ih (k + 2 - (k + 2) / 2) (by omega) (by omega) (fun x => if h : (k + 2) / 2 ≤ (idx x).val then ⟨(idx x).val - (k + 2) / 2, by omega⟩ else ⟨0, by omega⟩) (fun i => branches ⟨(k + 2) / 2 + i.val, by omega⟩) d (fun i => hd _) have ⟨hc1, hc2⟩ := clog_half_succ k omega theorem dispatchBob_depth_le {X Y Z : Type*} : ∀ (n : ℕ) (hn : 0 < n) (idx : Y → Fin n) (branches : Fin n → Protocol X Y Z) (d : ℕ), (∀ i, (branches i).depth ≤ d) → (dispatchBob n hn idx branches).depth ≤ Nat.clog 2 n + d := by intro n induction n using Nat.strong_induction_on with | h n ih => intro hn idx branches d hd match n with | 0 => exact absurd hn (Nat.lt_irrefl 0) | 1 => simp only [dispatchBob, Nat.clog_one_right, zero_add] exact hd ⟨0, Nat.zero_lt_one⟩ | k + 2 => simp only [dispatchBob, Protocol.depth] have hL := ih ((k + 2) / 2) (by omega) (by omega) (fun y => if h : (idx y).val < (k + 2) / 2 then ⟨(idx y).val, h⟩ else ⟨0, by omega⟩) (fun i => branches ⟨i.val, lt_trans i.isLt (by omega)⟩) d (fun i => hd _) have hR := ih (k + 2 - (k + 2) / 2) (by omega) (by omega) (fun y => if h : (k + 2) / 2 ≤ (idx y).val then ⟨(idx y).val - (k + 2) / 2, by omega⟩ else ⟨0, by omega⟩) (fun i => branches ⟨(k + 2) / 2 + i.val, by omega⟩) d (fun i => hd _) have ⟨hc1, hc2⟩ := clog_half_succ k omega /-- Exact upper bound `2 ^ Nat.clog 2 n ≤ 2 * n` for every `n ≥ 1`. -/ theorem two_pow_clog_le_two_mul {n : ℕ} (hn : 0 < n) : 2 ^ Nat.clog 2 n ≤ 2 * n := by cases eq_or_lt_of_le (Nat.succ_le_of_lt hn) with | inl h1 => subst h1; simp | inr hgt => have hpos : 0 < Nat.clog 2 n := Nat.clog_pos (by omega) hgt have hprev : 2 ^ (Nat.clog 2 n - 1) < n := by have hlt : Nat.clog 2 n - 1 < Nat.clog 2 n := by omega exact (Nat.lt_clog_iff_pow_lt (by omega)).mp hlt have heq : 2 ^ Nat.clog 2 n = 2 * 2 ^ (Nat.clog 2 n - 1) := by conv_lhs => rw [← Nat.sub_add_cancel hpos, Nat.pow_succ, mul_comm] omega /-- Cardinality of `k`-element subsets of `Fin ℓ` equals `Nat.choose ℓ k`. -/ noncomputable def subsetEquiv (ℓ k : ℕ) : { S : Finset (Fin ℓ) // S.card = k } ≃ Fin (Nat.choose ℓ k) := by have hcard : Fintype.card { S : Finset (Fin ℓ) // S.card = k } = Nat.choose ℓ k := by have e : { S : Finset (Fin ℓ) // S.card = k } ≃ { S : Finset (Fin ℓ) // S ∈ (Finset.univ : Finset (Fin ℓ)).powersetCard k } := Equiv.subtypeEquivRight (fun S => by simp [Finset.mem_powersetCard]) rw [Fintype.card_congr e, Fintype.card_coe, Finset.card_powersetCard, Finset.card_fin] exact (Fintype.equivFin _).trans (finCongr hcard) /-- Given `S : Finset (Fin ℓ)` with `S.card = k`, combine outputs from `Sᶜ` (`ℓ - k` coordinates) and `S` (`k` coordinates) back into `Fin ℓ → Z`. -/ noncomputable def combineOnSubset {Z : Type*} {ℓ k : ℕ} (S : Finset (Fin ℓ)) (_hS : S.card = k) (e0 : Fin (ℓ - k) ≃ { i : Fin ℓ // i ∉ S }) (e1 : Fin k ≃ { i : Fin ℓ // i ∈ S }) (z0 : Fin (ℓ - k) → Z) (z1 : Fin k → Z) : Fin ℓ → Z := fun i => if hi : i ∈ S then z1 (e1.symm ⟨i, hi⟩) else z0 (e0.symm ⟨i, hi⟩) /-- Canonical bijections enumerating `Sᶜ` and `S` for a `k`-element subset `S ⊆ Fin ℓ`. -/ noncomputable def subsetComplEquiv {ℓ k : ℕ} (S : Finset (Fin ℓ)) (hS : S.card = k) : Fin (ℓ - k) ≃ { i : Fin ℓ // i ∉ S } := by have hcard : Fintype.card { i : Fin ℓ // i ∉ S } = ℓ - k := by have e : { i : Fin ℓ // i ∉ S } ≃ { i : Fin ℓ // i ∈ Sᶜ } := Equiv.subtypeEquivRight (fun i => by simp) rw [Fintype.card_congr e, Fintype.card_coe, Finset.card_compl, Fintype.card_fin, hS] exact (finCongr hcard.symm).trans (Fintype.equivFin _).symm noncomputable def subsetMemEquiv {ℓ k : ℕ} (S : Finset (Fin ℓ)) (hS : S.card = k) : Fin k ≃ { i : Fin ℓ // i ∈ S } := by have hcard : Fintype.card { i : Fin ℓ // i ∈ S } = k := by rw [Fintype.card_coe, hS] exact (finCongr hcard.symm).trans (Fintype.equivFin _).symm /-- **Prefix-Coded Parallel Direct-Sum Protocol** `parallelSim P ℓ`: simulates `ℓ` independent copies of `P` in parallel by transmitting, at each internal node, the Hamming weight `k ∈ {0, …, ℓ}` and subset `S ∈ ([ℓ] choose k)` of coordinates taking the `true` branch, then recursing on the two complementary subsets. -/ noncomputable def parallelSim {X Y Z : Type*} : Protocol X Y Z → (ℓ : ℕ) → Protocol (Fin ℓ → X) (Fin ℓ → Y) (Fin ℓ → Z) | .leaf z, _ => .leaf (fun _ => z) | .alice g L R, ℓ => dispatchAlice (ℓ + 1) (Nat.succ_pos ℓ) (fun x => let S := Finset.univ.filter (fun i : Fin ℓ => g (x i) = true) ⟨S.card, Nat.lt_succ_of_le (by simpa using Finset.card_le_univ S)⟩) (fun k => have hpos : 0 < Nat.choose ℓ k.val := Nat.choose_pos (Nat.le_of_lt_succ k.isLt) let eqSub := subsetEquiv ℓ k.val dispatchAlice (Nat.choose ℓ k.val) hpos (fun x => let S := Finset.univ.filter (fun i : Fin ℓ => g (x i) = true) if hS : S.card = k.val then eqSub ⟨S, hS⟩ else ⟨0, hpos⟩) (fun idxS => let S := (eqSub.symm idxS).val let hS : S.card = k.val := (eqSub.symm idxS).property let e0 := subsetComplEquiv S hS let e1 := subsetMemEquiv S hS let P0 := (parallelSim L (ℓ - k.val)).comap (fun x i => x (e0 i).val) (fun y i => y (e0 i).val) let P1 := (parallelSim R k.val).comap (fun x i => x (e1 i).val) (fun y i => y (e1 i).val) P0.bind (fun z0 => P1.map (fun z1 => combineOnSubset S hS e0 e1 z0 z1)))) | .bob g L R, ℓ => dispatchBob (ℓ + 1) (Nat.succ_pos ℓ) (fun y => let S := Finset.univ.filter (fun i : Fin ℓ => g (y i) = true) ⟨S.card, Nat.lt_succ_of_le (by simpa using Finset.card_le_univ S)⟩) (fun k => have hpos : 0 < Nat.choose ℓ k.val := Nat.choose_pos (Nat.le_of_lt_succ k.isLt) let eqSub := subsetEquiv ℓ k.val dispatchBob (Nat.choose ℓ k.val) hpos (fun y => let S := Finset.univ.filter (fun i : Fin ℓ => g (y i) = true) if hS : S.card = k.val then eqSub ⟨S, hS⟩ else ⟨0, hpos⟩) (fun idxS => let S := (eqSub.symm idxS).val let hS : S.card = k.val := (eqSub.symm idxS).property let e0 := subsetComplEquiv S hS let e1 := subsetMemEquiv S hS let P0 := (parallelSim L (ℓ - k.val)).comap (fun x i => x (e0 i).val) (fun y i => y (e0 i).val) let P1 := (parallelSim R k.val).comap (fun x i => x (e1 i).val) (fun y i => y (e1 i).val) P0.bind (fun z0 => P1.map (fun z1 => combineOnSubset S hS e0 e1 z0 z1)))) theorem parallelSim_eval {X Y Z : Type*} (P : Protocol X Y Z) : ∀ (ℓ : ℕ) (x : Fin ℓ → X) (y : Fin ℓ → Y), (parallelSim P ℓ).eval x y = fun i => P.eval (x i) (y i) := by induction P with | leaf z => intro ℓ x y; rfl | alice g L R ihl ihr => intro ℓ x y simp only [parallelSim] rw [dispatchAlice_eval] rw [dispatchAlice_eval] set S0 := Finset.univ.filter (fun i : Fin ℓ => g (x i) = true) dsimp only rw [dif_pos rfl] rw [Protocol.bind_eval, Protocol.map_eval, Protocol.comap_eval, Protocol.comap_eval] rw [ihl (ℓ - S0.card), ihr S0.card] have hSidx : ((subsetEquiv ℓ S0.card).symm ((subsetEquiv ℓ S0.card) ⟨S0, rfl⟩)).val = S0 := congrArg Subtype.val (Equiv.symm_apply_apply (subsetEquiv ℓ S0.card) ⟨S0, rfl⟩) funext i simp only [combineOnSubset, Protocol.eval] by_cases hi : i ∈ ((subsetEquiv ℓ S0.card).symm ((subsetEquiv ℓ S0.card) ⟨S0, rfl⟩)).val · rw [dif_pos hi, Equiv.apply_symm_apply] rw [hSidx] at hi have hgx : g (x i) = true := (Finset.mem_filter.mp hi).2 simp [hgx] · rw [dif_neg hi, Equiv.apply_symm_apply] rw [hSidx] at hi have hgx : g (x i) ≠ true := fun h => hi (Finset.mem_filter.mpr ⟨Finset.mem_univ i, h⟩) have hgxf : g (x i) = false := Bool.eq_false_iff.mpr hgx simp [hgxf] | bob g L R ihl ihr => intro ℓ x y simp only [parallelSim] rw [dispatchBob_eval] rw [dispatchBob_eval] set S0 := Finset.univ.filter (fun i : Fin ℓ => g (y i) = true) dsimp only rw [dif_pos rfl] rw [Protocol.bind_eval, Protocol.map_eval, Protocol.comap_eval, Protocol.comap_eval] rw [ihl (ℓ - S0.card), ihr S0.card] have hSidx : ((subsetEquiv ℓ S0.card).symm ((subsetEquiv ℓ S0.card) ⟨S0, rfl⟩)).val = S0 := congrArg Subtype.val (Equiv.symm_apply_apply (subsetEquiv ℓ S0.card) ⟨S0, rfl⟩) funext i simp only [combineOnSubset, Protocol.eval] by_cases hi : i ∈ ((subsetEquiv ℓ S0.card).symm ((subsetEquiv ℓ S0.card) ⟨S0, rfl⟩)).val · rw [dif_pos hi, Equiv.apply_symm_apply] rw [hSidx] at hi have hgy : g (y i) = true := (Finset.mem_filter.mp hi).2 simp [hgy] · rw [dif_neg hi, Equiv.apply_symm_apply] rw [hSidx] at hi have hgy : g (y i) ≠ true := fun h => hi (Finset.mem_filter.mpr ⟨Finset.mem_univ i, h⟩) have hgyf : g (y i) = false := Bool.eq_false_iff.mpr hgy simp [hgyf] /-- Single-term binomial bound: `C(ℓ, k) * a^(ℓ - k) * b^k ≤ (a + b)^ℓ` for `k ≤ ℓ`. -/ private theorem choose_mul_pow_le_add_pow (ℓ k a b : ℕ) (hk : k ≤ ℓ) : Nat.choose ℓ k * a ^ (ℓ - k) * b ^ k ≤ (a + b) ^ ℓ := by rw [add_pow] have hmem : k ∈ Finset.range (ℓ + 1) := Finset.mem_range.mpr (Nat.lt_succ_of_le hk) have hle := Finset.single_le_sum (f := fun m => a ^ m * b ^ (ℓ - m) * Nat.choose ℓ m) (fun _ _ => Nat.zero_le _) (Finset.mem_range.mpr (Nat.lt_succ_of_le (Nat.sub_le ℓ k))) have hsub : ℓ - (ℓ - k) = k := Nat.sub_sub_self hk have hsymm : Nat.choose ℓ (ℓ - k) = Nat.choose ℓ k := Nat.choose_symm hk rw [hsub, hsymm] at hle calc Nat.choose ℓ k * a ^ (ℓ - k) * b ^ k = a ^ (ℓ - k) * b ^ k * Nat.choose ℓ k := by ring _ ≤ ∑ m ∈ Finset.range (ℓ + 1), a ^ m * b ^ (ℓ - m) * Nat.choose ℓ m := hle /-- **HEADLINE THEOREM 2 (Exact Non-Asymptotic Telescoping Binomial Direct-Sum Theorem)**: For every deterministic protocol `P` and every `ℓ : ℕ`, the parallel protocol `parallelSim P ℓ` computes `directSum P.eval ℓ` and satisfies the exact natural-number depth bound: `2 ^ (parallelSim P ℓ).depth ≤ P.leaves ^ ℓ * (4 * (ℓ + 1)) ^ (P.leaves - 1)`. -/ theorem telescoping_binomial_direct_sum {X Y Z : Type*} (P : Protocol X Y Z) : ∀ ℓ : ℕ, 2 ^ (parallelSim P ℓ).depth ≤ P.leaves ^ ℓ * (4 * (ℓ + 1)) ^ (P.leaves - 1) := by induction P with | leaf z => intro ℓ simp [parallelSim, Protocol.depth, Protocol.leaves] | alice g L R ihl ihr => intro ℓ have hLp := L.leaves_pos have hRp := R.leaves_pos -- Bound the depth of each weight-`k` branch by `D_k` let Dk : Fin (ℓ + 1) → ℕ := fun k => Nat.clog 2 (Nat.choose ℓ k.val) + ((parallelSim L (ℓ - k.val)).depth + (parallelSim R k.val).depth) let Dmax : ℕ := Finset.univ.sup Dk have hbranch : ∀ k : Fin (ℓ + 1), (dispatchAlice (X := Fin ℓ → X) (Y := Fin ℓ → Y) (Z := Fin ℓ → Z) (Nat.choose ℓ k.val) (Nat.choose_pos (Nat.le_of_lt_succ k.isLt)) (fun x => let S := Finset.univ.filter (fun i : Fin ℓ => g (x i) = true) if hS : S.card = k.val then (subsetEquiv ℓ k.val) ⟨S, hS⟩ else ⟨0, Nat.choose_pos (Nat.le_of_lt_succ k.isLt)⟩) (fun idxS => let S := ((subsetEquiv ℓ k.val).symm idxS).val let hS : S.card = k.val := ((subsetEquiv ℓ k.val).symm idxS).property let e0 := subsetComplEquiv S hS let e1 := subsetMemEquiv S hS let P0 := (parallelSim L (ℓ - k.val)).comap (fun x i => x (e0 i).val) (fun y i => y (e0 i).val) let P1 := (parallelSim R k.val).comap (fun x i => x (e1 i).val) (fun y i => y (e1 i).val) P0.bind (fun z0 => P1.map (fun z1 => combineOnSubset S hS e0 e1 z0 z1)))).depth ≤ Dmax := by intro k refine le_trans (dispatchAlice_depth_le _ _ _ _ ((parallelSim L (ℓ - k.val)).depth + (parallelSim R k.val).depth) ?_) (Finset.le_sup (f := Dk) (Finset.mem_univ k)) intro idxS refine le_trans (Protocol.bind_depth_le _ _ (parallelSim R k.val).depth ?_) ?_ · intro z0; rw [Protocol.map_depth, Protocol.comap_depth] · rw [Protocol.comap_depth] have hdepth : (parallelSim (.alice g L R) ℓ).depth ≤ Nat.clog 2 (ℓ + 1) + Dmax := by simpa only [parallelSim] using dispatchAlice_depth_le (ℓ + 1) (Nat.succ_pos ℓ) _ _ Dmax hbranch -- Choose `k*` attaining `Dmax` have hne : (Finset.univ : Finset (Fin (ℓ + 1))).Nonempty := ⟨⟨0, Nat.succ_pos ℓ⟩, Finset.mem_univ _⟩ rcases Finset.exists_mem_eq_sup Finset.univ hne Dk with ⟨k, _, hk_eq⟩ have hk_le : k.val ≤ ℓ := Nat.le_of_lt_succ k.isLt have hpow1 : 2 ^ Nat.clog 2 (ℓ + 1) ≤ 2 * (ℓ + 1) := two_pow_clog_le_two_mul (Nat.succ_pos ℓ) have hpow2 : 2 ^ Nat.clog 2 (Nat.choose ℓ k.val) ≤ 2 * Nat.choose ℓ k.val := two_pow_clog_le_two_mul (Nat.choose_pos hk_le) have hL_ih : 2 ^ (parallelSim L (ℓ - k.val)).depth ≤ L.leaves ^ (ℓ - k.val) * (4 * (ℓ + 1)) ^ (L.leaves - 1) := by refine le_trans (ihl (ℓ - k.val)) ?_ exact Nat.mul_le_mul_left _ (Nat.pow_le_pow_left (by omega) _) have hR_ih : 2 ^ (parallelSim R k.val).depth ≤ R.leaves ^ k.val * (4 * (ℓ + 1)) ^ (R.leaves - 1) := by refine le_trans (ihr k.val) ?_ exact Nat.mul_le_mul_left _ (Nat.pow_le_pow_left (by omega) _) have hpow_comb : (4 * (ℓ + 1)) * (4 * (ℓ + 1)) ^ (L.leaves - 1) * (4 * (ℓ + 1)) ^ (R.leaves - 1) = (4 * (ℓ + 1)) ^ ((L.leaves + R.leaves) - 1) := by rw [← Nat.pow_succ', ← Nat.pow_add]; congr 1; omega calc 2 ^ (parallelSim (.alice g L R) ℓ).depth ≤ 2 ^ (Nat.clog 2 (ℓ + 1) + Dmax) := Nat.pow_le_pow_right (by omega) hdepth _ = 2 ^ Nat.clog 2 (ℓ + 1) * (2 ^ Nat.clog 2 (Nat.choose ℓ k.val) * (2 ^ (parallelSim L (ℓ - k.val)).depth * 2 ^ (parallelSim R k.val).depth)) := by rw [show Dmax = Dk k from hk_eq]; simp only [Dk, Nat.pow_add] _ ≤ (2 * (ℓ + 1)) * ((2 * Nat.choose ℓ k.val) * ((L.leaves ^ (ℓ - k.val) * (4 * (ℓ + 1)) ^ (L.leaves - 1)) * (R.leaves ^ k.val * (4 * (ℓ + 1)) ^ (R.leaves - 1)))) := by gcongr _ = (Nat.choose ℓ k.val * L.leaves ^ (ℓ - k.val) * R.leaves ^ k.val) * ((4 * (ℓ + 1)) * (4 * (ℓ + 1)) ^ (L.leaves - 1) * (4 * (ℓ + 1)) ^ (R.leaves - 1)) := by ring _ = (Nat.choose ℓ k.val * L.leaves ^ (ℓ - k.val) * R.leaves ^ k.val) * (4 * (ℓ + 1)) ^ ((L.leaves + R.leaves) - 1) := by rw [hpow_comb] _ ≤ (L.leaves + R.leaves) ^ ℓ * (4 * (ℓ + 1)) ^ ((L.leaves + R.leaves) - 1) := by exact Nat.mul_le_mul_right _ (choose_mul_pow_le_add_pow ℓ k.val L.leaves R.leaves hk_le) | bob g L R ihl ihr => intro ℓ have hLp := L.leaves_pos have hRp := R.leaves_pos let Dk : Fin (ℓ + 1) → ℕ := fun k => Nat.clog 2 (Nat.choose ℓ k.val) + ((parallelSim L (ℓ - k.val)).depth + (parallelSim R k.val).depth) let Dmax : ℕ := Finset.univ.sup Dk have hbranch : ∀ k : Fin (ℓ + 1), (dispatchBob (X := Fin ℓ → X) (Y := Fin ℓ → Y) (Z := Fin ℓ → Z) (Nat.choose ℓ k.val) (Nat.choose_pos (Nat.le_of_lt_succ k.isLt)) (fun y => let S := Finset.univ.filter (fun i : Fin ℓ => g (y i) = true) if hS : S.card = k.val then (subsetEquiv ℓ k.val) ⟨S, hS⟩ else ⟨0, Nat.choose_pos (Nat.le_of_lt_succ k.isLt)⟩) (fun idxS => let S := ((subsetEquiv ℓ k.val).symm idxS).val let hS : S.card = k.val := ((subsetEquiv ℓ k.val).symm idxS).property let e0 := subsetComplEquiv S hS let e1 := subsetMemEquiv S hS let P0 := (parallelSim L (ℓ - k.val)).comap (fun x i => x (e0 i).val) (fun y i => y (e0 i).val) let P1 := (parallelSim R k.val).comap (fun x i => x (e1 i).val) (fun y i => y (e1 i).val) P0.bind (fun z0 => P1.map (fun z1 => combineOnSubset S hS e0 e1 z0 z1)))).depth ≤ Dmax := by intro k refine le_trans (dispatchBob_depth_le _ _ _ _ ((parallelSim L (ℓ - k.val)).depth + (parallelSim R k.val).depth) ?_) (Finset.le_sup (f := Dk) (Finset.mem_univ k)) intro idxS refine le_trans (Protocol.bind_depth_le _ _ (parallelSim R k.val).depth ?_) ?_ · intro z0; rw [Protocol.map_depth, Protocol.comap_depth] · rw [Protocol.comap_depth] have hdepth : (parallelSim (.bob g L R) ℓ).depth ≤ Nat.clog 2 (ℓ + 1) + Dmax := by simpa only [parallelSim] using dispatchBob_depth_le (ℓ + 1) (Nat.succ_pos ℓ) _ _ Dmax hbranch have hne : (Finset.univ : Finset (Fin (ℓ + 1))).Nonempty := ⟨⟨0, Nat.succ_pos ℓ⟩, Finset.mem_univ _⟩ rcases Finset.exists_mem_eq_sup Finset.univ hne Dk with ⟨k, _, hk_eq⟩ have hk_le : k.val ≤ ℓ := Nat.le_of_lt_succ k.isLt have hpow1 : 2 ^ Nat.clog 2 (ℓ + 1) ≤ 2 * (ℓ + 1) := two_pow_clog_le_two_mul (Nat.succ_pos ℓ) have hpow2 : 2 ^ Nat.clog 2 (Nat.choose ℓ k.val) ≤ 2 * Nat.choose ℓ k.val := two_pow_clog_le_two_mul (Nat.choose_pos hk_le) have hL_ih : 2 ^ (parallelSim L (ℓ - k.val)).depth ≤ L.leaves ^ (ℓ - k.val) * (4 * (ℓ + 1)) ^ (L.leaves - 1) := by refine le_trans (ihl (ℓ - k.val)) ?_ exact Nat.mul_le_mul_left _ (Nat.pow_le_pow_left (by omega) _) have hR_ih : 2 ^ (parallelSim R k.val).depth ≤ R.leaves ^ k.val * (4 * (ℓ + 1)) ^ (R.leaves - 1) := by refine le_trans (ihr k.val) ?_ exact Nat.mul_le_mul_left _ (Nat.pow_le_pow_left (by omega) _) have hpow_comb : (4 * (ℓ + 1)) * (4 * (ℓ + 1)) ^ (L.leaves - 1) * (4 * (ℓ + 1)) ^ (R.leaves - 1) = (4 * (ℓ + 1)) ^ ((L.leaves + R.leaves) - 1) := by rw [← Nat.pow_succ', ← Nat.pow_add]; congr 1; omega calc 2 ^ (parallelSim (.bob g L R) ℓ).depth ≤ 2 ^ (Nat.clog 2 (ℓ + 1) + Dmax) := Nat.pow_le_pow_right (by omega) hdepth _ = 2 ^ Nat.clog 2 (ℓ + 1) * (2 ^ Nat.clog 2 (Nat.choose ℓ k.val) * (2 ^ (parallelSim L (ℓ - k.val)).depth * 2 ^ (parallelSim R k.val).depth)) := by rw [show Dmax = Dk k from hk_eq]; simp only [Dk, Nat.pow_add] _ ≤ (2 * (ℓ + 1)) * ((2 * Nat.choose ℓ k.val) * ((L.leaves ^ (ℓ - k.val) * (4 * (ℓ + 1)) ^ (L.leaves - 1)) * (R.leaves ^ k.val * (4 * (ℓ + 1)) ^ (R.leaves - 1)))) := by gcongr _ = (Nat.choose ℓ k.val * L.leaves ^ (ℓ - k.val) * R.leaves ^ k.val) * ((4 * (ℓ + 1)) * (4 * (ℓ + 1)) ^ (L.leaves - 1) * (4 * (ℓ + 1)) ^ (R.leaves - 1)) := by ring _ = (Nat.choose ℓ k.val * L.leaves ^ (ℓ - k.val) * R.leaves ^ k.val) * (4 * (ℓ + 1)) ^ ((L.leaves + R.leaves) - 1) := by rw [hpow_comb] _ ≤ (L.leaves + R.leaves) ^ ℓ * (4 * (ℓ + 1)) ^ ((L.leaves + R.leaves) - 1) := by exact Nat.mul_le_mul_right _ (choose_mul_pow_le_add_pow ℓ k.val L.leaves R.leaves hk_le) /-- **HEADLINE COROLLARY 2 (Real Logarithmic Amortized Direct-Sum Upper Bound)**: For every protocol `P` computing `f` and every `ℓ ≥ 1`, `D(f^⊗ℓ) / ℓ ≤ log₂(P.leaves) + ((P.leaves - 1) / ℓ) * log₂(4(ℓ + 1))`. -/ theorem amortized_direct_sum_log_upper {X Y Z : Type*} (P : Protocol X Y Z) (f : X → Y → Z) (hP : P.Computes f) (ℓ : ℕ) (hℓ : 0 < ℓ) : ∃ Q : Protocol (Fin ℓ → X) (Fin ℓ → Y) (Fin ℓ → Z), Q.Computes (directSum f ℓ) ∧ (Q.depth : ℝ) / (ℓ : ℝ) ≤ Real.logb 2 (P.leaves : ℝ) + ((P.leaves - 1 : ℕ) : ℝ) * Real.logb 2 (4 * ((ℓ : ℝ) + 1)) / (ℓ : ℝ) := by refine ⟨parallelSim P ℓ, ?_, ?_⟩ · intro x y; rw [parallelSim_eval]; funext i; exact hP (x i) (y i) · have hint := telescoping_binomial_direct_sum P ℓ have hreal : ((2 : ℝ) ^ (parallelSim P ℓ).depth) ≤ (P.leaves : ℝ) ^ ℓ * (4 * ((ℓ : ℝ) + 1)) ^ (P.leaves - 1) := by exact_mod_cast hint have hLpos : (0 : ℝ) < (P.leaves : ℝ) := by exact_mod_cast P.leaves_pos have h4pos : (0 : ℝ) < 4 * ((ℓ : ℝ) + 1) := by positivity have hlog := Real.logb_le_logb_of_le (by norm_num : (1 : ℝ) < 2) (by positivity) hreal rw [Real.logb_pow, Real.logb_self_eq_one (by norm_num : (1 : ℝ) < 2), mul_one, Real.logb_mul (by positivity) (by positivity), Real.logb_pow, Real.logb_pow] at hlog have hℓR : (0 : ℝ) < (ℓ : ℝ) := by exact_mod_cast hℓ rw [div_le_iff₀ hℓR] have hmul : (Real.logb 2 (P.leaves : ℝ) + ((P.leaves - 1 : ℕ) : ℝ) * Real.logb 2 (4 * ((ℓ : ℝ) + 1)) / (ℓ : ℝ)) * (ℓ : ℝ) = (ℓ : ℝ) * Real.logb 2 (P.leaves : ℝ) + ((P.leaves - 1 : ℕ) : ℝ) * Real.logb 2 (4 * ((ℓ : ℝ) + 1)) := by field_simp [ne_of_gt hℓR] linarith /-! ## Section 4: Lower-Bound Hierarchy (Fooling Sets, Equality, and Multiplicative Color-Rank-Sum) -/ /-- A fooling set for `f : X → Y → Z` is a finite set `S` of input pairs such that no two distinct pairs `(x₁, y₁), (x₂, y₂) ∈ S` can lie in the same `f`-monochromatic rectangle. -/ def IsFoolingSet {X Y Z : Type*} (f : X → Y → Z) (S : Finset (X × Y)) : Prop := ∀ p ∈ S, ∀ q ∈ S, p ≠ q → ¬ (f p.1 p.2 = f q.1 q.2 ∧ f p.1 q.2 = f p.1 p.2 ∧ f q.1 p.2 = f p.1 p.2) /-- Fooling-set lower bound on protocol leaves and depth. -/ theorem fooling_set_leaves_lb {X Y Z : Type*} [DecidableEq Z] (P : Protocol X Y Z) (f : X → Y → Z) (hP : P.Computes f) (S : Finset (X × Y)) (hS : IsFoolingSet f S) : S.card ≤ P.leaves ∧ S.card ≤ 2 ^ P.depth := by have hinj : Set.InjOn (fun p : X × Y => (P.trace p.1 p.2, P.eval p.1 p.2)) (S : Set (X × Y)) := by intro p hp q hq heq by_contra hne have htr : P.trace p.1 p.2 = P.trace q.1 q.2 := (Prod.mk.inj heq).1 have h1 : f p.1 p.2 = f q.1 q.2 := by rw [← hP p.1 p.2, ← hP q.1 q.2] exact P.eval_eq_of_trace_eq htr have h2 : f p.1 q.2 = f p.1 p.2 := by rw [← hP p.1 q.2, ← hP p.1 p.2] exact (P.trace_rectangle htr).2 have h3 : f q.1 p.2 = f p.1 p.2 := by have h3' : f q.1 p.2 = f q.1 q.2 := by rw [← hP q.1 p.2, ← hP q.1 q.2] exact (P.trace_rectangle htr.symm).2 exact h3'.trans h1.symm exact hS p hp q hq hne ⟨h1, h2, h3⟩ have hmaps : Set.MapsTo (fun p : X × Y => (P.trace p.1 p.2, P.eval p.1 p.2)) (S : Set (X × Y)) (P.leafTable.toFinset : Set (List Bool × Z)) := by intro p _ simp only [Finset.mem_coe, List.mem_toFinset] exact P.trace_mem_leafTable p.1 p.2 have hle : S.card ≤ P.leaves := by calc S.card ≤ P.leafTable.toFinset.card := Finset.card_le_card_of_injOn _ hmaps hinj _ ≤ P.leafTable.length := List.toFinset_card_le _ _ = P.leaves := P.leafTable_length exact ⟨hle, le_trans hle P.leaves_le_two_pow_depth⟩ /-- Equality function on `Fin m`: `EQ m x y = decide (x = y)`. -/ def EQ (m : ℕ) (x y : Fin m) : Bool := decide (x = y) /-- Exact deterministic communication complexity of `EQ (2 ^ n)` for all `n ≥ 1`: `D(EQ (2 ^ n)) = n + 1`. -/ theorem eq_exact_complexity (n : ℕ) (hn : 1 ≤ n) : HasDepth (EQ (2 ^ n)) (n + 1) ∧ ¬ HasDepth (EQ (2 ^ n)) n := by have hm : 2 ≤ 2 ^ n := by have : 2 ^ 1 ≤ 2 ^ n := Nat.pow_le_pow_right (by omega) hn simpa using this have hm_pos : 0 < 2 ^ n := by omega constructor · -- Upper bound: Alice sends `x : Fin (2 ^ n)` (`n` bits), Bob sends `decide (x = y)` (`1` bit) refine ⟨dispatchAlice (2 ^ n) hm_pos id (fun x => .bob (fun y => decide (x = y)) (.leaf false) (.leaf true)), ?_, ?_⟩ · intro x y rw [dispatchAlice_eval] simp only [id_eq, Protocol.eval, EQ] by_cases h : x = y <;> simp [h] · have hclog : Nat.clog 2 (2 ^ n) = n := Nat.clog_pow 2 n (by omega) have hd := dispatchAlice_depth_le (2 ^ n) hm_pos id (fun x => .bob (fun y => decide (x = y)) (.leaf false) (.leaf true)) 1 (fun _ => by simp [Protocol.depth]) rw [hclog] at hd exact hd · -- Lower bound: diagonal + one off-diagonal pair forms a fooling set of size `2 ^ n + 1` rintro ⟨P, hP, hd⟩ let i0 : Fin (2 ^ n) := ⟨0, by omega⟩ let i1 : Fin (2 ^ n) := ⟨1, by omega⟩ have hi01 : i0 ≠ i1 := by intro h; have := congrArg Fin.val h; simp [i0, i1] at this let diag : Finset (Fin (2 ^ n) × Fin (2 ^ n)) := Finset.univ.image (fun i => (i, i)) let S : Finset (Fin (2 ^ n) × Fin (2 ^ n)) := insert (i0, i1) diag have hnotmem : (i0, i1) ∉ diag := by simp only [diag, Finset.mem_image, Finset.mem_univ, true_and, Prod.mk.injEq, not_exists] intro i ⟨h1, h2⟩; exact hi01 (h1.symm.trans h2) have hcard : S.card = 2 ^ n + 1 := by rw [Finset.card_insert_of_notMem hnotmem, Finset.card_image_of_injective _ (fun a b h => (Prod.mk.inj h).1), Finset.card_fin] have hfool : IsFoolingSet (EQ (2 ^ n)) S := by intro p hp q hq hne ⟨h1, h2, _⟩ rcases Finset.mem_insert.mp hp with rfl | hp' · rcases Finset.mem_insert.mp hq with rfl | hq' · exact hne rfl · rcases Finset.mem_image.mp hq' with ⟨j, _, rfl⟩ simp [EQ, hi01] at h1 · rcases Finset.mem_image.mp hp' with ⟨i, _, rfl⟩ rcases Finset.mem_insert.mp hq with rfl | hq' · simp [EQ, hi01] at h1 · rcases Finset.mem_image.mp hq' with ⟨j, _, rfl⟩ have hij : i ≠ j := fun h => hne (by rw [h]) simp [EQ, hij] at h2 have hlb := (fooling_set_leaves_lb P (EQ (2 ^ n)) hP S hfool).2 rw [hcard] at hlb have hpow : 2 ^ P.depth ≤ 2 ^ n := Nat.pow_le_pow_right (by omega) hd omega /-! ### Linear-Algebraic Color-Rank-Sum Lower Bound & Kronecker Rank Multiplicativity -/ /-- The monochromatic `ℚ`-indicator matrix of color `z` for `f : X → Y → Z`. -/ def colorMatrix {X Y Z : Type*} [DecidableEq Z] (f : X → Y → Z) (z : Z) : Matrix X Y ℚ := fun x y => if f x y = z then 1 else 0 /-- Number of leaves of a protocol tree `P` labeled with output `z`. -/ def Protocol.colorLeaves {X Y Z : Type*} [DecidableEq Z] : Protocol X Y Z → Z → ℕ | .leaf w, z => if w = z then 1 else 0 | .alice _ l r, z => l.colorLeaves z + r.colorLeaves z | .bob _ l r, z => l.colorLeaves z + r.colorLeaves z theorem Protocol.sum_colorLeaves {X Y Z : Type*} [Fintype Z] [DecidableEq Z] (P : Protocol X Y Z) : ∑ z : Z, P.colorLeaves z = P.leaves := by induction P with | leaf w => simp only [Protocol.colorLeaves, Protocol.leaves] rw [Finset.sum_ite_eq Finset.univ w] simp | alice _ l r ihl ihr => simp only [Protocol.colorLeaves, Protocol.leaves, Finset.sum_add_distrib, ihl, ihr] | bob _ l r ihl ihr => simp only [Protocol.colorLeaves, Protocol.leaves, Finset.sum_add_distrib, ihl, ihr] /-- Rank subadditivity for matrices over `ℚ`. -/ theorem matrix_rank_add_le {X Y : Type*} [Fintype X] [Fintype Y] (M N : Matrix X Y ℚ) : (M + N).rank ≤ M.rank + N.rank := by simp only [Matrix.rank] have hsub : LinearMap.range (M + N).mulVecLin ≤ LinearMap.range M.mulVecLin ⊔ LinearMap.range N.mulVecLin := by rintro v ⟨u, rfl⟩ rw [Matrix.mulVecLin_apply, Matrix.add_mulVec] exact Submodule.add_mem_sup ⟨u, rfl⟩ ⟨u, rfl⟩ calc Module.finrank ℚ (LinearMap.range (M + N).mulVecLin) ≤ Module.finrank ℚ ↥(LinearMap.range M.mulVecLin ⊔ LinearMap.range N.mulVecLin) := Submodule.finrank_mono hsub _ ≤ Module.finrank ℚ (LinearMap.range M.mulVecLin) + Module.finrank ℚ (LinearMap.range N.mulVecLin) := by have h := Submodule.finrank_sup_add_finrank_inf_eq (LinearMap.range M.mulVecLin) (LinearMap.range N.mulVecLin) omega /-- Row-masking a matrix does not increase its rank. -/ theorem matrix_rank_maskRows_le {X Y : Type*} [Fintype X] [Fintype Y] (p : X → Bool) (M : Matrix X Y ℚ) : (Matrix.of fun x y => if p x then M x y else 0).rank ≤ M.rank := by let proj : (X → ℚ) →ₗ[ℚ] (X → ℚ) := { toFun := fun v x => if p x then v x else 0 map_add' := fun u v => by funext x; by_cases h : p x <;> simp [h] map_smul' := fun c v => by funext x; by_cases h : p x <;> simp [h] } have hcomp : (Matrix.of fun x y => if p x then M x y else 0).mulVecLin = proj.comp M.mulVecLin := by ext v x simp only [Matrix.mulVecLin_apply, Matrix.mulVec, dotProduct, Matrix.of_apply, LinearMap.comp_apply, proj, LinearMap.coe_mk, AddHom.coe_mk] by_cases h : p x <;> simp [h] simp only [Matrix.rank] rw [hcomp, LinearMap.range_comp] exact Submodule.finrank_map_le proj (LinearMap.range M.mulVecLin) /-- Column-masking a matrix does not increase its rank. -/ theorem matrix_rank_maskCols_le {X Y : Type*} [Fintype X] [Fintype Y] (p : Y → Bool) (M : Matrix X Y ℚ) : (Matrix.of fun x y => if p y then M x y else 0).rank ≤ M.rank := by let proj : (Y → ℚ) →ₗ[ℚ] (Y → ℚ) := { toFun := fun v y => if p y then v y else 0 map_add' := fun u v => by funext y; by_cases h : p y <;> simp [h] map_smul' := fun c v => by funext y; by_cases h : p y <;> simp [h] } have hcomp : (Matrix.of fun x y => if p y then M x y else 0).mulVecLin = M.mulVecLin.comp proj := by ext v x simp only [Matrix.mulVecLin_apply, Matrix.mulVec, dotProduct, Matrix.of_apply, LinearMap.comp_apply, proj, LinearMap.coe_mk, AddHom.coe_mk] congr 1; funext y; by_cases h : p y <;> simp [h] simp only [Matrix.rank] rw [hcomp] exact Submodule.finrank_mono (LinearMap.range_comp_le_range proj M.mulVecLin) /-- Per-color rank lower bound: for every protocol `P` and color `z`, `rank (colorMatrix P.eval z) ≤ P.colorLeaves z`. -/ theorem colorMatrix_rank_le_colorLeaves {X Y Z : Type*} [Fintype X] [Fintype Y] [DecidableEq Z] (P : Protocol X Y Z) (z : Z) : (colorMatrix P.eval z).rank ≤ P.colorLeaves z := by induction P with | leaf w => by_cases hw : w = z · subst hw simp only [Protocol.colorLeaves, ↓reduceIte, Matrix.rank] have hsub : LinearMap.range (colorMatrix (Protocol.leaf (X := X) (Y := Y) w).eval w).mulVecLin ≤ Submodule.span ℚ ({fun _ : X => (1 : ℚ)} : Set (X → ℚ)) := by rintro v ⟨u, rfl⟩ rw [Submodule.mem_span_singleton] refine ⟨∑ y : Y, u y, ?_⟩ funext x simp [Matrix.mulVec, dotProduct, colorMatrix, Protocol.eval] calc Module.finrank ℚ (LinearMap.range (colorMatrix (Protocol.leaf (X := X) (Y := Y) w).eval w).mulVecLin) ≤ Module.finrank ℚ (Submodule.span ℚ ({fun _ : X => (1 : ℚ)} : Set (X → ℚ))) := Submodule.finrank_mono hsub _ ≤ 1 := by have hle := finrank_span_le_card (R := ℚ) ({fun _ : X => (1 : ℚ)} : Set (X → ℚ)) simpa using hle · simp only [Protocol.colorLeaves, hw, ↓reduceIte] have hzero : colorMatrix (Protocol.leaf (X := X) (Y := Y) w).eval z = (0 : Matrix X Y ℚ) := by ext x y; simp [colorMatrix, Protocol.eval, hw] rw [hzero, Matrix.rank] have hr : LinearMap.range (0 : Matrix X Y ℚ).mulVecLin = ⊥ := by ext v; simp rw [hr, finrank_bot] | alice g L R ihl ihr => have hsplit : colorMatrix (Protocol.alice g L R).eval z = (Matrix.of fun x y => if !g x then colorMatrix L.eval z x y else 0) + (Matrix.of fun x y => if g x then colorMatrix R.eval z x y else 0) := by ext x y simp only [colorMatrix, Protocol.eval, Matrix.add_apply, Matrix.of_apply] by_cases hgx : g x = true <;> simp [hgx] rw [hsplit] calc ((Matrix.of fun x y => if !g x then colorMatrix L.eval z x y else 0) + (Matrix.of fun x y => if g x then colorMatrix R.eval z x y else 0)).rank ≤ (Matrix.of fun x y => if !g x then colorMatrix L.eval z x y else 0).rank + (Matrix.of fun x y => if g x then colorMatrix R.eval z x y else 0).rank := matrix_rank_add_le _ _ _ ≤ (colorMatrix L.eval z).rank + (colorMatrix R.eval z).rank := Nat.add_le_add (matrix_rank_maskRows_le _ _) (matrix_rank_maskRows_le _ _) _ ≤ L.colorLeaves z + R.colorLeaves z := Nat.add_le_add ihl ihr | bob g L R ihl ihr => have hsplit : colorMatrix (Protocol.bob g L R).eval z = (Matrix.of fun x y => if !g y then colorMatrix L.eval z x y else 0) + (Matrix.of fun x y => if g y then colorMatrix R.eval z x y else 0) := by ext x y simp only [colorMatrix, Protocol.eval, Matrix.add_apply, Matrix.of_apply] by_cases hgy : g y = true <;> simp [hgy] rw [hsplit] calc ((Matrix.of fun x y => if !g y then colorMatrix L.eval z x y else 0) + (Matrix.of fun x y => if g y then colorMatrix R.eval z x y else 0)).rank ≤ (Matrix.of fun x y => if !g y then colorMatrix L.eval z x y else 0).rank + (Matrix.of fun x y => if g y then colorMatrix R.eval z x y else 0).rank := matrix_rank_add_le _ _ _ ≤ (colorMatrix L.eval z).rank + (colorMatrix R.eval z).rank := Nat.add_le_add (matrix_rank_maskCols_le _ _) (matrix_rank_maskCols_le _ _) _ ≤ L.colorLeaves z + R.colorLeaves z := Nat.add_le_add ihl ihr /-- **Color-Rank-Sum Lower Bound**: for every protocol `P` computing `f : X → Y → Z`, `∑ z : Z, (colorMatrix f z).rank ≤ P.leaves ≤ 2 ^ P.depth`. -/ theorem color_rank_sum_leaves_lb {X Y Z : Type*} [Fintype X] [Fintype Y] [Fintype Z] [DecidableEq Z] (P : Protocol X Y Z) (f : X → Y → Z) (hP : P.Computes f) : ∑ z : Z, (colorMatrix f z).rank ≤ P.leaves ∧ ∑ z : Z, (colorMatrix f z).rank ≤ 2 ^ P.depth := by have heq : ∀ z, colorMatrix f z = colorMatrix P.eval z := by intro z; ext x y; simp [colorMatrix, hP x y] have h1 : ∑ z : Z, (colorMatrix f z).rank ≤ P.leaves := by calc ∑ z : Z, (colorMatrix f z).rank = ∑ z : Z, (colorMatrix P.eval z).rank := by simp only [heq] _ ≤ ∑ z : Z, P.colorLeaves z := Finset.sum_le_sum (fun z _ => colorMatrix_rank_le_colorLeaves P z) _ = P.leaves := P.sum_colorLeaves exact ⟨h1, le_trans h1 P.leaves_le_two_pow_depth⟩ /-- Linear independence of pointwise tensor products of linearly independent families of vectors. -/ theorem linearIndependent_pointwise_mul {I J X Y : Type*} {u : I → (X → ℚ)} {v : J → (Y → ℚ)} (hu : LinearIndependent ℚ u) (hv : LinearIndependent ℚ v) : LinearIndependent ℚ (fun p : I × J => fun q : X × Y => u p.1 q.1 * v p.2 q.2) := by classical rw [linearIndependent_iff'] at hu hv ⊢ intro s g hsum p hp -- Write `s` inside `s₁ ×ˢ s₂` let s₁ : Finset I := s.image Prod.fst let s₂ : Finset J := s.image Prod.snd let gExt : I × J → ℚ := fun q => if q ∈ s then g q else 0 have hsum2 : ∀ x y, ∑ i ∈ s₁, ∑ j ∈ s₂, gExt (i, j) * (u i x * v j y) = 0 := by intro x y have h0 := congrFun hsum (x, y) simp only [Finset.sum_apply, Pi.smul_apply, smul_eq_mul, Pi.zero_apply] at h0 rw [← Finset.sum_product'] have hsub : s ⊆ s₁ ×ˢ s₂ := by intro q hq exact Finset.mem_product.mpr ⟨Finset.mem_image_of_mem Prod.fst hq, Finset.mem_image_of_mem Prod.snd hq⟩ rw [← Finset.sum_subset hsub] · calc ∑ q ∈ s, gExt q * (u q.1 x * v q.2 y) = ∑ q ∈ s, g q * (u q.1 x * v q.2 y) := Finset.sum_congr rfl (fun q hq => by simp [gExt, hq]) _ = 0 := h0 · intro q _ hq; simp [gExt, hq] have hinner : ∀ x : X, ∀ j ∈ s₂, ∑ i ∈ s₁, gExt (i, j) * u i x = 0 := by intro x apply hv s₂ (fun j => ∑ i ∈ s₁, gExt (i, j) * u i x) funext y simp only [Finset.sum_apply, Pi.smul_apply, smul_eq_mul, Pi.zero_apply] calc ∑ j ∈ s₂, (∑ i ∈ s₁, gExt (i, j) * u i x) * v j y = ∑ j ∈ s₂, ∑ i ∈ s₁, gExt (i, j) * (u i x * v j y) := by refine Finset.sum_congr rfl (fun j _ => ?_) rw [Finset.sum_mul]; refine Finset.sum_congr rfl (fun i _ => by ring) _ = ∑ i ∈ s₁, ∑ j ∈ s₂, gExt (i, j) * (u i x * v j y) := Finset.sum_comm _ = 0 := hsum2 x y have hp1 : p.1 ∈ s₁ := Finset.mem_image_of_mem Prod.fst hp have hp2 : p.2 ∈ s₂ := Finset.mem_image_of_mem Prod.snd hp have hzero : gExt (p.1, p.2) = 0 := by apply hu s₁ (fun i => gExt (i, p.2)) _ p.1 hp1 funext x simp only [Finset.sum_apply, Pi.smul_apply, smul_eq_mul, Pi.zero_apply] exact hinner x p.2 hp2 simpa [gExt, hp] using hzero /-- If a matrix `M` has `r` linearly independent vectors in the range of `M.mulVecLin`, then `r ≤ M.rank`. -/ theorem card_le_matrix_rank_of_linearIndependent {X Y I : Type*} [Fintype X] [Fintype Y] [Fintype I] (M : Matrix X Y ℚ) (u : I → (X → ℚ)) (hmem : ∀ i, u i ∈ LinearMap.range M.mulVecLin) (hli : LinearIndependent ℚ u) : Fintype.card I ≤ M.rank := by let u' : I → LinearMap.range M.mulVecLin := fun i => ⟨u i, hmem i⟩ have hli' : LinearIndependent ℚ u' := by refine LinearIndependent.of_comp (LinearMap.range M.mulVecLin).subtype ?_ exact hli simpa only [Matrix.rank] using hli'.fintype_card_le_finrank /-- Any matrix `M` has a linearly independent family of size `M.rank` inside `range M.mulVecLin`. -/ theorem exists_linearIndependent_in_range {X Y : Type*} [Fintype X] [Fintype Y] (M : Matrix X Y ℚ) : ∃ u : Fin M.rank → (X → ℚ), (∀ i, ∃ v : Y → ℚ, M.mulVec v = u i) ∧ LinearIndependent ℚ u := by let b := Module.finBasis ℚ (LinearMap.range M.mulVecLin) refine ⟨fun i => (b i : X → ℚ), ?_, ?_⟩ · intro i exact (b i).property · have hli := b.linearIndependent exact hli.map' (LinearMap.range M.mulVecLin).subtype (Submodule.ker_subtype _) /-- Kronecker-product rank lower bound (multi-fold version for `directSum f ℓ`): for every color vector `z : Fin ℓ → Z`, `∏ t : Fin ℓ, (colorMatrix f (z t)).rank ≤ (colorMatrix (directSum f ℓ) z).rank`. -/ theorem directSum_colorMatrix_rank_ge {X Y Z : Type*} [Fintype X] [Fintype Y] [DecidableEq Z] (f : X → Y → Z) : ∀ (ℓ : ℕ) (z : Fin ℓ → Z), ∏ t : Fin ℓ, (colorMatrix f (z t)).rank ≤ (colorMatrix (directSum f ℓ) z).rank := by intro ℓ induction ℓ with | zero => intro z simp only [Finset.univ_eq_empty, Finset.prod_empty] let u : Fin 1 → ((Fin 0 → X) → ℚ) := fun _ _ => 1 have hmem : ∀ i : Fin 1, u i ∈ LinearMap.range (colorMatrix (directSum f 0) z).mulVecLin := by intro _ refine ⟨fun _ => 1, ?_⟩ funext x simp only [Matrix.mulVecLin_apply, Matrix.mulVec, dotProduct, colorMatrix, u] have htriv : ∀ y : Fin 0 → Y, directSum f 0 x y = z := fun _ => funext (fun i => Fin.elim0 i) have hcardY : Fintype.card (Fin 0 → Y) = 1 := by simp simp only [htriv, ↓reduceIte, mul_one, Finset.sum_const, Finset.card_univ, hcardY, one_smul] have hli : LinearIndependent ℚ u := by rw [linearIndependent_iff'] intro s g hsum i hi have h0 := congrFun hsum Fin.elim0 have hs : s = {i} := by ext j; simp only [Finset.mem_singleton] exact ⟨fun _ => Subsingleton.elim j i, fun h => h ▸ hi⟩ rw [hs, Finset.sum_singleton] at h0 simpa [u] using h0 have hcard := card_le_matrix_rank_of_linearIndependent (colorMatrix (directSum f 0) z) u hmem hli simpa only [Fintype.card_fin] using hcard | succ m ih => intro z let z0 : Z := z 0 let ztail : Fin m → Z := fun i => z i.succ rcases exists_linearIndependent_in_range (colorMatrix f z0) with ⟨u0, hu0_mem, hu0_li⟩ rcases exists_linearIndependent_in_range (colorMatrix (directSum f m) ztail) with ⟨ut, hut_mem, hut_li⟩ -- Build the pointwise product family on `Fin (m + 1) → X` let eX : (Fin (m + 1) → X) ≃ X × (Fin m → X) := { toFun := fun x => (x 0, fun i => x i.succ) invFun := fun p => Fin.cons p.1 p.2 left_inv := fun x => by funext i; refine Fin.cases ?_ ?_ i <;> simp right_inv := fun ⟨a, b⟩ => by simp } let eY : (Fin (m + 1) → Y) ≃ Y × (Fin m → Y) := { toFun := fun y => (y 0, fun i => y i.succ) invFun := fun p => Fin.cons p.1 p.2 left_inv := fun y => by funext i; refine Fin.cases ?_ ?_ i <;> simp right_inv := fun ⟨a, b⟩ => by simp } let wProd : Fin (colorMatrix f z0).rank × Fin (colorMatrix (directSum f m) ztail).rank → (X × (Fin m → X) → ℚ) := fun p q => u0 p.1 q.1 * ut p.2 q.2 have hwProd_li : LinearIndependent ℚ wProd := linearIndependent_pointwise_mul hu0_li hut_li let w : Fin (colorMatrix f z0).rank × Fin (colorMatrix (directSum f m) ztail).rank → ((Fin (m + 1) → X) → ℚ) := fun p x => wProd p (eX x) have hw_li : LinearIndependent ℚ w := by rw [linearIndependent_iff'] at hwProd_li ⊢ intro s g hsum p hp apply hwProd_li s g _ p hp funext q have h0 := congrFun hsum (eX.symm q) simpa [w, eX.apply_symm_apply] using h0 have hw_mem : ∀ p, w p ∈ LinearMap.range (colorMatrix (directSum f (m + 1)) z).mulVecLin := by intro ⟨i, j⟩ rcases hu0_mem i with ⟨v0, hv0⟩ rcases hut_mem j with ⟨vt, hvt⟩ refine ⟨fun y => v0 (y 0) * vt (fun k => y k.succ), ?_⟩ funext x simp only [Matrix.mulVecLin_apply, Matrix.mulVec, dotProduct] have hfact : ∀ y : Fin (m + 1) → Y, colorMatrix (directSum f (m + 1)) z x y = colorMatrix f z0 (x 0) (y 0) * colorMatrix (directSum f m) ztail (fun k => x k.succ) (fun k => y k.succ) := by intro y change (if (fun t : Fin (m + 1) => f (x t) (y t)) = z then (1 : ℚ) else 0) = (if f (x 0) (y 0) = z 0 then (1 : ℚ) else 0) * (if (fun k : Fin m => f (x k.succ) (y k.succ)) = fun k => z k.succ then (1 : ℚ) else 0) have hiff : (fun t : Fin (m + 1) => f (x t) (y t)) = z ↔ (f (x 0) (y 0) = z 0 ∧ (fun k : Fin m => f (x k.succ) (y k.succ)) = fun k => z k.succ) := by constructor · intro h refine ⟨congrFun h 0, ?_⟩ funext k; exact congrFun h k.succ · rintro ⟨h0, ht⟩ funext t; refine Fin.cases h0 (fun k => congrFun ht k) t by_cases h1 : f (x 0) (y 0) = z 0 <;> by_cases h2 : (fun k : Fin m => f (x k.succ) (y k.succ)) = fun k => z k.succ · have h12 : (fun t : Fin (m + 1) => f (x t) (y t)) = z := hiff.mpr ⟨h1, h2⟩ rw [if_pos h12, if_pos h1, if_pos h2, mul_one] · have h12 : ¬ ((fun t : Fin (m + 1) => f (x t) (y t)) = z) := fun h => h2 (hiff.mp h).2 rw [if_neg h12, if_pos h1, if_neg h2, mul_zero] · have h12 : ¬ ((fun t : Fin (m + 1) => f (x t) (y t)) = z) := fun h => h1 (hiff.mp h).1 rw [if_neg h12, if_neg h1, if_pos h2, zero_mul] · have h12 : ¬ ((fun t : Fin (m + 1) => f (x t) (y t)) = z) := fun h => h1 (hiff.mp h).1 rw [if_neg h12, if_neg h1, if_neg h2, zero_mul] calc ∑ y : Fin (m + 1) → Y, colorMatrix (directSum f (m + 1)) z x y * (v0 (y 0) * vt (fun k => y k.succ)) = ∑ q : Y × (Fin m → Y), (colorMatrix f z0 (x 0) q.1 * v0 q.1) * (colorMatrix (directSum f m) ztail (fun k => x k.succ) q.2 * vt q.2) := by refine Fintype.sum_equiv eY _ _ (fun y => ?_) rw [hfact y] simp only [eY, Equiv.coe_fn_mk] ring _ = (∑ y0 : Y, colorMatrix f z0 (x 0) y0 * v0 y0) * (∑ yt : Fin m → Y, colorMatrix (directSum f m) ztail (fun k => x k.succ) yt * vt yt) := by rw [Fintype.sum_prod_type, Finset.sum_mul] refine Finset.sum_congr rfl (fun y0 _ => by rw [Finset.mul_sum]) _ = u0 i (x 0) * ut j (fun k => x k.succ) := by have h1 := congrFun hv0 (x 0) have h2 := congrFun hvt (fun k => x k.succ) simp only [Matrix.mulVec, dotProduct] at h1 h2 rw [h1, h2] _ = w (i, j) x := rfl have hcard := card_le_matrix_rank_of_linearIndependent (colorMatrix (directSum f (m + 1)) z) w hw_mem hw_li rw [Fintype.card_prod, Fintype.card_fin, Fintype.card_fin] at hcard rw [Fin.prod_univ_succ] exact le_trans (Nat.mul_le_mul_left _ (ih ztail)) hcard /-- **HEADLINE THEOREM 3 (Multiplicative Direct-Sum Color-Rank-Sum Lower Bound)**: For every finite communication problem `f : X → Y → Z`, every `ℓ : ℕ`, and every protocol `P` computing `directSum f ℓ`: `(∑ z : Z, (colorMatrix f z).rank) ^ ℓ ≤ P.leaves ≤ 2 ^ P.depth`. -/ theorem direct_sum_color_rank_sum_lb {X Y Z : Type*} [Fintype X] [Fintype Y] [Fintype Z] [DecidableEq Z] (f : X → Y → Z) (ℓ : ℕ) (P : Protocol (Fin ℓ → X) (Fin ℓ → Y) (Fin ℓ → Z)) (hP : P.Computes (directSum f ℓ)) : (∑ z : Z, (colorMatrix f z).rank) ^ ℓ ≤ P.leaves ∧ (∑ z : Z, (colorMatrix f z).rank) ^ ℓ ≤ 2 ^ P.depth := by have hpow : (∑ z : Z, (colorMatrix f z).rank) ^ ℓ = ∑ zv : Fin ℓ → Z, ∏ t : Fin ℓ, (colorMatrix f (zv t)).rank := by rw [Fintype.sum_pow] have hsum_le : (∑ z : Z, (colorMatrix f z).rank) ^ ℓ ≤ ∑ zv : Fin ℓ → Z, (colorMatrix (directSum f ℓ) zv).rank := by rw [hpow] exact Finset.sum_le_sum (fun zv _ => directSum_colorMatrix_rank_ge f ℓ zv) have ⟨hlb1, hlb2⟩ := color_rank_sum_leaves_lb P (directSum f ℓ) hP exact ⟨le_trans hsum_le hlb1, le_trans hsum_le hlb2⟩ /-- **HEADLINE COROLLARY 3 (Amortized Deterministic Communication Sandwich Theorem)**: For every protocol `P₀` computing `f` and every `ℓ ≥ 1`, `log₂(∑ z, rank M_{f,z}) ≤ D(f^⊗ℓ) / ℓ ≤ log₂ L(P₀) + ((L(P₀) - 1)/ℓ) log₂(4(ℓ + 1))`. -/ theorem amortized_sandwich_theorem {X Y Z : Type*} [Fintype X] [Fintype Y] [Fintype Z] [DecidableEq Z] (f : X → Y → Z) (P₀ : Protocol X Y Z) (hP₀ : P₀.Computes f) (ℓ : ℕ) (hℓ : 0 < ℓ) (hrank_pos : 0 < ∑ z : Z, (colorMatrix f z).rank) : (∀ P : Protocol (Fin ℓ → X) (Fin ℓ → Y) (Fin ℓ → Z), P.Computes (directSum f ℓ) → Real.logb 2 ((∑ z : Z, (colorMatrix f z).rank : ℕ) : ℝ) ≤ (P.depth : ℝ) / (ℓ : ℝ)) ∧ (∃ Q : Protocol (Fin ℓ → X) (Fin ℓ → Y) (Fin ℓ → Z), Q.Computes (directSum f ℓ) ∧ (Q.depth : ℝ) / (ℓ : ℝ) ≤ Real.logb 2 (P₀.leaves : ℝ) + ((P₀.leaves - 1 : ℕ) : ℝ) * Real.logb 2 (4 * ((ℓ : ℝ) + 1)) / (ℓ : ℝ)) := by refine ⟨?_, amortized_direct_sum_log_upper P₀ f hP₀ ℓ hℓ⟩ intro P hP have hlb := (direct_sum_color_rank_sum_lb f ℓ P hP).2 have hreal : ((∑ z : Z, (colorMatrix f z).rank : ℕ) : ℝ) ^ ℓ ≤ (2 : ℝ) ^ P.depth := by exact_mod_cast hlb have hrpos : (0 : ℝ) < ((∑ z : Z, (colorMatrix f z).rank : ℕ) : ℝ) := by exact_mod_cast hrank_pos have hlog := Real.logb_le_logb_of_le (by norm_num : (1 : ℝ) < 2) (by positivity) hreal rw [Real.logb_pow, Real.logb_pow, Real.logb_self_eq_one (by norm_num : (1 : ℝ) < 2), mul_one] at hlog have hℓR : (0 : ℝ) < (ℓ : ℝ) := by exact_mod_cast hℓ rw [le_div_iff₀ hℓR] linarith /-! ## Section 5: Exact Characterization of `GT n`, Two-Copy Direct-Sum Refutation, and Exact `IND k` -/ /-- Triangular Greater-Than / threshold Boolean matrix `GT n : Fin n → Fin n → Bool`, defined by `GT n i j = decide (i.val + j.val < n - 1)`. -/ def GT (n : ℕ) (i j : Fin n) : Bool := decide (i.val + j.val < n - 1) /-- Sequential `ℓ`-fold direct-sum protocol obtained by running `P` independently on each coordinate; its exact leaf count is `P.leaves ^ ℓ`. -/ def seqDirectSum {X Y Z : Type*} (P : Protocol X Y Z) : (ℓ : ℕ) → Protocol (Fin ℓ → X) (Fin ℓ → Y) (Fin ℓ → Z) | 0 => .leaf Fin.elim0 | ℓ + 1 => (P.comap (fun x => x 0) (fun y => y 0)).bind (fun z0 => ((seqDirectSum P ℓ).comap (fun x i => x i.succ) (fun y i => y i.succ)).map (fun zt => Fin.cons z0 zt)) theorem seqDirectSum_eval {X Y Z : Type*} (P : Protocol X Y Z) : ∀ (ℓ : ℕ) (x : Fin ℓ → X) (y : Fin ℓ → Y), (seqDirectSum P ℓ).eval x y = fun i => P.eval (x i) (y i) := by intro ℓ induction ℓ with | zero => intro x y; funext i; exact Fin.elim0 i | succ m ih => intro x y simp only [seqDirectSum, Protocol.bind_eval, Protocol.map_eval, Protocol.comap_eval, ih] funext i; refine Fin.cases ?_ ?_ i <;> simp theorem Protocol.bind_leaves_mul {X Y Z W : Type*} (P : Protocol X Y Z) (Q : Z → Protocol X Y W) (m : ℕ) (hQ : ∀ z, (Q z).leaves = m) : (P.bind Q).leaves = P.leaves * m := by induction P with | leaf z => simpa [Protocol.bind, Protocol.leaves] using hQ z | alice _ l r ihl ihr => simp only [Protocol.bind, Protocol.leaves, ihl, ihr, Nat.add_mul] | bob _ l r ihl ihr => simp only [Protocol.bind, Protocol.leaves, ihl, ihr, Nat.add_mul] theorem seqDirectSum_leaves {X Y Z : Type*} (P : Protocol X Y Z) : ∀ ℓ : ℕ, (seqDirectSum P ℓ).leaves = P.leaves ^ ℓ := by intro ℓ induction ℓ with | zero => rfl | succ m ih => simp only [seqDirectSum] rw [Protocol.bind_leaves_mul _ _ (P.leaves ^ m) (fun _ => by rw [Protocol.map_leaves, Protocol.comap_leaves, ih])] rw [Protocol.comap_leaves, pow_succ'] /-- Explicit `(2 * n - 1)`-leaf protocol for `GT n` (`n ≥ 1`): Alice scans rows `r = 0, …, n - 2` (on each active row `r`, Bob sends 1 bit `j < n - 1 - r`), and on the final row `r = n - 1`, Alice immediately outputs `false` (1 leaf). -/ def gtProtoAux (n : ℕ) : (k : ℕ) → Protocol (Fin n) (Fin n) Bool | 0 => .leaf false | k + 1 => .alice (fun i => decide (i.val = k)) (gtProtoAux n k) (.bob (fun j => decide (j.val + k < n - 1)) (.leaf false) (.leaf true)) def gtProto (n : ℕ) : Protocol (Fin n) (Fin n) Bool := gtProtoAux n (n - 1) theorem gtProtoAux_leaves (n k : ℕ) : (gtProtoAux n k).leaves = 2 * k + 1 := by induction k with | zero => rfl | succ m ih => simp only [gtProtoAux, Protocol.leaves, ih] omega theorem gtProto_leaves (n : ℕ) (hn : 1 ≤ n) : (gtProto n).leaves = 2 * n - 1 := by rw [gtProto, gtProtoAux_leaves]; omega theorem gtProtoAux_eval (n : ℕ) : ∀ (k : ℕ) (i j : Fin n), (gtProtoAux n k).eval i j = if i.val < k then decide (i.val + j.val < n - 1) else false := by intro k induction k with | zero => intro i j; simp [gtProtoAux, Protocol.eval] | succ m ih => intro i j simp only [gtProtoAux, Protocol.eval] by_cases hEq : i.val = m · simp only [decide_eq_true_eq, hEq, ↓reduceIte] have hlt : m < m + 1 := Nat.lt_succ_self m simp only [hlt, ↓reduceIte] have hcomm : j.val + m = m + j.val := Nat.add_comm _ _ rw [hcomm] by_cases hlt' : m + j.val < n - 1 <;> simp [hlt'] · simp only [decide_eq_true_eq, hEq, ↓reduceIte, ih] by_cases hlt : i.val < m · have hlt' : i.val < m + 1 := Nat.lt_succ_of_lt hlt simp [hlt, hlt'] · have hnot : ¬ i.val < m + 1 := by omega simp [hlt, hnot] theorem gtProto_computes (n : ℕ) (hn : 1 ≤ n) : (gtProto n).Computes (GT n) := by intro i j rw [gtProto, gtProtoAux_eval] simp only [GT] by_cases h : i.val < n - 1 · simp [h] · have hi : i.val = n - 1 := by omega have hnot : ¬ (i.val + j.val < n - 1) := by omega simp [h, hnot] /-- Exact rank lower bound on the `true`-color matrix of `GT n`: `n - 1 ≤ rank (colorMatrix (GT n) true)`. -/ theorem gt_true_rank_ge (n : ℕ) : n - 1 ≤ (colorMatrix (GT n) true).rank := by cases n with | zero => simp | succ m => simp only [Nat.add_sub_cancel] let u : Fin m → (Fin (m + 1) → ℚ) := fun j i => colorMatrix (GT (m + 1)) true i ⟨j.val, Nat.lt_succ_of_lt j.isLt⟩ have hmem : ∀ j : Fin m, u j ∈ LinearMap.range (colorMatrix (GT (m + 1)) true).mulVecLin := by intro j refine ⟨Pi.single ⟨j.val, Nat.lt_succ_of_lt j.isLt⟩ 1, ?_⟩ funext i simp [Matrix.mulVec, dotProduct, Pi.single_apply, u] have hli : LinearIndependent ℚ u := by rw [linearIndependent_iff'] intro s g hsum suffices ∀ r : ℕ, ∀ j : Fin m, j.val ≤ r → j ∈ s → g j = 0 by intro j hj; exact this m j (le_of_lt j.isLt) hj intro r induction r with | zero => intro j hj0 hj have hjv : j.val = 0 := Nat.eq_zero_of_le_zero hj0 let row : Fin (m + 1) := ⟨m - 1, by omega⟩ have h0 := congrFun hsum row simp only [Finset.sum_apply, Pi.smul_apply, smul_eq_mul, Pi.zero_apply] at h0 have hterm : ∀ k ∈ s, g k * u k row = if k = j then g j else 0 := by intro k _ by_cases hkj : k = j · subst hkj have hlt : (m - 1) + k.val < m := by omega simp [u, colorMatrix, GT, row, hlt] · have hkpos : 1 ≤ k.val := by have hne : k.val ≠ j.val := fun h => hkj (Fin.ext h) omega have hnot : ¬ ((m - 1) + k.val < m) := by omega simp [u, colorMatrix, GT, row, hkj, hnot] rw [Finset.sum_congr rfl hterm, Finset.sum_ite_eq' s j] at h0 simpa [hj] using h0 | succ r' ih => intro j hjle hj by_cases hlt : j.val ≤ r' · exact ih j hlt hj · have hjv : j.val = r' + 1 := by omega let row : Fin (m + 1) := ⟨m - 1 - j.val, by omega⟩ have h0 := congrFun hsum row simp only [Finset.sum_apply, Pi.smul_apply, smul_eq_mul, Pi.zero_apply] at h0 have hterm : ∀ k ∈ s, g k * u k row = if k = j then g j else 0 := by intro k hk by_cases hkj : k = j · subst hkj have hok : (m - 1 - k.val) + k.val < m := by omega simp [u, colorMatrix, GT, row, hok] · by_cases hklt : k.val ≤ r' · simp [hkj, ih k hklt hk] · have hnot : ¬ ((m - 1 - j.val) + k.val < m) := by omega simp [u, colorMatrix, GT, row, hkj, hnot] rw [Finset.sum_congr rfl hterm, Finset.sum_ite_eq' s j] at h0 simpa [hj] using h0 simpa using card_le_matrix_rank_of_linearIndependent (colorMatrix (GT (m + 1)) true) u hmem hli /-- Exact rank lower bound on the `false`-color matrix of `GT n`: `n ≤ rank (colorMatrix (GT n) false)`. -/ theorem gt_false_rank_ge (n : ℕ) : n ≤ (colorMatrix (GT n) false).rank := by let u : Fin n → (Fin n → ℚ) := fun j i => colorMatrix (GT n) false i j have hmem : ∀ j : Fin n, u j ∈ LinearMap.range (colorMatrix (GT n) false).mulVecLin := by intro j refine ⟨Pi.single j 1, ?_⟩ funext i simp [Matrix.mulVec, dotProduct, Pi.single_apply, u] have hli : LinearIndependent ℚ u := by rw [linearIndependent_iff'] intro s g hsum -- Descending induction on `j.val` from `n - 1` down to `0`: -- At row `i = n - 1 - j`, `i + k ≥ n - 1` iff `k ≥ j`! suffices ∀ d : ℕ, ∀ j : Fin n, n - 1 - j.val ≤ d → j ∈ s → g j = 0 by intro j hj; exact this (n - 1) j (by omega) hj intro d induction d with | zero => intro j hle hj have hjv : j.val = n - 1 := by omega let row : Fin n := ⟨0, by omega⟩ have h0 := congrFun hsum row simp only [Finset.sum_apply, Pi.smul_apply, smul_eq_mul, Pi.zero_apply] at h0 have hterm : ∀ k ∈ s, g k * u k row = if k = j then g j else 0 := by intro k _ by_cases hkj : k = j · subst hkj have hnot : ¬ (0 + k.val < n - 1) := by omega simp only [u, colorMatrix, GT, row, ↓reduceIte, decide_eq_false hnot, mul_one] · have hklt : 0 + k.val < n - 1 := by have hne : k.val ≠ j.val := fun h => hkj (Fin.ext h) omega simp only [u, colorMatrix, GT, row, hkj, ↓reduceIte, decide_eq_true hklt, Bool.true_eq_false, mul_zero] rw [Finset.sum_congr rfl hterm, Finset.sum_ite_eq' s j] at h0 simpa [hj] using h0 | succ d' ih => intro j hle hj by_cases hsmall : n - 1 - j.val ≤ d' · exact ih j hsmall hj · have hjv : n - 1 - j.val = d' + 1 := by omega let row : Fin n := ⟨n - 1 - j.val, by omega⟩ have h0 := congrFun hsum row simp only [Finset.sum_apply, Pi.smul_apply, smul_eq_mul, Pi.zero_apply] at h0 have hterm : ∀ k ∈ s, g k * u k row = if k = j then g j else 0 := by intro k hk by_cases hkj : k = j · subst hkj have hnot : ¬ ((n - 1 - k.val) + k.val < n - 1) := by omega simp only [u, colorMatrix, GT, row, ↓reduceIte, decide_eq_false hnot, mul_one] · by_cases hkgt : n - 1 - k.val ≤ d' · simp [hkj, ih k hkgt hk] · have hklt : (n - 1 - j.val) + k.val < n - 1 := by have hne : k.val ≠ j.val := fun h => hkj (Fin.ext h) omega simp only [u, colorMatrix, GT, row, hkj, ↓reduceIte, decide_eq_true hklt, Bool.true_eq_false, mul_zero] rw [Finset.sum_congr rfl hterm, Finset.sum_ite_eq' s j] at h0 simpa [hj] using h0 simpa using card_le_matrix_rank_of_linearIndependent (colorMatrix (GT n) false) u hmem hli /-- Color-rank sum of `GT n` is at least `2 * n - 1`. -/ theorem gt_color_rank_sum_ge (n : ℕ) (hn : 1 ≤ n) : 2 * n - 1 ≤ ∑ b : Bool, (colorMatrix (GT n) b).rank := by have hsum : ∑ b : Bool, (colorMatrix (GT n) b).rank = (colorMatrix (GT n) false).rank + (colorMatrix (GT n) true).rank := by simp [add_comm] rw [hsum] have h1 := gt_false_rank_ge n have h2 := gt_true_rank_ge n omega /-- **HEADLINE THEOREM 4 (Exact Direct-Sum Leaf Count & Amortized Complexity of `GT n`)**: For every `n ≥ 2` and every `ℓ ≥ 1`: 1. Every protocol `P` computing `directSum (GT n) ℓ` has `(2 * n - 1) ^ ℓ ≤ P.leaves ≤ 2 ^ P.depth`; 2. `seqDirectSum (gtProto n) ℓ` attains the exact leaf count `(2 * n - 1) ^ ℓ`; 3. `parallelSim (gtProto n) ℓ` achieves amortized cost `log₂(2n - 1) ≤ D / ℓ ≤ log₂(2n - 1) + ((2n - 2)/ℓ) · log₂(4(ℓ + 1))`. -/ theorem gt_exact_direct_sum_and_amortized (n ℓ : ℕ) (hn : 2 ≤ n) (hℓ : 0 < ℓ) : (∀ P : Protocol (Fin ℓ → Fin n) (Fin ℓ → Fin n) (Fin ℓ → Bool), P.Computes (directSum (GT n) ℓ) → (2 * n - 1) ^ ℓ ≤ P.leaves ∧ (2 * n - 1) ^ ℓ ≤ 2 ^ P.depth) ∧ (∃ P : Protocol (Fin ℓ → Fin n) (Fin ℓ → Fin n) (Fin ℓ → Bool), P.Computes (directSum (GT n) ℓ) ∧ P.leaves = (2 * n - 1) ^ ℓ) ∧ (∃ Q : Protocol (Fin ℓ → Fin n) (Fin ℓ → Fin n) (Fin ℓ → Bool), Q.Computes (directSum (GT n) ℓ) ∧ Real.logb 2 ((2 * n - 1 : ℕ) : ℝ) ≤ (Q.depth : ℝ) / (ℓ : ℝ) ∧ (Q.depth : ℝ) / (ℓ : ℝ) ≤ Real.logb 2 ((2 * n - 1 : ℕ) : ℝ) + ((2 * n - 2 : ℕ) : ℝ) * Real.logb 2 (4 * ((ℓ : ℝ) + 1)) / (ℓ : ℝ)) := by have hn1 : 1 ≤ n := by omega have hrk := gt_color_rank_sum_ge n hn1 have hlb : ∀ P : Protocol (Fin ℓ → Fin n) (Fin ℓ → Fin n) (Fin ℓ → Bool), P.Computes (directSum (GT n) ℓ) → (2 * n - 1) ^ ℓ ≤ P.leaves ∧ (2 * n - 1) ^ ℓ ≤ 2 ^ P.depth := by intro P hP have ⟨h1, h2⟩ := direct_sum_color_rank_sum_lb (GT n) ℓ P hP have hpow := Nat.pow_le_pow_left hrk ℓ exact ⟨le_trans hpow h1, le_trans hpow h2⟩ refine ⟨hlb, ?_, ?_⟩ · refine ⟨seqDirectSum (gtProto n) ℓ, ?_, ?_⟩ · intro x y; rw [seqDirectSum_eval]; funext i; exact gtProto_computes n hn1 (x i) (y i) · rw [seqDirectSum_leaves, gtProto_leaves n hn1] · rcases amortized_direct_sum_log_upper (gtProto n) (GT n) (gtProto_computes n hn1) ℓ hℓ with ⟨Q, hQ, hQub⟩ have hQlb_nat := (hlb Q hQ).2 have hQlb_real : ((2 * n - 1 : ℕ) : ℝ) ^ ℓ ≤ (2 : ℝ) ^ Q.depth := by exact_mod_cast hQlb_nat have hpos : (0 : ℝ) < ((2 * n - 1 : ℕ) : ℝ) := by exact_mod_cast (by omega : 0 < 2 * n - 1) have hlog := Real.logb_le_logb_of_le (by norm_num : (1 : ℝ) < 2) (by positivity) hQlb_real rw [Real.logb_pow, Real.logb_pow, Real.logb_self_eq_one (by norm_num : (1 : ℝ) < 2), mul_one] at hlog have hℓR : (0 : ℝ) < (ℓ : ℝ) := by exact_mod_cast hℓ have hlbR : Real.logb 2 ((2 * n - 1 : ℕ) : ℝ) ≤ (Q.depth : ℝ) / (ℓ : ℝ) := by rw [le_div_iff₀ hℓR]; linarith have hleaves : (gtProto n).leaves = 2 * n - 1 := gtProto_leaves n hn1 have hsub : (gtProto n).leaves - 1 = 2 * n - 2 := by omega rw [hleaves] at hQub have hQub' : (Q.depth : ℝ) / (ℓ : ℝ) ≤ Real.logb 2 ((2 * n - 1 : ℕ) : ℝ) + ((2 * n - 2 : ℕ) : ℝ) * Real.logb 2 (4 * ((ℓ : ℝ) + 1)) / (ℓ : ℝ) := by have hsub2 : 2 * n - 1 - 1 = 2 * n - 2 := by omega rwa [hsub2] at hQub exact ⟨Q, hQ, hlbR, hQub'⟩ /-- Explicit depth-`(m + 1)` protocol for `GT (2 ^ (m - 1) + 1)` (`m ≥ 2`). -/ def gtPow2SingleProto (m : ℕ) : Protocol (Fin (2 ^ (m - 1) + 1)) (Fin (2 ^ (m - 1) + 1)) Bool := let M := 2 ^ (m - 1) .alice (fun i => decide (i.val = M)) (dispatchAlice M (Nat.pow_pos (by omega)) (fun i => if h : i.val < M then ⟨i.val, h⟩ else ⟨0, Nat.pow_pos (by omega)⟩) (fun r => .bob (fun j => decide (r.val + j.val < M)) (.leaf false) (.leaf true))) (.leaf false) /-- Explicit 2-round depth-`(2 * m + 1)` protocol for `directSum (GT (2 ^ (m - 1) + 1)) 2` (`m ≥ 2`), strictly beating `2 * (m + 1) = 2 * m + 2` already at `ℓ = 2` copies! -/ def gtPow2TwoCopyProto (m : ℕ) : Protocol (Fin 2 → Fin (2 ^ (m - 1) + 1)) (Fin 2 → Fin (2 ^ (m - 1) + 1)) (Fin 2 → Bool) := let M := 2 ^ (m - 1) have hMpos : 0 < M := Nat.pow_pos (by omega) have hM2pos : 0 < M * M := Nat.mul_pos hMpos hMpos let mkOut : Bool → Bool → (Fin 2 → Bool) := fun b0 b1 i => if i = 0 then b0 else b1 -- Branch 0: both coordinates active (`r0 < M ∧ r1 < M`) -> Alice sends `(r0, r1)` in `2m - 2` bits, Bob sends 2 bits let bothActive := dispatchAlice (M * M) hM2pos (fun x => if h : (x 0).val < M ∧ (x 1).val < M then ⟨(x 0).val * M + (x 1).val, by nlinarith⟩ else ⟨0, hM2pos⟩) (fun idx => let r0 := idx.val / M let r1 := idx.val % M .bob (fun y => decide (r0 + (y 0).val < M)) (.bob (fun y => decide (r1 + (y 1).val < M)) (.leaf (mkOut false false)) (.leaf (mkOut false true))) (.bob (fun y => decide (r1 + (y 1).val < M)) (.leaf (mkOut true false)) (.leaf (mkOut true true)))) -- Branch 1: at least one coordinate is dead (`= M`) let firstActive := dispatchAlice M hMpos (fun x => if h : (x 0).val < M then ⟨(x 0).val, h⟩ else ⟨0, hMpos⟩) (fun r0 => .bob (fun y => decide (r0.val + (y 0).val < M)) (.leaf (mkOut false false)) (.leaf (mkOut true false))) let secondActive := dispatchAlice M hMpos (fun x => if h : (x 1).val < M then ⟨(x 1).val, h⟩ else ⟨0, hMpos⟩) (fun r1 => .bob (fun y => decide (r1.val + (y 1).val < M)) (.leaf (mkOut false false)) (.leaf (mkOut false true))) .alice (fun x => decide ((x 0).val = M ∨ (x 1).val = M)) bothActive (.alice (fun x => decide ((x 0).val = M ∧ (x 1).val = M)) (.alice (fun x => decide ((x 0).val = M)) firstActive secondActive) (.leaf (mkOut false false))) /-- **HEADLINE THEOREM 5 (Infinite Family of Total Boolean Functions Breaking Direct Sum at `ℓ = 2` Copies)**: For every `m ≥ 2`, let `n = 2 ^ (m - 1) + 1`. Then: 1. `D(GT n) = m + 1` (exact); 2. `D(GT n ^ ⊗2) = 2 * m + 1 < 2 * (m + 1) = 2 * D(GT n)` (exact!). In particular, at `m = 2` (`GT 3`, `3 × 3` total Boolean matrix), `D(GT 3) = 3` and `D(GT 3 ^ ⊗2) = 5 < 6`. -/ theorem gt_pow2_plus_one_infinite_two_copy_savings (m : ℕ) (hm : 2 ≤ m) : HasDepth (GT (2 ^ (m - 1) + 1)) (m + 1) ∧ ¬ HasDepth (GT (2 ^ (m - 1) + 1)) m ∧ HasDepth (directSum (GT (2 ^ (m - 1) + 1)) 2) (2 * m + 1) ∧ ¬ HasDepth (directSum (GT (2 ^ (m - 1) + 1)) 2) (2 * m) := by have hMpos : 0 < 2 ^ (m - 1) := Nat.pow_pos (by omega) have h2M : 2 * (2 ^ (m - 1) + 1) - 1 = 2 ^ m + 1 := by have hpow : 2 * 2 ^ (m - 1) = 2 ^ m := by conv_rhs => rw [← Nat.sub_add_cancel (by omega : 1 ≤ m), Nat.pow_succ, mul_comm] omega refine ⟨?_, ?_, ?_, ?_⟩ · -- Single-copy upper bound: `m + 1` refine ⟨gtPow2SingleProto m, ?_, ?_⟩ · intro i j simp only [gtPow2SingleProto, Protocol.eval, GT, Nat.add_sub_cancel] by_cases hi : i.val = 2 ^ (m - 1) · simp [hi] · have hlt : i.val < 2 ^ (m - 1) := by omega simp only [decide_eq_true_eq, hi, ↓reduceIte] rw [dispatchAlice_eval] simp only [hlt, ↓reduceDIte, Protocol.eval] by_cases hlt2 : i.val + j.val < 2 ^ (m - 1) <;> simp [hlt2] · simp only [gtPow2SingleProto, Protocol.depth] have hd := dispatchAlice_depth_le (2 ^ (m - 1)) hMpos (fun i : Fin (2 ^ (m - 1) + 1) => if h : i.val < 2 ^ (m - 1) then ⟨i.val, h⟩ else ⟨0, hMpos⟩) (fun r : Fin (2 ^ (m - 1)) => .bob (fun j : Fin (2 ^ (m - 1) + 1) => decide (r.val + j.val < 2 ^ (m - 1))) (.leaf false) (.leaf true)) 1 (fun _ => by simp [Protocol.depth]) have hclog : Nat.clog 2 (2 ^ (m - 1)) = m - 1 := Nat.clog_pow 2 (m - 1) (by omega) rw [hclog] at hd omega · -- Single-copy lower bound: `¬ HasDepth (GT (2 ^ (m - 1) + 1)) m` rintro ⟨P, hP, hd⟩ have hlb := (color_rank_sum_leaves_lb P (GT (2 ^ (m - 1) + 1)) hP).2 have hrk := gt_color_rank_sum_ge (2 ^ (m - 1) + 1) (by omega) have hpow : 2 ^ P.depth ≤ 2 ^ m := Nat.pow_le_pow_right (by omega) hd omega · -- Two-copy upper bound: `2 * m + 1` refine ⟨gtPow2TwoCopyProto m, ?_, ?_⟩ · intro x y simp only [gtPow2TwoCopyProto, Protocol.eval] by_cases hor : (x 0).val = 2 ^ (m - 1) ∨ (x 1).val = 2 ^ (m - 1) · simp only [decide_eq_true_eq, hor, ↓reduceIte] by_cases hand : (x 0).val = 2 ^ (m - 1) ∧ (x 1).val = 2 ^ (m - 1) · simp only [hand, ↓reduceIte] funext i; fin_cases i · have hnot : ¬ ((x 0).val + (y 0).val < 2 ^ (m - 1)) := by omega simp [directSum, GT, hnot] · have hnot : ¬ ((x 1).val + (y 1).val < 2 ^ (m - 1)) := by omega simp [directSum, GT, hnot] · simp only [hand, ↓reduceIte] by_cases h0 : (x 0).val = 2 ^ (m - 1) · have h1lt : (x 1).val < 2 ^ (m - 1) := by omega simp only [h0, ↓reduceIte] rw [dispatchAlice_eval] simp only [h1lt, ↓reduceDIte, Protocol.eval] have hnot0 : ¬ ((x 0).val + (y 0).val < 2 ^ (m - 1)) := by omega by_cases hb1 : (x 1).val + (y 1).val < 2 ^ (m - 1) · simp only [decide_eq_true hb1, ↓reduceIte] funext i; fin_cases i <;> simp [directSum, GT, hnot0, hb1] · simp only [decide_eq_false hb1, Bool.false_eq_true, ↓reduceIte] funext i; fin_cases i <;> simp [directSum, GT, hnot0, hb1] · have h0lt : (x 0).val < 2 ^ (m - 1) := by omega have h1 : (x 1).val = 2 ^ (m - 1) := by omega simp only [h0, ↓reduceIte] rw [dispatchAlice_eval] simp only [h0lt, ↓reduceDIte, Protocol.eval] have hnot1 : ¬ ((x 1).val + (y 1).val < 2 ^ (m - 1)) := by omega by_cases hb0 : (x 0).val + (y 0).val < 2 ^ (m - 1) · simp only [decide_eq_true hb0, ↓reduceIte] funext i; fin_cases i <;> simp [directSum, GT, hb0, hnot1] · simp only [decide_eq_false hb0, Bool.false_eq_true, ↓reduceIte] funext i; fin_cases i <;> simp [directSum, GT, hb0, hnot1] · have hboth : (x 0).val < 2 ^ (m - 1) ∧ (x 1).val < 2 ^ (m - 1) := by omega simp only [decide_eq_true_eq, hor, ↓reduceIte] rw [dispatchAlice_eval] rw [dif_pos hboth] have hdiv : ((x 0).val * 2 ^ (m - 1) + (x 1).val) / 2 ^ (m - 1) = (x 0).val := by rw [mul_comm (x 0).val, Nat.mul_add_div hMpos, Nat.div_eq_of_lt hboth.2, add_zero] have hmod : ((x 0).val * 2 ^ (m - 1) + (x 1).val) % 2 ^ (m - 1) = (x 1).val := by rw [mul_comm (x 0).val, Nat.mul_add_mod, Nat.mod_eq_of_lt hboth.2] simp only [Protocol.eval] rw [hdiv, hmod] by_cases hb0 : (x 0).val + (y 0).val < 2 ^ (m - 1) <;> by_cases hb1 : (x 1).val + (y 1).val < 2 ^ (m - 1) <;> (simp only [decide_eq_true_eq, hb0, hb1, ↓reduceIte]; funext i; fin_cases i <;> simp [directSum, GT, hb0, hb1]) · unfold gtPow2TwoCopyProto dsimp only simp only [Protocol.depth] have hM2 : 2 ^ (m - 1) * 2 ^ (m - 1) = 2 ^ (2 * m - 2) := by rw [← Nat.pow_add]; congr 1; omega have hclog2 : Nat.clog 2 (2 ^ (m - 1) * 2 ^ (m - 1)) = 2 * m - 2 := by rw [hM2]; exact Nat.clog_pow 2 (2 * m - 2) (by omega) have hclog1 : Nat.clog 2 (2 ^ (m - 1)) = m - 1 := Nat.clog_pow 2 (m - 1) (by omega) have hd_both := dispatchAlice_depth_le (2 ^ (m - 1) * 2 ^ (m - 1)) (Nat.mul_pos hMpos hMpos) (fun x : Fin 2 → Fin (2 ^ (m - 1) + 1) => if h : (x 0).val < 2 ^ (m - 1) ∧ (x 1).val < 2 ^ (m - 1) then ⟨(x 0).val * 2 ^ (m - 1) + (x 1).val, by nlinarith⟩ else ⟨0, Nat.mul_pos hMpos hMpos⟩) (fun idx : Fin (2 ^ (m - 1) * 2 ^ (m - 1)) => .bob (fun y : Fin 2 → Fin (2 ^ (m - 1) + 1) => decide (idx.val / 2 ^ (m - 1) + (y 0).val < 2 ^ (m - 1))) (.bob (fun y => decide (idx.val % 2 ^ (m - 1) + (y 1).val < 2 ^ (m - 1))) (.leaf (fun i : Fin 2 => if i = 0 then false else false)) (.leaf (fun i : Fin 2 => if i = 0 then false else true))) (.bob (fun y => decide (idx.val % 2 ^ (m - 1) + (y 1).val < 2 ^ (m - 1))) (.leaf (fun i : Fin 2 => if i = 0 then true else false)) (.leaf (fun i : Fin 2 => if i = 0 then true else true)))) 2 (fun _ => by simp [Protocol.depth]) have hd_first := dispatchAlice_depth_le (2 ^ (m - 1)) hMpos (fun x : Fin 2 → Fin (2 ^ (m - 1) + 1) => if h : (x 0).val < 2 ^ (m - 1) then ⟨(x 0).val, h⟩ else ⟨0, hMpos⟩) (fun r0 : Fin (2 ^ (m - 1)) => .bob (fun y : Fin 2 → Fin (2 ^ (m - 1) + 1) => decide (r0.val + (y 0).val < 2 ^ (m - 1))) (.leaf (fun i : Fin 2 => if i = 0 then false else false)) (.leaf (fun i : Fin 2 => if i = 0 then true else false))) 1 (fun _ => by simp [Protocol.depth]) have hd_second := dispatchAlice_depth_le (2 ^ (m - 1)) hMpos (fun x : Fin 2 → Fin (2 ^ (m - 1) + 1) => if h : (x 1).val < 2 ^ (m - 1) then ⟨(x 1).val, h⟩ else ⟨0, hMpos⟩) (fun r1 : Fin (2 ^ (m - 1)) => .bob (fun y : Fin 2 → Fin (2 ^ (m - 1) + 1) => decide (r1.val + (y 1).val < 2 ^ (m - 1))) (.leaf (fun i : Fin 2 => if i = 0 then false else false)) (.leaf (fun i : Fin 2 => if i = 0 then false else true))) 1 (fun _ => by simp [Protocol.depth]) rw [hclog2] at hd_both rw [hclog1] at hd_first hd_second omega · -- Two-copy lower bound: `¬ HasDepth (directSum (GT (2 ^ (m - 1) + 1)) 2) (2 * m)` rintro ⟨P, hP, hd⟩ have hlb := ((gt_exact_direct_sum_and_amortized (2 ^ (m - 1) + 1) 2 (by omega) (by omega)).1 P hP).2 rw [h2M] at hlb have hpow : 2 ^ P.depth ≤ 2 ^ (2 * m) := Nat.pow_le_pow_right (by omega) hd have hgt : 2 ^ (2 * m) < (2 ^ m + 1) ^ 2 := by have hsq : (2 ^ m) ^ 2 = 2 ^ (2 * m) := by rw [← Nat.pow_mul, mul_comm] nlinarith [Nat.pow_pos (a := 2) (n := m) (by omega)] omega /-- Strict amortized compression ratio dominance of `GT 3` (`log₂ 5 / 3 ≈ 0.7740`) over the classical Feder–Kushilevitz–Naor–Nisan `AND = GT 2` benchmark (`log₂ 3 / 2 ≈ 0.7925`). -/ theorem gt3_beats_fknn_and_compression_ratio : Real.logb 2 5 / 3 < Real.logb 2 3 / 2 := by have hlog2 : 0 < Real.log 2 := Real.log_pos (by norm_num) rw [Real.logb, Real.logb] have hpow : (5 : ℝ) ^ (2 : ℕ) < (3 : ℝ) ^ (3 : ℕ) := by norm_num have hlog : Real.log ((5 : ℝ) ^ (2 : ℕ)) < Real.log ((3 : ℝ) ^ (3 : ℕ)) := Real.log_lt_log (by positivity) hpow rw [Real.log_pow, Real.log_pow] at hlog simp only [Nat.cast_ofNat] at hlog have h1 : Real.log 5 / Real.log 2 / 3 = (2 * Real.log 5) / (6 * Real.log 2) := by field_simp [ne_of_gt hlog2]; ring have h2 : Real.log 3 / Real.log 2 / 2 = (3 * Real.log 3) / (6 * Real.log 2) := by field_simp [ne_of_gt hlog2]; ring rw [h1, h2] exact div_lt_div_of_pos_right hlog (by positivity) /-! ### Exact Deterministic Complexity of Indexing `IND k` -/ /-- Indexing function `IND k : Fin k → (Fin k → Bool) → Bool`, `IND k i y = y i`. -/ def IND (k : ℕ) (i : Fin k) (y : Fin k → Bool) : Bool := y i /-- Elementary inequality `a * 2 ^ (k - a) ≤ 2 ^ (k - 1)` for all `1 ≤ a ≤ k`. -/ theorem mul_two_pow_sub_le (k a : ℕ) (ha1 : 1 ≤ a) (hak : a ≤ k) : a * 2 ^ (k - a) ≤ 2 ^ (k - 1) := by induction a with | zero => omega | succ m ih => cases m with | zero => simp | succ r => have hih := ih (by omega) (by omega) have hstep : (r + 2) * 2 ^ (k - (r + 2)) ≤ (r + 1) * 2 ^ (k - (r + 1)) := by have hpow : 2 ^ (k - (r + 1)) = 2 * 2 ^ (k - (r + 2)) := by have hsub : k - (r + 1) = (k - (r + 2)) + 1 := by omega rw [hsub, Nat.pow_succ, mul_comm] rw [hpow] have : r + 2 ≤ (r + 1) * 2 := by omega calc (r + 2) * 2 ^ (k - (r + 2)) ≤ ((r + 1) * 2) * 2 ^ (k - (r + 2)) := Nat.mul_le_mul_right _ this _ = (r + 1) * (2 * 2 ^ (k - (r + 2))) := by ring exact le_trans hstep hih /-- Every `IND k`-monochromatic rectangle `A × B` has area `A.card * B.card ≤ 2 ^ (k - 1)`. -/ theorem indexing_mono_rect_area_le (k : ℕ) (_hk : 1 ≤ k) (A : Finset (Fin k)) (B : Finset (Fin k → Bool)) (b : Bool) (hmono : ∀ i ∈ A, ∀ y ∈ B, IND k i y = b) : A.card * B.card ≤ 2 ^ (k - 1) := by by_cases hA : A.card = 0 · simp [hA] · have hA1 : 1 ≤ A.card := by omega have hAk : A.card ≤ k := by simpa using Finset.card_le_univ A -- Inject `B` into `({i : Fin k // i ∉ A} → Bool)` by restricting `y` to `Aᶜ` have hinj : Set.InjOn (fun (y : Fin k → Bool) (i : { i : Fin k // i ∉ A }) => y i.val) (B : Set (Fin k → Bool)) := by intro y₁ hy₁ y₂ hy₂ heq funext i by_cases hi : i ∈ A · rw [show y₁ i = IND k i y₁ from rfl, show y₂ i = IND k i y₂ from rfl, hmono i hi y₁ hy₁, hmono i hi y₂ hy₂] · exact congrFun heq ⟨i, hi⟩ have hBcard : B.card ≤ 2 ^ (k - A.card) := by have hle := Finset.card_le_card_of_injOn (fun (y : Fin k → Bool) (i : { i : Fin k // i ∉ A }) => y i.val) (fun _ _ => Finset.mem_univ _) hinj have hcard_dom : Fintype.card { i : Fin k // i ∉ A } = k - A.card := by have e : { i : Fin k // i ∉ A } ≃ { i : Fin k // i ∈ Aᶜ } := Equiv.subtypeEquivRight (fun i => by simp) rw [Fintype.card_congr e, Fintype.card_coe, Finset.card_compl, Fintype.card_fin] rw [Finset.card_univ, Fintype.card_fun, Fintype.card_bool, hcard_dom] at hle exact hle calc A.card * B.card ≤ A.card * 2 ^ (k - A.card) := Nat.mul_le_mul_left _ hBcard _ ≤ 2 ^ (k - 1) := mul_two_pow_sub_le k A.card hA1 hAk /-- Total-area bound for `IND k`: every protocol `P` computing `IND k` on `A ×ˢ B` satisfies `A.card * B.card ≤ P.leaves * 2 ^ (k - 1)`. -/ theorem indexing_rect_leaves_lb (k : ℕ) (hk : 1 ≤ k) (P : Protocol (Fin k) (Fin k → Bool) Bool) : ∀ (A : Finset (Fin k)) (B : Finset (Fin k → Bool)), (∀ i ∈ A, ∀ y ∈ B, P.eval i y = IND k i y) → A.card * B.card ≤ P.leaves * 2 ^ (k - 1) := by induction P with | leaf b => intro A B hAB simp only [Protocol.leaves, one_mul] exact indexing_mono_rect_area_le k hk A B b (fun i hi y hy => (hAB i hi y hy).symm) | alice g L R ihl ihr => intro A B hAB let A0 := A.filter (fun i => g i = false) let A1 := A.filter (fun i => g i = true) have hcard : A.card = A0.card + A1.card := by have hdisj : Disjoint A0 A1 := by rw [Finset.disjoint_filter]; intro i _ h0 h1; rw [h0] at h1; cases h1 have hunion : A0 ∪ A1 = A := by ext i; simp only [Finset.mem_union, A0, A1, Finset.mem_filter] cases g i <;> simp rw [← hunion, Finset.card_union_of_disjoint hdisj] have hL := ihl A0 B (fun i hi y hy => by have ⟨hiA, hgi⟩ := Finset.mem_filter.mp hi have h := hAB i hiA y hy simpa [Protocol.eval, hgi] using h) have hR := ihr A1 B (fun i hi y hy => by have ⟨hiA, hgi⟩ := Finset.mem_filter.mp hi have h := hAB i hiA y hy simpa [Protocol.eval, hgi] using h) simp only [Protocol.leaves] rw [hcard, Nat.add_mul, Nat.add_mul] exact Nat.add_le_add hL hR | bob g L R ihl ihr => intro A B hAB let B0 := B.filter (fun y => g y = false) let B1 := B.filter (fun y => g y = true) have hcard : B.card = B0.card + B1.card := by have hdisj : Disjoint B0 B1 := by rw [Finset.disjoint_filter]; intro y _ h0 h1; rw [h0] at h1; cases h1 have hunion : B0 ∪ B1 = B := by ext y; simp only [Finset.mem_union, B0, B1, Finset.mem_filter] cases g y <;> simp rw [← hunion, Finset.card_union_of_disjoint hdisj] have hL := ihl A B0 (fun i hi y hy => by have ⟨hyB, hgy⟩ := Finset.mem_filter.mp hy have h := hAB i hi y hyB simpa [Protocol.eval, hgy] using h) have hR := ihr A B1 (fun i hi y hy => by have ⟨hyB, hgy⟩ := Finset.mem_filter.mp hy have h := hAB i hi y hyB simpa [Protocol.eval, hgy] using h) simp only [Protocol.leaves] rw [hcard, Nat.mul_add, Nat.add_mul] exact Nat.add_le_add hL hR /-- **HEADLINE THEOREM 6 (Exact Deterministic Complexity of Indexing `IND k`)**: For every `k ≥ 1`: 1. Every protocol `P` computing `IND k` satisfies `2 * k ≤ P.leaves` and `Nat.clog 2 k + 1 ≤ P.depth`; 2. The Alice-dispatch protocol achieves exact leaves `2 * k` and exact depth `Nat.clog 2 k + 1`. -/ theorem indexing_exact_complexity (k : ℕ) (hk : 1 ≤ k) : (∀ P : Protocol (Fin k) (Fin k → Bool) Bool, P.Computes (IND k) → 2 * k ≤ P.leaves ∧ Nat.clog 2 k + 1 ≤ P.depth) ∧ (∃ Q : Protocol (Fin k) (Fin k → Bool) Bool, Q.Computes (IND k) ∧ Q.leaves = 2 * k ∧ Q.depth ≤ Nat.clog 2 k + 1) := by constructor · intro P hP have harea := indexing_rect_leaves_lb k hk P Finset.univ Finset.univ (fun i _ y _ => hP i y) have hcard : (Finset.univ : Finset (Fin k)).card * (Finset.univ : Finset (Fin k → Bool)).card = (2 * k) * 2 ^ (k - 1) := by rw [Finset.card_univ, Finset.card_univ, Fintype.card_fin, Fintype.card_fun, Fintype.card_bool, Fintype.card_fin] have hpow : 2 ^ k = 2 * 2 ^ (k - 1) := by conv_lhs => rw [← Nat.sub_add_cancel hk, Nat.pow_succ, mul_comm] rw [hpow]; ring rw [hcard] at harea have hleaves : 2 * k ≤ P.leaves := Nat.le_of_mul_le_mul_right harea (Nat.pow_pos (by omega)) have hdepth : Nat.clog 2 k + 1 ≤ P.depth := by have h2 := le_trans hleaves P.leaves_le_two_pow_depth have hpos : 0 < P.depth := by by_contra hd0 have hd : P.depth = 0 := by omega rw [hd] at h2; omega have hhalf : k ≤ 2 ^ (P.depth - 1) := by have heq : 2 ^ P.depth = 2 * 2 ^ (P.depth - 1) := by conv_lhs => rw [← Nat.sub_add_cancel hpos, Nat.pow_succ, mul_comm] rw [heq] at h2; omega have hclog := (Nat.clog_le_iff_le_pow (by omega : 1 < 2)).mpr hhalf omega exact ⟨hleaves, hdepth⟩ · -- Matching protocol: Alice dispatches `i : Fin k`, Bob sends `y i` let Q : Protocol (Fin k) (Fin k → Bool) Bool := dispatchAlice k (by omega) id (fun i => .bob (fun y : Fin k → Bool => y i) (.leaf false) (.leaf true)) have hQcomp : Q.Computes (IND k) := by intro i y simp only [Q] rw [dispatchAlice_eval] simp only [id_eq, Protocol.eval, IND] by_cases hy : y i = true <;> simp [hy] have hQdepth : Q.depth ≤ Nat.clog 2 k + 1 := dispatchAlice_depth_le k (by omega) id _ 1 (fun _ => by simp [Protocol.depth]) have hdisp_leaves : ∀ (n : ℕ) (hn : 0 < n) (idx : Fin k → Fin n) (br : Fin n → Protocol (Fin k) (Fin k → Bool) Bool), (∀ i, (br i).leaves = 2) → (dispatchAlice n hn idx br).leaves = 2 * n := by intro n induction n using Nat.strong_induction_on with | h n ih => intro hn idx br hbr match n with | 0 => exact absurd hn (Nat.lt_irrefl 0) | 1 => simpa [dispatchAlice] using hbr ⟨0, Nat.zero_lt_one⟩ | r + 2 => simp only [dispatchAlice, Protocol.leaves] have hL := ih ((r + 2) / 2) (by omega) (by omega) (fun x => if h : (idx x).val < (r + 2) / 2 then ⟨(idx x).val, h⟩ else ⟨0, by omega⟩) (fun i => br ⟨i.val, lt_trans i.isLt (by omega)⟩) (fun i => hbr _) have hR := ih (r + 2 - (r + 2) / 2) (by omega) (by omega) (fun x => if h : (r + 2) / 2 ≤ (idx x).val then ⟨(idx x).val - (r + 2) / 2, by omega⟩ else ⟨0, by omega⟩) (fun i => br ⟨(r + 2) / 2 + i.val, by omega⟩) (fun i => hbr _) omega have hQleaves : Q.leaves = 2 * k := hdisp_leaves k (by omega) id _ (fun _ => by simp [Protocol.leaves]) exact ⟨Q, hQcomp, hQleaves, hQdepth⟩ /-! ## Section 6: Product-Duplication Lower Bounds & Exact Sharpness of Protocol Balancing -/ /-- Alice-join `F ⊕_A G`: Alice receives an input of `F` or `G`, Bob receives one input of each. -/ def aliceJoin {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : Type*} (F : X₁ → Y₁ → Z₁) (G : X₂ → Y₂ → Z₂) : (X₁ ⊕ X₂) → (Y₁ × Y₂) → (Z₁ ⊕ Z₂) | .inl x₁, (y₁, _) => .inl (F x₁ y₁) | .inr x₂, (_, y₂) => .inr (G x₂ y₂) /-- Bob-join `F ⊕_B G`: Bob receives an input of `F` or `G`, Alice receives one input of each. -/ def bobJoin {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : Type*} (F : X₁ → Y₁ → Z₁) (G : X₂ → Y₂ → Z₂) : (X₁ × X₂) → (Y₁ ⊕ Y₂) → (Z₁ ⊕ Z₂) | (x₁, _), .inl y₁ => .inl (F x₁ y₁) | (_, x₂), .inr y₂ => .inr (G x₂ y₂) /-- Number of distinct outputs attained by `f` on a combinatorial rectangle `A ×ˢ B`. -/ def imageCard {X Y Z : Type*} [DecidableEq Z] (f : X → Y → Z) (A : Finset X) (B : Finset Y) : ℕ := ((A ×ˢ B).image (fun p => f p.1 p.2)).card /-- Any protocol computing `f` on `A ×ˢ B` has at least `imageCard f A B` leaves. -/ theorem imageCard_le_leaves {X Y Z : Type*} [DecidableEq Z] (P : Protocol X Y Z) (f : X → Y → Z) (A : Finset X) (B : Finset Y) (hP : ∀ x ∈ A, ∀ y ∈ B, P.eval x y = f x y) : imageCard f A B ≤ P.leaves ∧ imageCard f A B ≤ 2 ^ P.depth := by have hsub : (A ×ˢ B).image (fun p => f p.1 p.2) ⊆ (P.leafTable.map Prod.snd).toFinset := by intro z hz rcases Finset.mem_image.mp hz with ⟨⟨x, y⟩, hxy, rfl⟩ rcases Finset.mem_product.mp hxy with ⟨hx, hy⟩ rw [List.mem_toFinset, List.mem_map] exact ⟨(P.trace x y, P.eval x y), P.trace_mem_leafTable x y, hP x hx y hy⟩ have hle : imageCard f A B ≤ P.leaves := by calc imageCard f A B ≤ (P.leafTable.map Prod.snd).toFinset.card := Finset.card_le_card hsub _ ≤ (P.leafTable.map Prod.snd).length := List.toFinset_card_le _ _ = P.leaves := by rw [List.length_map, P.leafTable_length] exact ⟨hle, le_trans hle P.leaves_le_two_pow_depth⟩ /-- Slice dichotomy for any Boolean coloring of a Cartesian product `X₁ × X₂`. -/ theorem slice_dichotomy {X₁ X₂ : Type*} (g : X₁ × X₂ → Bool) (b : Bool) : (∃ x₁ : X₁, ∀ x₂ : X₂, g (x₁, x₂) = b) ∨ (∀ x₁ : X₁, ∃ x₂ : X₂, g (x₁, x₂) = !b) := by by_cases h : ∃ x₁ : X₁, ∀ x₂ : X₂, g (x₁, x₂) = b · exact Or.inl h · right push Not at h intro x₁ rcases h x₁ with ⟨x₂, hx₂⟩ refine ⟨x₂, ?_⟩ cases hg : g (x₁, x₂) <;> cases b <;> simp_all /-- Image cardinality of `bobJoin F G` splits cleanly into left (`Z₁`) and right (`Z₂`) outputs. -/ theorem imageCard_bobJoin_eq {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : Type*} [Fintype Y₁] [Fintype Y₂] [DecidableEq X₁] [DecidableEq X₂] [DecidableEq Z₁] [DecidableEq Z₂] (F : X₁ → Y₁ → Z₁) (G : X₂ → Y₂ → Z₂) (R : Finset (X₁ × X₂)) : imageCard (bobJoin F G) R Finset.univ = ((R.image Prod.fst ×ˢ (Finset.univ : Finset Y₁)).image (fun p => F p.1 p.2)).card + ((R.image Prod.snd ×ˢ (Finset.univ : Finset Y₂)).image (fun p => G p.1 p.2)).card := by let S₁ : Finset (Z₁ ⊕ Z₂) := ((R.image Prod.fst ×ˢ (Finset.univ : Finset Y₁)).image (fun p => F p.1 p.2)).image Sum.inl let S₂ : Finset (Z₁ ⊕ Z₂) := ((R.image Prod.snd ×ˢ (Finset.univ : Finset Y₂)).image (fun p => G p.1 p.2)).image Sum.inr have hdisj : Disjoint S₁ S₂ := by rw [Finset.disjoint_left] intro z hz₁ hz₂ rcases Finset.mem_image.mp hz₁ with ⟨z₁, _, rfl⟩ rcases Finset.mem_image.mp hz₂ with ⟨z₂, _, h⟩ cases h have hunion : (R ×ˢ (Finset.univ : Finset (Y₁ ⊕ Y₂))).image (fun p => bobJoin F G p.1 p.2) = S₁ ∪ S₂ := by ext z simp only [Finset.mem_image, Finset.mem_product, Finset.mem_univ, and_true, Finset.mem_union, S₁, S₂, Prod.exists] constructor · rintro ⟨x₁, x₂, y, hR, rfl⟩ cases y with | inl y₁ => left; refine ⟨F x₁ y₁, ⟨x₁, y₁, ⟨x₁, x₂, hR, rfl⟩, rfl⟩, rfl⟩ | inr y₂ => right; refine ⟨G x₂ y₂, ⟨x₂, y₂, ⟨x₁, x₂, hR, rfl⟩, rfl⟩, rfl⟩ · rintro (⟨z₁, ⟨x₁, y₁, ⟨a, b, hR, rfl⟩, rfl⟩, rfl⟩ | ⟨z₂, ⟨x₂, y₂, ⟨a, b, hR, rfl⟩, rfl⟩, rfl⟩) · exact ⟨a, b, Sum.inl y₁, hR, rfl⟩ · exact ⟨a, b, Sum.inr y₂, hR, rfl⟩ rw [imageCard, hunion, Finset.card_union_of_disjoint hdisj, Finset.card_image_of_injective _ Sum.inl_injective, Finset.card_image_of_injective _ Sum.inr_injective] /-- **THEOREM 7A (4-Case Product-Duplication Theorem for `bobJoin F G`)**: For any Alice split `g : X₁ × X₂ → Bool` partitioning `X₁ × X₂` into `R₀ = {g = false}` and `R₁ = {g = true}`, if `F` attains `m₁` outputs and `G` attains `m₂` outputs, then at least one half attains `m₁ + m₂` outputs, OR the sum of outputs across the two halves is at least `min (2 * m₁ + m₂) (m₁ + 2 * m₂)`. -/ theorem product_duplication_bobJoin {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : Type*} [Fintype X₁] [Fintype Y₁] [Fintype X₂] [Fintype Y₂] [DecidableEq X₁] [DecidableEq X₂] [Nonempty X₁] [Nonempty X₂] [DecidableEq Z₁] [DecidableEq Z₂] (F : X₁ → Y₁ → Z₁) (G : X₂ → Y₂ → Z₂) (g : X₁ × X₂ → Bool) : let R₀ := Finset.univ.filter (fun p : X₁ × X₂ => g p = false) let R₁ := Finset.univ.filter (fun p : X₁ × X₂ => g p = true) let m₁ := imageCard F Finset.univ Finset.univ let m₂ := imageCard G Finset.univ Finset.univ let c₀ := imageCard (bobJoin F G) R₀ Finset.univ let c₁ := imageCard (bobJoin F G) R₁ Finset.univ m₁ + m₂ ≤ c₀ ∨ m₁ + m₂ ≤ c₁ ∨ 2 * m₁ + m₂ ≤ c₀ + c₁ ∨ m₁ + 2 * m₂ ≤ c₀ + c₁ := by intro R₀ R₁ m₁ m₂ c₀ c₁ let L₀ := ((R₀.image Prod.fst ×ˢ (Finset.univ : Finset Y₁)).image (fun p => F p.1 p.2)).card let K₀ := ((R₀.image Prod.snd ×ˢ (Finset.univ : Finset Y₂)).image (fun p => G p.1 p.2)).card let L₁ := ((R₁.image Prod.fst ×ˢ (Finset.univ : Finset Y₁)).image (fun p => F p.1 p.2)).card let K₁ := ((R₁.image Prod.snd ×ˢ (Finset.univ : Finset Y₂)).image (fun p => G p.1 p.2)).card have hc₀ : c₀ = L₀ + K₀ := imageCard_bobJoin_eq F G R₀ have hc₁ : c₁ = L₁ + K₁ := imageCard_bobJoin_eq F G R₁ have hcov₁ : m₁ ≤ L₀ + L₁ := by obtain ⟨x₂⟩ := ‹Nonempty X₂› have hunion : (Finset.univ ×ˢ (Finset.univ : Finset Y₁)).image (fun p => F p.1 p.2) ⊆ ((R₀.image Prod.fst ×ˢ Finset.univ).image (fun p => F p.1 p.2)) ∪ ((R₁.image Prod.fst ×ˢ Finset.univ).image (fun p => F p.1 p.2)) := by intro z hz rcases Finset.mem_image.mp hz with ⟨⟨x₁, y₁⟩, _, rfl⟩ cases hg : g (x₁, x₂) · exact Finset.mem_union_left _ (Finset.mem_image.mpr ⟨(x₁, y₁), Finset.mem_product.mpr ⟨Finset.mem_image.mpr ⟨(x₁, x₂), Finset.mem_filter.mpr ⟨Finset.mem_univ _, hg⟩, rfl⟩, Finset.mem_univ _⟩, rfl⟩) · exact Finset.mem_union_right _ (Finset.mem_image.mpr ⟨(x₁, y₁), Finset.mem_product.mpr ⟨Finset.mem_image.mpr ⟨(x₁, x₂), Finset.mem_filter.mpr ⟨Finset.mem_univ _, hg⟩, rfl⟩, Finset.mem_univ _⟩, rfl⟩) exact le_trans (Finset.card_le_card hunion) (Finset.card_union_le _ _) have hcov₂ : m₂ ≤ K₀ + K₁ := by obtain ⟨x₁⟩ := ‹Nonempty X₁› have hunion : (Finset.univ ×ˢ (Finset.univ : Finset Y₂)).image (fun p => G p.1 p.2) ⊆ ((R₀.image Prod.snd ×ˢ Finset.univ).image (fun p => G p.1 p.2)) ∪ ((R₁.image Prod.snd ×ˢ Finset.univ).image (fun p => G p.1 p.2)) := by intro z hz rcases Finset.mem_image.mp hz with ⟨⟨x₂, y₂⟩, _, rfl⟩ cases hg : g (x₁, x₂) · exact Finset.mem_union_left _ (Finset.mem_image.mpr ⟨(x₂, y₂), Finset.mem_product.mpr ⟨Finset.mem_image.mpr ⟨(x₁, x₂), Finset.mem_filter.mpr ⟨Finset.mem_univ _, hg⟩, rfl⟩, Finset.mem_univ _⟩, rfl⟩) · exact Finset.mem_union_right _ (Finset.mem_image.mpr ⟨(x₂, y₂), Finset.mem_product.mpr ⟨Finset.mem_image.mpr ⟨(x₁, x₂), Finset.mem_filter.mpr ⟨Finset.mem_univ _, hg⟩, rfl⟩, Finset.mem_univ _⟩, rfl⟩) exact le_trans (Finset.card_le_card hunion) (Finset.card_union_le _ _) -- Helper lemmas: full projection implies full output count have hfull_K₀ : (∃ x₁ : X₁, ∀ x₂ : X₂, g (x₁, x₂) = false) → m₂ ≤ K₀ := by rintro ⟨x₁, hx₁⟩ have hsub : R₀.image Prod.snd = Finset.univ := by ext x₂; simp only [Finset.mem_image, Finset.mem_univ, iff_true] exact ⟨(x₁, x₂), Finset.mem_filter.mpr ⟨Finset.mem_univ _, hx₁ x₂⟩, rfl⟩ simp only [K₀, hsub, m₂, imageCard, le_rfl] have hfull_K₁ : (∃ x₁ : X₁, ∀ x₂ : X₂, g (x₁, x₂) = true) → m₂ ≤ K₁ := by rintro ⟨x₁, hx₁⟩ have hsub : R₁.image Prod.snd = Finset.univ := by ext x₂; simp only [Finset.mem_image, Finset.mem_univ, iff_true] exact ⟨(x₁, x₂), Finset.mem_filter.mpr ⟨Finset.mem_univ _, hx₁ x₂⟩, rfl⟩ simp only [K₁, hsub, m₂, imageCard, le_rfl] have hfull_L₀ : (∀ x₁ : X₁, ∃ x₂ : X₂, g (x₁, x₂) = false) → m₁ ≤ L₀ := by intro h have hsub : R₀.image Prod.fst = Finset.univ := by ext x₁; simp only [Finset.mem_image, Finset.mem_univ, iff_true] rcases h x₁ with ⟨x₂, hx₂⟩ exact ⟨(x₁, x₂), Finset.mem_filter.mpr ⟨Finset.mem_univ _, hx₂⟩, rfl⟩ simp only [L₀, hsub, m₁, imageCard, le_rfl] have hfull_L₁ : (∀ x₁ : X₁, ∃ x₂ : X₂, g (x₁, x₂) = true) → m₁ ≤ L₁ := by intro h have hsub : R₁.image Prod.fst = Finset.univ := by ext x₁; simp only [Finset.mem_image, Finset.mem_univ, iff_true] rcases h x₁ with ⟨x₂, hx₂⟩ exact ⟨(x₁, x₂), Finset.mem_filter.mpr ⟨Finset.mem_univ _, hx₂⟩, rfl⟩ simp only [L₁, hsub, m₁, imageCard, le_rfl] -- Apply slice dichotomy for both `b = false` and `b = true`! rcases slice_dichotomy g false with hK0 | hL1 · rcases slice_dichotomy g true with hK1 | hL0 · -- Both `K₀ ≥ m₂` and `K₁ ≥ m₂`! right; right; right have a := hfull_K₀ hK0 have b := hfull_K₁ hK1 omega · -- `K₀ ≥ m₂` and `L₀ ≥ m₁`! left have a := hfull_K₀ hK0 have b := hfull_L₀ hL0 omega · rcases slice_dichotomy g true with hK1 | hL0 · -- `K₁ ≥ m₂` and `L₁ ≥ m₁`! right; left have a := hfull_K₁ hK1 have b := hfull_L₁ hL1 omega · -- Both `L₀ ≥ m₁` and `L₁ ≥ m₁`! right; right; left have a := hfull_L₀ hL0 have b := hfull_L₁ hL1 omega /-- Image cardinality of `aliceJoin F G` splits cleanly into left (`Z₁`) and right (`Z₂`) outputs. -/ theorem imageCard_aliceJoin_eq {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : Type*} [Fintype X₁] [Fintype X₂] [DecidableEq Y₁] [DecidableEq Y₂] [DecidableEq Z₁] [DecidableEq Z₂] (F : X₁ → Y₁ → Z₁) (G : X₂ → Y₂ → Z₂) (C : Finset (Y₁ × Y₂)) : imageCard (aliceJoin F G) Finset.univ C = (((Finset.univ : Finset X₁) ×ˢ C.image Prod.fst).image (fun p => F p.1 p.2)).card + (((Finset.univ : Finset X₂) ×ˢ C.image Prod.snd).image (fun p => G p.1 p.2)).card := by let S₁ : Finset (Z₁ ⊕ Z₂) := (((Finset.univ : Finset X₁) ×ˢ C.image Prod.fst).image (fun p => F p.1 p.2)).image Sum.inl let S₂ : Finset (Z₁ ⊕ Z₂) := (((Finset.univ : Finset X₂) ×ˢ C.image Prod.snd).image (fun p => G p.1 p.2)).image Sum.inr have hdisj : Disjoint S₁ S₂ := by rw [Finset.disjoint_left] intro z hz₁ hz₂ rcases Finset.mem_image.mp hz₁ with ⟨z₁, _, rfl⟩ rcases Finset.mem_image.mp hz₂ with ⟨z₂, _, h⟩ cases h have hunion : ((Finset.univ : Finset (X₁ ⊕ X₂)) ×ˢ C).image (fun p => aliceJoin F G p.1 p.2) = S₁ ∪ S₂ := by ext z simp only [Finset.mem_image, Finset.mem_product, Finset.mem_univ, true_and, Finset.mem_union, S₁, S₂, Prod.exists] constructor · rintro ⟨x, y₁, y₂, hC, rfl⟩ cases x with | inl x₁ => left; refine ⟨F x₁ y₁, ⟨x₁, y₁, ⟨y₁, y₂, hC, rfl⟩, rfl⟩, rfl⟩ | inr x₂ => right; refine ⟨G x₂ y₂, ⟨x₂, y₂, ⟨y₁, y₂, hC, rfl⟩, rfl⟩, rfl⟩ · rintro (⟨z₁, ⟨x₁, y₁, ⟨a, b, hC, rfl⟩, rfl⟩, rfl⟩ | ⟨z₂, ⟨x₂, y₂, ⟨a, b, hC, rfl⟩, rfl⟩, rfl⟩) · exact ⟨Sum.inl x₁, a, b, hC, rfl⟩ · exact ⟨Sum.inr x₂, a, b, hC, rfl⟩ rw [imageCard, hunion, Finset.card_union_of_disjoint hdisj, Finset.card_image_of_injective _ Sum.inl_injective, Finset.card_image_of_injective _ Sum.inr_injective] /-- **THEOREM 7B (Dual 4-Case Product-Duplication Theorem for `aliceJoin F G`)**: For any Bob split `g : Y₁ × Y₂ → Bool` partitioning `Y₁ × Y₂` into `C₀` and `C₁`, the same 4-case product-duplication dichotomy holds. -/ theorem product_duplication_aliceJoin {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : Type*} [Fintype X₁] [Fintype Y₁] [Fintype X₂] [Fintype Y₂] [DecidableEq Y₁] [DecidableEq Y₂] [Nonempty Y₁] [Nonempty Y₂] [DecidableEq Z₁] [DecidableEq Z₂] (F : X₁ → Y₁ → Z₁) (G : X₂ → Y₂ → Z₂) (g : Y₁ × Y₂ → Bool) : let C₀ := Finset.univ.filter (fun p : Y₁ × Y₂ => g p = false) let C₁ := Finset.univ.filter (fun p : Y₁ × Y₂ => g p = true) let m₁ := imageCard F Finset.univ Finset.univ let m₂ := imageCard G Finset.univ Finset.univ let c₀ := imageCard (aliceJoin F G) Finset.univ C₀ let c₁ := imageCard (aliceJoin F G) Finset.univ C₁ m₁ + m₂ ≤ c₀ ∨ m₁ + m₂ ≤ c₁ ∨ 2 * m₁ + m₂ ≤ c₀ + c₁ ∨ m₁ + 2 * m₂ ≤ c₀ + c₁ := by intro C₀ C₁ m₁ m₂ c₀ c₁ let L₀ := (((Finset.univ : Finset X₁) ×ˢ C₀.image Prod.fst).image (fun p => F p.1 p.2)).card let K₀ := (((Finset.univ : Finset X₂) ×ˢ C₀.image Prod.snd).image (fun p => G p.1 p.2)).card let L₁ := (((Finset.univ : Finset X₁) ×ˢ C₁.image Prod.fst).image (fun p => F p.1 p.2)).card let K₁ := (((Finset.univ : Finset X₂) ×ˢ C₁.image Prod.snd).image (fun p => G p.1 p.2)).card have hc₀ : c₀ = L₀ + K₀ := imageCard_aliceJoin_eq F G C₀ have hc₁ : c₁ = L₁ + K₁ := imageCard_aliceJoin_eq F G C₁ have hcov₁ : m₁ ≤ L₀ + L₁ := by obtain ⟨y₂⟩ := ‹Nonempty Y₂› have hunion : ((Finset.univ : Finset X₁) ×ˢ Finset.univ).image (fun p => F p.1 p.2) ⊆ ((Finset.univ ×ˢ C₀.image Prod.fst).image (fun p => F p.1 p.2)) ∪ ((Finset.univ ×ˢ C₁.image Prod.fst).image (fun p => F p.1 p.2)) := by intro z hz rcases Finset.mem_image.mp hz with ⟨⟨x₁, y₁⟩, _, rfl⟩ cases hg : g (y₁, y₂) · exact Finset.mem_union_left _ (Finset.mem_image.mpr ⟨(x₁, y₁), Finset.mem_product.mpr ⟨Finset.mem_univ _, Finset.mem_image.mpr ⟨(y₁, y₂), Finset.mem_filter.mpr ⟨Finset.mem_univ _, hg⟩, rfl⟩⟩, rfl⟩) · exact Finset.mem_union_right _ (Finset.mem_image.mpr ⟨(x₁, y₁), Finset.mem_product.mpr ⟨Finset.mem_univ _, Finset.mem_image.mpr ⟨(y₁, y₂), Finset.mem_filter.mpr ⟨Finset.mem_univ _, hg⟩, rfl⟩⟩, rfl⟩) exact le_trans (Finset.card_le_card hunion) (Finset.card_union_le _ _) have hcov₂ : m₂ ≤ K₀ + K₁ := by obtain ⟨y₁⟩ := ‹Nonempty Y₁› have hunion : ((Finset.univ : Finset X₂) ×ˢ Finset.univ).image (fun p => G p.1 p.2) ⊆ ((Finset.univ ×ˢ C₀.image Prod.snd).image (fun p => G p.1 p.2)) ∪ ((Finset.univ ×ˢ C₁.image Prod.snd).image (fun p => G p.1 p.2)) := by intro z hz rcases Finset.mem_image.mp hz with ⟨⟨x₂, y₂⟩, _, rfl⟩ cases hg : g (y₁, y₂) · exact Finset.mem_union_left _ (Finset.mem_image.mpr ⟨(x₂, y₂), Finset.mem_product.mpr ⟨Finset.mem_univ _, Finset.mem_image.mpr ⟨(y₁, y₂), Finset.mem_filter.mpr ⟨Finset.mem_univ _, hg⟩, rfl⟩⟩, rfl⟩) · exact Finset.mem_union_right _ (Finset.mem_image.mpr ⟨(x₂, y₂), Finset.mem_product.mpr ⟨Finset.mem_univ _, Finset.mem_image.mpr ⟨(y₁, y₂), Finset.mem_filter.mpr ⟨Finset.mem_univ _, hg⟩, rfl⟩⟩, rfl⟩) exact le_trans (Finset.card_le_card hunion) (Finset.card_union_le _ _) have hfull_K₀ : (∃ y₁ : Y₁, ∀ y₂ : Y₂, g (y₁, y₂) = false) → m₂ ≤ K₀ := by rintro ⟨y₁, hy₁⟩ have hsub : C₀.image Prod.snd = Finset.univ := by ext y₂; simp only [Finset.mem_image, Finset.mem_univ, iff_true] exact ⟨(y₁, y₂), Finset.mem_filter.mpr ⟨Finset.mem_univ _, hy₁ y₂⟩, rfl⟩ simp only [K₀, hsub, m₂, imageCard, le_rfl] have hfull_K₁ : (∃ y₁ : Y₁, ∀ y₂ : Y₂, g (y₁, y₂) = true) → m₂ ≤ K₁ := by rintro ⟨y₁, hy₁⟩ have hsub : C₁.image Prod.snd = Finset.univ := by ext y₂; simp only [Finset.mem_image, Finset.mem_univ, iff_true] exact ⟨(y₁, y₂), Finset.mem_filter.mpr ⟨Finset.mem_univ _, hy₁ y₂⟩, rfl⟩ simp only [K₁, hsub, m₂, imageCard, le_rfl] have hfull_L₀ : (∀ y₁ : Y₁, ∃ y₂ : Y₂, g (y₁, y₂) = false) → m₁ ≤ L₀ := by intro h have hsub : C₀.image Prod.fst = Finset.univ := by ext y₁; simp only [Finset.mem_image, Finset.mem_univ, iff_true] rcases h y₁ with ⟨y₂, hy₂⟩ exact ⟨(y₁, y₂), Finset.mem_filter.mpr ⟨Finset.mem_univ _, hy₂⟩, rfl⟩ simp only [L₀, hsub, m₁, imageCard, le_rfl] have hfull_L₁ : (∀ y₁ : Y₁, ∃ y₂ : Y₂, g (y₁, y₂) = true) → m₁ ≤ L₁ := by intro h have hsub : C₁.image Prod.fst = Finset.univ := by ext y₁; simp only [Finset.mem_image, Finset.mem_univ, iff_true] rcases h y₁ with ⟨y₂, hy₂⟩ exact ⟨(y₁, y₂), Finset.mem_filter.mpr ⟨Finset.mem_univ _, hy₂⟩, rfl⟩ simp only [L₁, hsub, m₁, imageCard, le_rfl] rcases slice_dichotomy g false with hK0 | hL1 · rcases slice_dichotomy g true with hK1 | hL0 · right; right; right have a := hfull_K₀ hK0; have b := hfull_K₁ hK1; omega · left have a := hfull_K₀ hK0; have b := hfull_L₀ hL0; omega · rcases slice_dichotomy g true with hK1 | hL0 · right; left have a := hfull_K₁ hK1; have b := hfull_L₁ hL1; omega · right; right; left have a := hfull_L₀ hL0; have b := hfull_L₁ hL1; omega /-! ### Exact Depth `D(T₃) = 6` of the 27-Leaf Universal Ternary Protocol Tree `T₃` -/ /-- Universal ternary protocol-tree communication games `T₀, T₁, T₂, T₃` with `1, 3, 9, 27` leaves. -/ abbrev Z0 := Unit abbrev Z1 := Z0 ⊕ (Z0 ⊕ Z0) abbrev Z2 := Z1 ⊕ (Z1 ⊕ Z1) abbrev Z3 := Z2 ⊕ (Z2 ⊕ Z2) abbrev Y0 := Unit abbrev Y1 := Y0 × (Y0 ⊕ Y0) abbrev Y2 := Y1 × (Y1 ⊕ Y1) def U0 : Unit → Y0 → Z0 := fun _ _ => () def U1 := aliceJoin U0 (bobJoin U0 U0) def U2 := aliceJoin U1 (bobJoin U1 U1) def U3 := aliceJoin U2 (bobJoin U2 U2) /-- Helper: lift a protocol on `(X₁, Y₁)` to `(X₁ ⊕ X₂, Y₁ × Y₂)` agreeing on `Sum.inl x₁`. -/ def liftLeftAlice {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : Type*} : Protocol X₁ Y₁ Z₁ → Protocol (X₁ ⊕ X₂) (Y₁ × Y₂) (Z₁ ⊕ Z₂) | .leaf z₁ => .leaf (.inl z₁) | .alice g L R => .alice (fun x => match x with | .inl x₁ => g x₁ | .inr _ => false) (liftLeftAlice L) (liftLeftAlice R) | .bob g L R => .bob (fun y => g y.1) (liftLeftAlice L) (liftLeftAlice R) def liftRightAlice {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : Type*} : Protocol X₂ Y₂ Z₂ → Protocol (X₁ ⊕ X₂) (Y₁ × Y₂) (Z₁ ⊕ Z₂) | .leaf z₂ => .leaf (.inr z₂) | .alice g L R => .alice (fun x => match x with | .inl _ => false | .inr x₂ => g x₂) (liftRightAlice L) (liftRightAlice R) | .bob g L R => .bob (fun y => g y.2) (liftRightAlice L) (liftRightAlice R) def protoAliceJoin {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : Type*} (P₁ : Protocol X₁ Y₁ Z₁) (P₂ : Protocol X₂ Y₂ Z₂) : Protocol (X₁ ⊕ X₂) (Y₁ × Y₂) (Z₁ ⊕ Z₂) := .alice (fun x => match x with | .inl _ => false | .inr _ => true) (liftLeftAlice P₁) (liftRightAlice P₂) def liftLeftBob {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : Type*} : Protocol X₁ Y₁ Z₁ → Protocol (X₁ × X₂) (Y₁ ⊕ Y₂) (Z₁ ⊕ Z₂) | .leaf z₁ => .leaf (.inl z₁) | .alice g L R => .alice (fun x => g x.1) (liftLeftBob L) (liftLeftBob R) | .bob g L R => .bob (fun y => match y with | .inl y₁ => g y₁ | .inr _ => false) (liftLeftBob L) (liftLeftBob R) def liftRightBob {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : Type*} : Protocol X₂ Y₂ Z₂ → Protocol (X₁ × X₂) (Y₁ ⊕ Y₂) (Z₁ ⊕ Z₂) | .leaf z₂ => .leaf (.inr z₂) | .alice g L R => .alice (fun x => g x.2) (liftRightBob L) (liftRightBob R) | .bob g L R => .bob (fun y => match y with | .inl _ => false | .inr y₂ => g y₂) (liftRightBob L) (liftRightBob R) def protoBobJoin {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : Type*} (P₁ : Protocol X₁ Y₁ Z₁) (P₂ : Protocol X₂ Y₂ Z₂) : Protocol (X₁ × X₂) (Y₁ ⊕ Y₂) (Z₁ ⊕ Z₂) := .bob (fun y => match y with | .inl _ => false | .inr _ => true) (liftLeftBob P₁) (liftRightBob P₂) theorem liftLeftAlice_eval {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : Type*} (P₁ : Protocol X₁ Y₁ Z₁) (x₁ : X₁) (y : Y₁ × Y₂) : (liftLeftAlice (X₂ := X₂) (Y₂ := Y₂) (Z₂ := Z₂) P₁).eval (.inl x₁) y = .inl (P₁.eval x₁ y.1) := by induction P₁ with | leaf _ => rfl | alice g L R ihl ihr => simp only [liftLeftAlice, Protocol.eval]; split_ifs <;> [exact ihr; exact ihl] | bob g L R ihl ihr => simp only [liftLeftAlice, Protocol.eval]; split_ifs <;> [exact ihr; exact ihl] theorem liftRightAlice_eval {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : Type*} (P₂ : Protocol X₂ Y₂ Z₂) (x₂ : X₂) (y : Y₁ × Y₂) : (liftRightAlice (X₁ := X₁) (Y₁ := Y₁) (Z₁ := Z₁) P₂).eval (.inr x₂) y = .inr (P₂.eval x₂ y.2) := by induction P₂ with | leaf _ => rfl | alice g L R ihl ihr => simp only [liftRightAlice, Protocol.eval]; split_ifs <;> [exact ihr; exact ihl] | bob g L R ihl ihr => simp only [liftRightAlice, Protocol.eval]; split_ifs <;> [exact ihr; exact ihl] theorem liftLeftBob_eval {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : Type*} (P₁ : Protocol X₁ Y₁ Z₁) (x : X₁ × X₂) (y₁ : Y₁) : (liftLeftBob (X₂ := X₂) (Y₂ := Y₂) (Z₂ := Z₂) P₁).eval x (.inl y₁) = .inl (P₁.eval x.1 y₁) := by induction P₁ with | leaf _ => rfl | alice g L R ihl ihr => simp only [liftLeftBob, Protocol.eval]; split_ifs <;> [exact ihr; exact ihl] | bob g L R ihl ihr => simp only [liftLeftBob, Protocol.eval]; split_ifs <;> [exact ihr; exact ihl] theorem liftRightBob_eval {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : Type*} (P₂ : Protocol X₂ Y₂ Z₂) (x : X₁ × X₂) (y₂ : Y₂) : (liftRightBob (X₁ := X₁) (Y₁ := Y₁) (Z₁ := Z₁) P₂).eval x (.inr y₂) = .inr (P₂.eval x.2 y₂) := by induction P₂ with | leaf _ => rfl | alice g L R ihl ihr => simp only [liftRightBob, Protocol.eval]; split_ifs <;> [exact ihr; exact ihl] | bob g L R ihl ihr => simp only [liftRightBob, Protocol.eval]; split_ifs <;> [exact ihr; exact ihl] theorem liftLeftAlice_depth {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : Type*} (P₁ : Protocol X₁ Y₁ Z₁) : (liftLeftAlice (X₂ := X₂) (Y₂ := Y₂) (Z₂ := Z₂) P₁).depth = P₁.depth := by induction P₁ with | leaf _ => rfl | alice _ _ _ ihl ihr => simp [liftLeftAlice, Protocol.depth, ihl, ihr] | bob _ _ _ ihl ihr => simp [liftLeftAlice, Protocol.depth, ihl, ihr] theorem liftRightAlice_depth {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : Type*} (P₂ : Protocol X₂ Y₂ Z₂) : (liftRightAlice (X₁ := X₁) (Y₁ := Y₁) (Z₁ := Z₁) P₂).depth = P₂.depth := by induction P₂ with | leaf _ => rfl | alice _ _ _ ihl ihr => simp [liftRightAlice, Protocol.depth, ihl, ihr] | bob _ _ _ ihl ihr => simp [liftRightAlice, Protocol.depth, ihl, ihr] theorem liftLeftBob_depth {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : Type*} (P₁ : Protocol X₁ Y₁ Z₁) : (liftLeftBob (X₂ := X₂) (Y₂ := Y₂) (Z₂ := Z₂) P₁).depth = P₁.depth := by induction P₁ with | leaf _ => rfl | alice _ _ _ ihl ihr => simp [liftLeftBob, Protocol.depth, ihl, ihr] | bob _ _ _ ihl ihr => simp [liftLeftBob, Protocol.depth, ihl, ihr] theorem liftRightBob_depth {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : Type*} (P₂ : Protocol X₂ Y₂ Z₂) : (liftRightBob (X₁ := X₁) (Y₁ := Y₁) (Z₁ := Z₁) P₂).depth = P₂.depth := by induction P₂ with | leaf _ => rfl | alice _ _ _ ihl ihr => simp [liftRightBob, Protocol.depth, ihl, ihr] | bob _ _ _ ihl ihr => simp [liftRightBob, Protocol.depth, ihl, ihr] theorem liftLeftAlice_leaves {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : Type*} (P₁ : Protocol X₁ Y₁ Z₁) : (liftLeftAlice (X₂ := X₂) (Y₂ := Y₂) (Z₂ := Z₂) P₁).leaves = P₁.leaves := by induction P₁ with | leaf _ => rfl | alice _ _ _ ihl ihr => simp [liftLeftAlice, Protocol.leaves, ihl, ihr] | bob _ _ _ ihl ihr => simp [liftLeftAlice, Protocol.leaves, ihl, ihr] theorem liftRightAlice_leaves {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : Type*} (P₂ : Protocol X₂ Y₂ Z₂) : (liftRightAlice (X₁ := X₁) (Y₁ := Y₁) (Z₁ := Z₁) P₂).leaves = P₂.leaves := by induction P₂ with | leaf _ => rfl | alice _ _ _ ihl ihr => simp [liftRightAlice, Protocol.leaves, ihl, ihr] | bob _ _ _ ihl ihr => simp [liftRightAlice, Protocol.leaves, ihl, ihr] theorem liftLeftBob_leaves {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : Type*} (P₁ : Protocol X₁ Y₁ Z₁) : (liftLeftBob (X₂ := X₂) (Y₂ := Y₂) (Z₂ := Z₂) P₁).leaves = P₁.leaves := by induction P₁ with | leaf _ => rfl | alice _ _ _ ihl ihr => simp [liftLeftBob, Protocol.leaves, ihl, ihr] | bob _ _ _ ihl ihr => simp [liftLeftBob, Protocol.leaves, ihl, ihr] theorem liftRightBob_leaves {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : Type*} (P₂ : Protocol X₂ Y₂ Z₂) : (liftRightBob (X₁ := X₁) (Y₁ := Y₁) (Z₁ := Z₁) P₂).leaves = P₂.leaves := by induction P₂ with | leaf _ => rfl | alice _ _ _ ihl ihr => simp [liftRightBob, Protocol.leaves, ihl, ihr] | bob _ _ _ ihl ihr => simp [liftRightBob, Protocol.leaves, ihl, ihr] theorem protoAliceJoin_computes {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : Type*} {F : X₁ → Y₁ → Z₁} {G : X₂ → Y₂ → Z₂} {P₁ : Protocol X₁ Y₁ Z₁} {P₂ : Protocol X₂ Y₂ Z₂} (h₁ : P₁.Computes F) (h₂ : P₂.Computes G) : (protoAliceJoin P₁ P₂).Computes (aliceJoin F G) := by intro x y cases x with | inl x₁ => simp only [protoAliceJoin, Protocol.eval, Bool.false_eq_true, ↓reduceIte, liftLeftAlice_eval, aliceJoin] exact congrArg Sum.inl (h₁ x₁ y.1) | inr x₂ => simp only [protoAliceJoin, Protocol.eval, ↓reduceIte, liftRightAlice_eval, aliceJoin] exact congrArg Sum.inr (h₂ x₂ y.2) theorem protoBobJoin_computes {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : Type*} {F : X₁ → Y₁ → Z₁} {G : X₂ → Y₂ → Z₂} {P₁ : Protocol X₁ Y₁ Z₁} {P₂ : Protocol X₂ Y₂ Z₂} (h₁ : P₁.Computes F) (h₂ : P₂.Computes G) : (protoBobJoin P₁ P₂).Computes (bobJoin F G) := by intro x y cases y with | inl y₁ => simp only [protoBobJoin, Protocol.eval, Bool.false_eq_true, ↓reduceIte, liftLeftBob_eval, bobJoin] exact congrArg Sum.inl (h₁ x.1 y₁) | inr y₂ => simp only [protoBobJoin, Protocol.eval, ↓reduceIte, liftRightBob_eval, bobJoin] exact congrArg Sum.inr (h₂ x.2 y₂) /-- Output image cardinality of `aliceJoin F G` over all inputs equals the sum of image cardinalities. -/ theorem imageCard_aliceJoin_univ {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : Type*} [Fintype X₁] [Fintype Y₁] [Fintype X₂] [Fintype Y₂] [DecidableEq Y₁] [DecidableEq Y₂] [Nonempty Y₁] [Nonempty Y₂] [DecidableEq Z₁] [DecidableEq Z₂] (F : X₁ → Y₁ → Z₁) (G : X₂ → Y₂ → Z₂) : imageCard (aliceJoin F G) Finset.univ Finset.univ = imageCard F Finset.univ Finset.univ + imageCard G Finset.univ Finset.univ := by rw [imageCard_aliceJoin_eq] have h1 : (Finset.univ : Finset (Y₁ × Y₂)).image Prod.fst = Finset.univ := by obtain ⟨y₂⟩ := ‹Nonempty Y₂› ext y₁; simp only [Finset.mem_image, Finset.mem_univ, true_and, iff_true]; exact ⟨(y₁, y₂), rfl⟩ have h2 : (Finset.univ : Finset (Y₁ × Y₂)).image Prod.snd = Finset.univ := by obtain ⟨y₁⟩ := ‹Nonempty Y₁› ext y₂; simp only [Finset.mem_image, Finset.mem_univ, true_and, iff_true]; exact ⟨(y₁, y₂), rfl⟩ rw [h1, h2]; rfl theorem imageCard_bobJoin_univ {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : Type*} [Fintype X₁] [Fintype Y₁] [Fintype X₂] [Fintype Y₂] [DecidableEq X₁] [DecidableEq X₂] [Nonempty X₁] [Nonempty X₂] [DecidableEq Z₁] [DecidableEq Z₂] (F : X₁ → Y₁ → Z₁) (G : X₂ → Y₂ → Z₂) : imageCard (bobJoin F G) Finset.univ Finset.univ = imageCard F Finset.univ Finset.univ + imageCard G Finset.univ Finset.univ := by rw [imageCard_bobJoin_eq] have h1 : (Finset.univ : Finset (X₁ × X₂)).image Prod.fst = Finset.univ := by obtain ⟨x₂⟩ := ‹Nonempty X₂› ext x₁; simp only [Finset.mem_image, Finset.mem_univ, true_and, iff_true]; exact ⟨(x₁, x₂), rfl⟩ have h2 : (Finset.univ : Finset (X₁ × X₂)).image Prod.snd = Finset.univ := by obtain ⟨x₁⟩ := ‹Nonempty X₁› ext x₂; simp only [Finset.mem_image, Finset.mem_univ, true_and, iff_true]; exact ⟨(x₁, x₂), rfl⟩ rw [h1, h2]; rfl /-- Exact image cardinalities of the universal ternary protocol trees `U0, U1, U2, U3`: `1, 3, 9, 27`. -/ theorem U0_imageCard : imageCard U0 Finset.univ Finset.univ = 1 := by decide theorem U1_imageCard : imageCard U1 Finset.univ Finset.univ = 3 := by rw [U1, imageCard_aliceJoin_univ, imageCard_bobJoin_univ, U0_imageCard] theorem U2_imageCard : imageCard U2 Finset.univ Finset.univ = 9 := by rw [U2, imageCard_aliceJoin_univ, imageCard_bobJoin_univ, U1_imageCard] theorem U3_imageCard : imageCard U3 Finset.univ Finset.univ = 27 := by rw [U3, imageCard_aliceJoin_univ, imageCard_bobJoin_univ, U2_imageCard] /-- Canonical ternary protocols `P0, P1, P2, P3` computing `U0, U1, U2, U3` with depths `0, 2, 4, 6` and leaves `1, 3, 9, 27`. -/ def P0 : Protocol Unit Unit Unit := .leaf () def P1 := protoAliceJoin P0 (protoBobJoin P0 P0) def P2 := protoAliceJoin P1 (protoBobJoin P1 P1) def P3 := protoAliceJoin P2 (protoBobJoin P2 P2) theorem P3_computes_U3 : P3.Computes U3 := by have h0 : P0.Computes U0 := fun _ _ => rfl have h1 : P1.Computes U1 := protoAliceJoin_computes h0 (protoBobJoin_computes h0 h0) have h2 : P2.Computes U2 := protoAliceJoin_computes h1 (protoBobJoin_computes h1 h1) exact protoAliceJoin_computes h2 (protoBobJoin_computes h2 h2) theorem P3_depth_and_leaves : P3.depth = 6 ∧ P3.leaves = 27 := by have d0 : P0.depth = 0 := rfl have l0 : P0.leaves = 1 := rfl have d1 : P1.depth = 2 := by simp [P1, protoAliceJoin, protoBobJoin, Protocol.depth, liftLeftAlice_depth, liftRightAlice_depth, liftLeftBob_depth, liftRightBob_depth, d0] have l1 : P1.leaves = 3 := by simp [P1, protoAliceJoin, protoBobJoin, Protocol.leaves, liftLeftAlice_leaves, liftRightAlice_leaves, liftLeftBob_leaves, liftRightBob_leaves, l0] have d2 : P2.depth = 4 := by simp [P2, protoAliceJoin, protoBobJoin, Protocol.depth, liftLeftAlice_depth, liftRightAlice_depth, liftLeftBob_depth, liftRightBob_depth, d1] have l2 : P2.leaves = 9 := by simp [P2, protoAliceJoin, protoBobJoin, Protocol.leaves, liftLeftAlice_leaves, liftRightAlice_leaves, liftLeftBob_leaves, liftRightBob_leaves, l1] have d3 : P3.depth = 6 := by simp [P3, protoAliceJoin, protoBobJoin, Protocol.depth, liftLeftAlice_depth, liftRightAlice_depth, liftLeftBob_depth, liftRightBob_depth, d2] have l3 : P3.leaves = 27 := by simp [P3, protoAliceJoin, protoBobJoin, Protocol.leaves, liftLeftAlice_leaves, liftRightAlice_leaves, liftLeftBob_leaves, liftRightBob_leaves, l2] exact ⟨d3, l3⟩ /-- **HEADLINE THEOREM 7 (Exact Depth `D(U3) = 6` of the 27-Leaf Universal Ternary Tree `U3`)**: Even though `U3` has only `L(U3) = 27 < 32 = 2^5` leaves, **no** depth-5 deterministic communication protocol can compute `U3`! Proved directly via the 4-Case Product-Duplication Theorems (`7A` & `7B`), yielding an exact `D(U3) / log₂ L(U3) = 6 / log₂ 27 = 2 / log₂ 3 ≈ 1.2619` separation. -/ theorem ternary_universal_tree_U3_exact_depth : HasDepth U3 6 ∧ HasLeaves U3 27 ∧ ¬ HasDepth U3 5 := by refine ⟨⟨P3, P3_computes_U3, le_of_eq P3_depth_and_leaves.1⟩, ⟨P3, P3_computes_U3, le_of_eq P3_depth_and_leaves.2⟩, ?_⟩ rintro ⟨P, hP, hd⟩ cases P with | leaf z => have hlb := (imageCard_le_leaves (.leaf z) U3 Finset.univ Finset.univ (fun x _ y _ => hP x y)).1 rw [U3_imageCard] at hlb simp [Protocol.leaves] at hlb | alice g L R => simp only [Protocol.depth] at hd have hLd : L.depth ≤ 4 := by omega have hRd : R.depth ≤ 4 := by omega -- Restrict Alice's split `g : X₂ ⊕ (X₂ × X₂) → Bool` to the left `X₂` and right `X₂ × X₂` let A0 := Finset.univ.filter (fun x => g x = false) let A1 := Finset.univ.filter (fun x => g x = true) have hL_ub : imageCard U3 A0 Finset.univ ≤ 16 := by have h1 := (imageCard_le_leaves L U3 A0 Finset.univ (fun x hx y _ => by have hgx : g x = false := (Finset.mem_filter.mp hx).2 have h := hP x y simpa [Protocol.eval, hgx] using h)).2 exact le_trans h1 (Nat.pow_le_pow_right (by omega) hLd) have hR_ub : imageCard U3 A1 Finset.univ ≤ 16 := by have h1 := (imageCard_le_leaves R U3 A1 Finset.univ (fun x hx y _ => by have hgx : g x = true := (Finset.mem_filter.mp hx).2 have h := hP x y simpa [Protocol.eval, hgx] using h)).2 exact le_trans h1 (Nat.pow_le_pow_right (by omega) hRd) -- Split `imageCard U3 A_b univ` into `inl` (from `U2`) and `inr` (from `bobJoin U2 U2`)! let gL := fun x => g (.inl x) let gR := fun p => g (.inr p) let AL0 := Finset.univ.filter (fun x => gL x = false) let AL1 := Finset.univ.filter (fun x => gL x = true) let AR0 := Finset.univ.filter (fun p => gR p = false) let AR1 := Finset.univ.filter (fun p => gR p = true) -- Show `imageCard U2 AL0 univ + imageCard (bobJoin U2 U2) AR0 univ ≤ imageCard U3 A0 univ` have hsplit0 : imageCard U2 AL0 Finset.univ + imageCard (bobJoin U2 U2) AR0 Finset.univ ≤ imageCard U3 A0 Finset.univ := by let S₁ : Finset Z3 := ((AL0 ×ˢ Finset.univ).image (fun p => U2 p.1 p.2)).image Sum.inl let S₂ : Finset Z3 := ((AR0 ×ˢ Finset.univ).image (fun p => bobJoin U2 U2 p.1 p.2)).image Sum.inr have hdisj : Disjoint S₁ S₂ := by rw [Finset.disjoint_left] intro z hz1 hz2 rcases Finset.mem_image.mp hz1 with ⟨_, _, rfl⟩ rcases Finset.mem_image.mp hz2 with ⟨_, _, h⟩; cases h have hsub : S₁ ∪ S₂ ⊆ (A0 ×ˢ Finset.univ).image (fun p => U3 p.1 p.2) := by intro z hz rcases Finset.mem_union.mp hz with h1 | h2 · rcases Finset.mem_image.mp h1 with ⟨z₁, hz₁, rfl⟩ rcases Finset.mem_image.mp hz₁ with ⟨⟨x₁, y₁⟩, hxy, rfl⟩ have hx₁ : g (.inl x₁) = false := (Finset.mem_filter.mp (Finset.mem_product.mp hxy).1).2 obtain ⟨y₂⟩ := (inferInstance : Nonempty (Y2 ⊕ Y2)) exact Finset.mem_image.mpr ⟨(.inl x₁, (y₁, y₂)), Finset.mem_product.mpr ⟨Finset.mem_filter.mpr ⟨Finset.mem_univ _, hx₁⟩, Finset.mem_univ _⟩, rfl⟩ · rcases Finset.mem_image.mp h2 with ⟨z₂, hz₂, rfl⟩ rcases Finset.mem_image.mp hz₂ with ⟨⟨x₂, y₂⟩, hxy, rfl⟩ have hx₂ : g (.inr x₂) = false := (Finset.mem_filter.mp (Finset.mem_product.mp hxy).1).2 obtain ⟨y₁⟩ := (inferInstance : Nonempty Y2) exact Finset.mem_image.mpr ⟨(.inr x₂, (y₁, y₂)), Finset.mem_product.mpr ⟨Finset.mem_filter.mpr ⟨Finset.mem_univ _, hx₂⟩, Finset.mem_univ _⟩, rfl⟩ have hcard := Finset.card_le_card hsub rw [Finset.card_union_of_disjoint hdisj, Finset.card_image_of_injective _ Sum.inl_injective, Finset.card_image_of_injective _ Sum.inr_injective] at hcard exact hcard have hsplit1 : imageCard U2 AL1 Finset.univ + imageCard (bobJoin U2 U2) AR1 Finset.univ ≤ imageCard U3 A1 Finset.univ := by let S₁ : Finset Z3 := ((AL1 ×ˢ Finset.univ).image (fun p => U2 p.1 p.2)).image Sum.inl let S₂ : Finset Z3 := ((AR1 ×ˢ Finset.univ).image (fun p => bobJoin U2 U2 p.1 p.2)).image Sum.inr have hdisj : Disjoint S₁ S₂ := by rw [Finset.disjoint_left] intro z hz1 hz2 rcases Finset.mem_image.mp hz1 with ⟨_, _, rfl⟩ rcases Finset.mem_image.mp hz2 with ⟨_, _, h⟩; cases h have hsub : S₁ ∪ S₂ ⊆ (A1 ×ˢ Finset.univ).image (fun p => U3 p.1 p.2) := by intro z hz rcases Finset.mem_union.mp hz with h1 | h2 · rcases Finset.mem_image.mp h1 with ⟨z₁, hz₁, rfl⟩ rcases Finset.mem_image.mp hz₁ with ⟨⟨x₁, y₁⟩, hxy, rfl⟩ have hx₁ : g (.inl x₁) = true := (Finset.mem_filter.mp (Finset.mem_product.mp hxy).1).2 obtain ⟨y₂⟩ := (inferInstance : Nonempty (Y2 ⊕ Y2)) exact Finset.mem_image.mpr ⟨(.inl x₁, (y₁, y₂)), Finset.mem_product.mpr ⟨Finset.mem_filter.mpr ⟨Finset.mem_univ _, hx₁⟩, Finset.mem_univ _⟩, rfl⟩ · rcases Finset.mem_image.mp h2 with ⟨z₂, hz₂, rfl⟩ rcases Finset.mem_image.mp hz₂ with ⟨⟨x₂, y₂⟩, hxy, rfl⟩ have hx₂ : g (.inr x₂) = true := (Finset.mem_filter.mp (Finset.mem_product.mp hxy).1).2 obtain ⟨y₁⟩ := (inferInstance : Nonempty Y2) exact Finset.mem_image.mpr ⟨(.inr x₂, (y₁, y₂)), Finset.mem_product.mpr ⟨Finset.mem_filter.mpr ⟨Finset.mem_univ _, hx₂⟩, Finset.mem_univ _⟩, rfl⟩ have hcard := Finset.card_le_card hsub rw [Finset.card_union_of_disjoint hdisj, Finset.card_image_of_injective _ Sum.inl_injective, Finset.card_image_of_injective _ Sum.inr_injective] at hcard exact hcard -- Covering bound on `U2`: `9 ≤ imageCard U2 AL0 univ + imageCard U2 AL1 univ` have hcovL : 9 ≤ imageCard U2 AL0 Finset.univ + imageCard U2 AL1 Finset.univ := by rw [← U2_imageCard] have hunion : (Finset.univ ×ˢ Finset.univ).image (fun p => U2 p.1 p.2) ⊆ (AL0 ×ˢ Finset.univ).image (fun p => U2 p.1 p.2) ∪ (AL1 ×ˢ Finset.univ).image (fun p => U2 p.1 p.2) := by intro z hz rcases Finset.mem_image.mp hz with ⟨⟨x, y⟩, _, rfl⟩ cases hgx : gL x · exact Finset.mem_union_left _ (Finset.mem_image.mpr ⟨(x, y), Finset.mem_product.mpr ⟨Finset.mem_filter.mpr ⟨Finset.mem_univ _, hgx⟩, Finset.mem_univ _⟩, rfl⟩) · exact Finset.mem_union_right _ (Finset.mem_image.mpr ⟨(x, y), Finset.mem_product.mpr ⟨Finset.mem_filter.mpr ⟨Finset.mem_univ _, hgx⟩, Finset.mem_univ _⟩, rfl⟩) exact le_trans (Finset.card_le_card hunion) (Finset.card_union_le _ _) -- Apply Product-Duplication Theorem 7A to `bobJoin U2 U2` with split `gR`! have hdup := product_duplication_bobJoin U2 U2 gR dsimp only at hdup change imageCard U2 Finset.univ Finset.univ + imageCard U2 Finset.univ Finset.univ ≤ imageCard (bobJoin U2 U2) AR0 Finset.univ ∨ imageCard U2 Finset.univ Finset.univ + imageCard U2 Finset.univ Finset.univ ≤ imageCard (bobJoin U2 U2) AR1 Finset.univ ∨ 2 * imageCard U2 Finset.univ Finset.univ + imageCard U2 Finset.univ Finset.univ ≤ imageCard (bobJoin U2 U2) AR0 Finset.univ + imageCard (bobJoin U2 U2) AR1 Finset.univ ∨ imageCard U2 Finset.univ Finset.univ + 2 * imageCard U2 Finset.univ Finset.univ ≤ imageCard (bobJoin U2 U2) AR0 Finset.univ + imageCard (bobJoin U2 U2) AR1 Finset.univ at hdup rw [U2_imageCard] at hdup -- Every branch forces either `18 ≤ 16` or `36 ≤ 32`! rcases hdup with h1 | h2 | h3 | h4 <;> omega | bob g L R => simp only [Protocol.depth] at hd have hLd : L.depth ≤ 4 := by omega have hRd : R.depth ≤ 4 := by omega let B0 := Finset.univ.filter (fun y => g y = false) let B1 := Finset.univ.filter (fun y => g y = true) have hL_ub : imageCard U3 Finset.univ B0 ≤ 16 := by have h1 := (imageCard_le_leaves L U3 Finset.univ B0 (fun x _ y hy => by have hgy : g y = false := (Finset.mem_filter.mp hy).2 have h := hP x y simpa [Protocol.eval, hgy] using h)).2 exact le_trans h1 (Nat.pow_le_pow_right (by omega) hLd) have hR_ub : imageCard U3 Finset.univ B1 ≤ 16 := by have h1 := (imageCard_le_leaves R U3 Finset.univ B1 (fun x _ y hy => by have hgy : g y = true := (Finset.mem_filter.mp hy).2 have h := hP x y simpa [Protocol.eval, hgy] using h)).2 exact le_trans h1 (Nat.pow_le_pow_right (by omega) hRd) -- Apply Dual Product-Duplication Theorem 7B to `U3 = aliceJoin U2 (bobJoin U2 U2)`! have hdup := product_duplication_aliceJoin U2 (bobJoin U2 U2) g dsimp only at hdup change imageCard U2 Finset.univ Finset.univ + imageCard (bobJoin U2 U2) Finset.univ Finset.univ ≤ imageCard U3 Finset.univ B0 ∨ imageCard U2 Finset.univ Finset.univ + imageCard (bobJoin U2 U2) Finset.univ Finset.univ ≤ imageCard U3 Finset.univ B1 ∨ 2 * imageCard U2 Finset.univ Finset.univ + imageCard (bobJoin U2 U2) Finset.univ Finset.univ ≤ imageCard U3 Finset.univ B0 + imageCard U3 Finset.univ B1 ∨ imageCard U2 Finset.univ Finset.univ + 2 * imageCard (bobJoin U2 U2) Finset.univ Finset.univ ≤ imageCard U3 Finset.univ B0 + imageCard U3 Finset.univ B1 at hdup have hm1 : imageCard U2 Finset.univ Finset.univ = 9 := U2_imageCard have hm2 : imageCard (bobJoin U2 U2) Finset.univ Finset.univ = 18 := by rw [imageCard_bobJoin_univ, U2_imageCard] rw [hm1, hm2] at hdup -- Every branch gives `27 ≤ 16` or `36 ≤ 32` or `45 ≤ 32`! rcases hdup with h1 | h2 | h3 | h4 <;> omega /-! ### Exact Sharpness of `supergoldenCap 2 = 3`: 4-Leaf Alternating Caterpillar `C₄` -/ /-- The 4-leaf alternating caterpillar communication matrix `cat4 : Fin 3 → Fin 2 → Fin 4`: `row 0 = [0, 0]`, `row 1 = [1, 2]`, `row 2 = [1, 3]`. -/ def cat4 (r : Fin 3) (c : Fin 2) : Fin 4 := match r.val, c.val with | 0, _ => 0 | 1, 0 => 1 | 2, 0 => 1 | 1, 1 => 2 | _, _ => 3 /-- Canonical 4-leaf, depth-3 protocol computing `cat4`. -/ def cat4Proto : Protocol (Fin 3) (Fin 2) (Fin 4) := .alice (fun r => decide (r.val ≠ 0)) (.leaf 0) (.bob (fun c => decide (c.val = 1)) (.leaf 1) (.alice (fun r => decide (r.val = 2)) (.leaf 2) (.leaf 3))) theorem cat4Proto_computes : cat4Proto.Computes cat4 := by intro r c; fin_cases r <;> fin_cases c <;> decide theorem cat4Proto_depth_and_leaves : cat4Proto.depth = 3 ∧ cat4Proto.leaves = 4 := by decide /-- **HEADLINE THEOREM 8 (Exact Sharpness of `supergoldenCap 2 = 3`)**: The 4-leaf alternating caterpillar `cat4` has `L(cat4) = 4`, yet `¬ HasDepth cat4 2` (exact depth `D(cat4) = 3`, achieving `D / log₂ L = 3/2 = 1.5`). Therefore `supergoldenCap 2 = 3` in Theorem 1 (`supergolden_protocol_balancing`) cannot be increased even by `1`. -/ theorem cat4_exact_sharpness : HasDepth cat4 3 ∧ HasLeaves cat4 4 ∧ ¬ HasDepth cat4 2 := by refine ⟨⟨cat4Proto, cat4Proto_computes, le_of_eq cat4Proto_depth_and_leaves.1⟩, ⟨cat4Proto, cat4Proto_computes, le_of_eq cat4Proto_depth_and_leaves.2⟩, ?_⟩ rintro ⟨P, hP, hd⟩ cases P with | leaf z => have h0 : z = 0 := by have := hP 0 0; simpa [Protocol.eval, cat4] using this have h1 : z = 1 := by have := hP 1 0; simpa [Protocol.eval, cat4] using this rw [h0] at h1; cases h1 | bob g L R => simp only [Protocol.depth] at hd have hLd : L.depth ≤ 1 := by omega have hRd : R.depth ≤ 1 := by omega -- Column `c = 1` goes either to `L` (`depth ≤ 1`) or `R` (`depth ≤ 1`), -- yet attains 3 distinct values `{0, 2, 3}` on rows `{0, 1, 2}` (> 2 = 2^1)! cases hg1 : g 1 with | false => have hcard : imageCard cat4 Finset.univ {1} = 3 := by decide have hlb := (imageCard_le_leaves L cat4 Finset.univ {1} (fun x _ y hy => by rw [Finset.mem_singleton.mp hy] have h := hP x 1 simpa [Protocol.eval, hg1] using h)).2 rw [hcard] at hlb have hpow : 2 ^ L.depth ≤ 2 ^ 1 := Nat.pow_le_pow_right (by omega) hLd omega | true => have hcard : imageCard cat4 Finset.univ {1} = 3 := by decide have hlb := (imageCard_le_leaves R cat4 Finset.univ {1} (fun x _ y hy => by rw [Finset.mem_singleton.mp hy] have h := hP x 1 simpa [Protocol.eval, hg1] using h)).2 rw [hcard] at hlb have hpow : 2 ^ R.depth ≤ 2 ^ 1 := Nat.pow_le_pow_right (by omega) hRd omega | alice g L R => simp only [Protocol.depth] at hd have hLd : L.depth ≤ 1 := by omega have hRd : R.depth ≤ 1 := by omega -- Every pair of distinct rows of `cat4` attains 3 distinct outputs (> 2 = 2^1)! have hpair01 : imageCard cat4 {0, 1} Finset.univ = 3 := by decide have hpair02 : imageCard cat4 {0, 2} Finset.univ = 3 := by decide have hpair12 : imageCard cat4 {1, 2} Finset.univ = 3 := by decide have hL2 : 2 ^ L.depth ≤ 2 ^ 1 := Nat.pow_le_pow_right (by omega) hLd have hR2 : 2 ^ R.depth ≤ 2 ^ 1 := Nat.pow_le_pow_right (by omega) hRd -- By pigeonhole among `g 0, g 1, g 2 : Bool`, at least two agree! cases h0 : g 0 <;> cases h1 : g 1 <;> cases h2 : g 2 · -- g0 = g1 = false -> {0, 1} in L have hlb := (imageCard_le_leaves L cat4 {0, 1} Finset.univ (fun x hx y _ => by rcases Finset.mem_insert.mp hx with rfl | hx' · simpa [Protocol.eval, h0] using hP 0 y · rw [Finset.mem_singleton.mp hx']; simpa [Protocol.eval, h1] using hP 1 y)).2 omega · -- g0 = g1 = false -> {0, 1} in L have hlb := (imageCard_le_leaves L cat4 {0, 1} Finset.univ (fun x hx y _ => by rcases Finset.mem_insert.mp hx with rfl | hx' · simpa [Protocol.eval, h0] using hP 0 y · rw [Finset.mem_singleton.mp hx']; simpa [Protocol.eval, h1] using hP 1 y)).2 omega · -- g0 = g2 = false -> {0, 2} in L have hlb := (imageCard_le_leaves L cat4 {0, 2} Finset.univ (fun x hx y _ => by rcases Finset.mem_insert.mp hx with rfl | hx' · simpa [Protocol.eval, h0] using hP 0 y · rw [Finset.mem_singleton.mp hx']; simpa [Protocol.eval, h2] using hP 2 y)).2 omega · -- g1 = g2 = true -> {1, 2} in R have hlb := (imageCard_le_leaves R cat4 {1, 2} Finset.univ (fun x hx y _ => by rcases Finset.mem_insert.mp hx with rfl | hx' · simpa [Protocol.eval, h1] using hP 1 y · rw [Finset.mem_singleton.mp hx']; simpa [Protocol.eval, h2] using hP 2 y)).2 omega · -- g1 = g2 = false -> {1, 2} in L have hlb := (imageCard_le_leaves L cat4 {1, 2} Finset.univ (fun x hx y _ => by rcases Finset.mem_insert.mp hx with rfl | hx' · simpa [Protocol.eval, h1] using hP 1 y · rw [Finset.mem_singleton.mp hx']; simpa [Protocol.eval, h2] using hP 2 y)).2 omega · -- g0 = g2 = true -> {0, 2} in R have hlb := (imageCard_le_leaves R cat4 {0, 2} Finset.univ (fun x hx y _ => by rcases Finset.mem_insert.mp hx with rfl | hx' · simpa [Protocol.eval, h0] using hP 0 y · rw [Finset.mem_singleton.mp hx']; simpa [Protocol.eval, h2] using hP 2 y)).2 omega · -- g0 = g1 = true -> {0, 1} in R have hlb := (imageCard_le_leaves R cat4 {0, 1} Finset.univ (fun x hx y _ => by rcases Finset.mem_insert.mp hx with rfl | hx' · simpa [Protocol.eval, h0] using hP 0 y · rw [Finset.mem_singleton.mp hx']; simpa [Protocol.eval, h1] using hP 1 y)).2 omega · -- g0 = g1 = true -> {0, 1} in R have hlb := (imageCard_le_leaves R cat4 {0, 1} Finset.univ (fun x hx y _ => by rcases Finset.mem_insert.mp hx with rfl | hx' · simpa [Protocol.eval, h0] using hP 0 y · rw [Finset.mem_singleton.mp hx']; simpa [Protocol.eval, h1] using hP 1 y)).2 omega end CommComplexity /-! ## Verification of Standard Foundations Across All Headline Theorems -/ #print axioms CommComplexity.Protocol.leaves_le_two_pow_depth #print axioms CommComplexity.Protocol.trace_rectangle #print axioms CommComplexity.Protocol.output_card_le_leaves #print axioms CommComplexity.supergolden_psi_exists #print axioms CommComplexity.supergoldenCap_ge_psi_pow #print axioms CommComplexity.supergolden_constant_lt_and_beats_classical #print axioms CommComplexity.TreePath.leaves_decomp #print axioms CommComplexity.supergolden_protocol_balancing #print axioms CommComplexity.supergolden_log_balancing_bound #print axioms CommComplexity.telescoping_binomial_direct_sum #print axioms CommComplexity.amortized_direct_sum_log_upper #print axioms CommComplexity.fooling_set_leaves_lb #print axioms CommComplexity.eq_exact_complexity #print axioms CommComplexity.color_rank_sum_leaves_lb #print axioms CommComplexity.directSum_colorMatrix_rank_ge #print axioms CommComplexity.direct_sum_color_rank_sum_lb #print axioms CommComplexity.amortized_sandwich_theorem #print axioms CommComplexity.gt_exact_direct_sum_and_amortized #print axioms CommComplexity.gt_pow2_plus_one_infinite_two_copy_savings #print axioms CommComplexity.gt3_beats_fknn_and_compression_ratio #print axioms CommComplexity.indexing_exact_complexity #print axioms CommComplexity.product_duplication_bobJoin #print axioms CommComplexity.product_duplication_aliceJoin #print axioms CommComplexity.ternary_universal_tree_U3_exact_depth #print axioms CommComplexity.cat4_exact_sharpness