import Mathlib.Algebra.MvPolynomial.Basic import Mathlib.Algebra.MvPolynomial.Degrees import Mathlib.Algebra.MvPolynomial.Monad import Mathlib.Algebra.MvPolynomial.Rename import Mathlib.Algebra.MvPolynomial.Equiv import Mathlib.Algebra.MvPolynomial.SchwartzZippel import Mathlib.Algebra.Polynomial.Roots import Mathlib.Algebra.Order.Field.Basic import Mathlib.Data.Fintype.Perm import Mathlib.Data.Nat.Log /-! # Kabanets–Impagliazzo Hybrid Reconstruction (Lemma 2 of `main.tex`) Formalizes: 1. Over any infinite field `F`, given nonzero `f ∈ MvPolynomial (Fin n) F` with `f.bind₁ G = 0` (where `G i = rename (Φ i) (permPoly F m)` for embeddings `Φ i : Fin m × Fin m ↪ U`), there exist a minimal index `i : Fin n` and an assignment to all variables outside `S_i` and `x_i` yielding a nonzero polynomial `g(y, w) ∈ MvPolynomial ((Fin m × Fin m) ⊕ Unit) F` such that `w - perm_m(y)` divides `g(y, w)` in `MvPolynomial`. 2. Multilinear-restriction monomial count: for `j ≠ i` with `|S_j ∩ S_i| ≤ Δ`, the restricted polynomial `q_j(y)` is multilinear on at most `Δ` variables and has at most `2 ^ Δ` monomials (and `< 2 * n` when `Δ = Nat.clog 2 n` and `n ≥ 1`). 3. Straight-line arithmetic circuit model (`IsValidCircuit`, `Computes`) matching `main.tex` Section 1, and constructive proof that if `Computes s f` and `2 ^ Δ ≤ 2 * n`, then `Computes (s + m ^ 2 + 1 + 2 * n ^ 2 * (Δ + 2)) g`. 4. Full Lemma 2 interface combining the reconstruction with Bürgisser's graph theorem `(I2)` passed as an explicit hypothesis (no custom axioms). -/ namespace PermanentPIT.HybridReconstruction open MvPolynomial Finset /-! ### Section 1: Permanent polynomial and NW generator -/ /-- The `m × m` permanent polynomial over a commutative semiring `R`. -/ noncomputable def permPoly (R : Type*) [CommSemiring R] (m : ℕ) : MvPolynomial (Fin m × Fin m) R := ∑ σ : Equiv.Perm (Fin m), ∏ i : Fin m, MvPolynomial.X (i, σ i) /-- The monomial exponent vector corresponding to a permutation `σ`. -/ noncomputable def permMonomial {m : ℕ} (σ : Equiv.Perm (Fin m)) : (Fin m × Fin m) →₀ ℕ := ∑ i : Fin m, Finsupp.single (i, σ i) 1 theorem prod_X_eq_monomial_permMonomial {R : Type*} [CommSemiring R] {m : ℕ} (σ : Equiv.Perm (Fin m)) : (∏ i : Fin m, (MvPolynomial.X (i, σ i) : MvPolynomial (Fin m × Fin m) R)) = MvPolynomial.monomial (permMonomial σ) 1 := by classical have hgen : ∀ s : Finset (Fin m), (∏ i ∈ s, (MvPolynomial.X (i, σ i) : MvPolynomial (Fin m × Fin m) R)) = MvPolynomial.monomial (∑ i ∈ s, Finsupp.single (i, σ i) 1) 1 := by intro s induction s using Finset.induction_on with | empty => simp | insert a s ha ih => rw [Finset.prod_insert ha, Finset.sum_insert ha, ih, MvPolynomial.X, MvPolynomial.monomial_mul, one_mul] exact hgen Finset.univ theorem permMonomial_apply {m : ℕ} (σ : Equiv.Perm (Fin m)) (p : Fin m × Fin m) : permMonomial σ p = if σ p.1 = p.2 then 1 else 0 := by classical unfold permMonomial rw [Finsupp.finsetSum_apply] rw [Finset.sum_eq_single p.1] · simp [Finsupp.single_apply, Prod.ext_iff] · intro i _ hi have hne : (i, σ i) ≠ p := fun h => hi (congrArg Prod.fst h) simp [hne] · intro hp exact absurd (Finset.mem_univ p.1) hp /-- The NW generator coordinate polynomials `G i = rename (Φ i) (perm_m)`. -/ noncomputable def nwGenerator (R : Type*) [CommSemiring R] {U : Type*} {n m : ℕ} (Φ : Fin n → (Fin m × Fin m ↪ U)) : Fin n → MvPolynomial U R := fun i => MvPolynomial.rename (Φ i) (permPoly R m) /-- The image finset `S_i = range (Φ i)` inside `U`. -/ def designSet {U : Type*} [DecidableEq U] {n m : ℕ} (Φ : Fin n → (Fin m × Fin m ↪ U)) (i : Fin n) : Finset U := Finset.univ.image (Φ i) /-! ### Section 2: Nonvanishing over infinite fields and partial evaluation -/ theorem totalDegree_pow_le {σ R : Type*} [CommSemiring R] (p : MvPolynomial σ R) (k : ℕ) : (p ^ k).totalDegree ≤ k * p.totalDegree := by induction k with | zero => simp | succ k ih => rw [pow_succ, Nat.succ_mul] exact (MvPolynomial.totalDegree_mul (p ^ k) p).trans (Nat.add_le_add_right ih _) theorem totalDegree_rename_le {σ τ R : Type*} [CommSemiring R] (f : σ → τ) (p : MvPolynomial σ R) : (MvPolynomial.rename f p).totalDegree ≤ p.totalDegree := by classical have hbind : MvPolynomial.rename f p = ∑ s ∈ p.support, MvPolynomial.C (p.coeff s) * ∏ i ∈ s.support, (MvPolynomial.X (f i) : MvPolynomial τ R) ^ (s i) := by conv_lhs => rw [p.as_sum] rw [map_sum] refine Finset.sum_congr rfl fun s _ => ?_ rw [MvPolynomial.monomial_eq, map_mul, MvPolynomial.rename_C, Finsupp.prod, map_prod] congr 1 refine Finset.prod_congr rfl fun i _ => ?_ rw [map_pow, MvPolynomial.rename_X] rw [hbind] refine (MvPolynomial.totalDegree_finsetSum _ _).trans ?_ rw [Finset.sup_le_iff] intro s hs have hX : ∀ i : σ, ((MvPolynomial.X (f i) : MvPolynomial τ R)).totalDegree ≤ 1 := fun i => by rw [MvPolynomial.X] exact (MvPolynomial.totalDegree_monomial_le (Finsupp.single (f i) 1) (1 : R)).trans (by simp) have hterm : (MvPolynomial.C (p.coeff s) * ∏ i ∈ s.support, (MvPolynomial.X (f i) : MvPolynomial τ R) ^ (s i)).totalDegree ≤ s.sum fun _ e => e := by calc (MvPolynomial.C (p.coeff s) * ∏ i ∈ s.support, (MvPolynomial.X (f i) : MvPolynomial τ R) ^ (s i)).totalDegree ≤ (MvPolynomial.C (p.coeff s) : MvPolynomial τ R).totalDegree + (∏ i ∈ s.support, (MvPolynomial.X (f i) : MvPolynomial τ R) ^ (s i)).totalDegree := MvPolynomial.totalDegree_mul _ _ _ = (∏ i ∈ s.support, (MvPolynomial.X (f i) : MvPolynomial τ R) ^ (s i)).totalDegree := by simp _ ≤ ∑ i ∈ s.support, ((MvPolynomial.X (f i) : MvPolynomial τ R) ^ (s i)).totalDegree := MvPolynomial.totalDegree_finsetProd _ _ _ ≤ ∑ i ∈ s.support, s i * (MvPolynomial.X (f i) : MvPolynomial τ R).totalDegree := Finset.sum_le_sum fun i _ => totalDegree_pow_le _ _ _ ≤ ∑ i ∈ s.support, s i * 1 := Finset.sum_le_sum fun i _ => Nat.mul_le_mul_left (s i) (hX i) _ = s.sum fun _ e => e := by simp [Finsupp.sum] exact hterm.trans (Finset.le_sup (f := fun s : σ →₀ ℕ => s.sum fun _ e => e) hs) /-- Any nonzero multivariate polynomial over an infinite field has a nonvanishing evaluation. -/ theorem exists_eval_ne_zero_of_infinite {F U : Type*} [Field F] [Infinite F] [Fintype U] [DecidableEq U] (p : MvPolynomial U F) (hp : p ≠ 0) : ∃ z : U → F, MvPolynomial.eval z p ≠ 0 := by classical let S : Finset F := (Finset.range (p.totalDegree + 1)).image (Infinite.natEmbedding F) have hScard : S.card = p.totalDegree + 1 := by rw [Finset.card_image_of_injective _ (Infinite.natEmbedding F).injective, Finset.card_range] let e : U ≃ Fin (Fintype.card U) := Fintype.equivFin U let q : MvPolynomial (Fin (Fintype.card U)) F := MvPolynomial.rename e p have hq_ne : q ≠ 0 := by intro hq apply hp exact MvPolynomial.rename_injective e e.injective (by simpa [q] using hq) have hq_deg : q.totalDegree < S.card := by rw [hScard] exact Nat.lt_succ_of_le (totalDegree_rename_le e p) have hfin : ∃ w ∈ Fintype.piFinset (fun _ : Fin (Fintype.card U) => S), MvPolynomial.eval w q ≠ 0 := by by_contra h push Not at h have hfilter : (Fintype.piFinset (fun _ : Fin (Fintype.card U) => S)).filter (fun w => MvPolynomial.eval w q = 0) = Fintype.piFinset (fun _ : Fin (Fintype.card U) => S) := Finset.filter_eq_self.mpr h have hne : ((S.card : ℚ≥0) ^ Fintype.card U) ≠ 0 := pow_ne_zero _ (by exact_mod_cast (Nat.ne_of_gt (Nat.zero_lt_of_lt hq_deg))) have hsz := MvPolynomial.schwartz_zippel_totalDegree hq_ne S have hleft : (1 : ℚ≥0) ≤ (q.totalDegree : ℚ≥0) / (S.card : ℚ≥0) := by simpa [hfilter, Fintype.card_piFinset_const, hne] using hsz have hcast : (q.totalDegree : ℚ≥0) < (S.card : ℚ≥0) := by exact_mod_cast hq_deg have hpos : (0 : ℚ≥0) < (S.card : ℚ≥0) := by exact_mod_cast (Nat.zero_lt_of_lt hq_deg) exact (not_lt_of_ge hleft) ((div_lt_one hpos).2 hcast) rcases hfin with ⟨w, _, heval⟩ exact ⟨w ∘ e, by simpa [q, MvPolynomial.eval_rename] using heval⟩ /-- Partial evaluation of a nonzero polynomial in `A ⊕ B` over an infinite field: there exists an assignment `β : B → F` leaving a nonzero polynomial in `A`. -/ theorem exists_partial_eval_ne_zero {F A B : Type*} [Field F] [Infinite F] [Fintype B] [DecidableEq B] (p : MvPolynomial (A ⊕ B) F) (hp : p ≠ 0) : ∃ β : B → F, MvPolynomial.bind₁ (Sum.elim MvPolynomial.X (fun b => MvPolynomial.C (β b))) p ≠ 0 := by classical let e : MvPolynomial (A ⊕ B) F ≃+* MvPolynomial A (MvPolynomial B F) := MvPolynomial.sumRingEquiv F A B have hq_ne : e p ≠ 0 := fun h => hp (e.injective (by simpa using h)) have hex : ∃ μ : A →₀ ℕ, (e p).coeff μ ≠ 0 := by by_contra hall push Not at hall apply hq_ne apply MvPolynomial.ext intro μ simpa using hall μ rcases hex with ⟨μ, hμ⟩ obtain ⟨β, hβ⟩ := exists_eval_ne_zero_of_infinite ((e p).coeff μ) hμ refine ⟨β, ?_⟩ have hmap : ∀ q : MvPolynomial (A ⊕ B) F, MvPolynomial.map (MvPolynomial.eval β) (e q) = MvPolynomial.bind₁ (Sum.elim MvPolynomial.X (fun b => MvPolynomial.C (β b))) q := by intro q induction q using MvPolynomial.induction_on with | C a => simp [e, MvPolynomial.sumRingEquiv_C] | add p₁ p₂ hp₁ hp₂ => rw [map_add, map_add, map_add, hp₁, hp₂] | mul_X p₁ v hp₁ => cases v with | inl a => rw [map_mul, map_mul, map_mul, hp₁] simp [e, MvPolynomial.sumRingEquiv_X_inl] | inr b => rw [map_mul, map_mul, map_mul, hp₁] simp [e, MvPolynomial.sumRingEquiv_X_inr] intro hzero have hcoeff : (MvPolynomial.map (MvPolynomial.eval β) (e p)).coeff μ = 0 := by rw [hmap p, hzero, MvPolynomial.coeff_zero] rw [MvPolynomial.coeff_map] at hcoeff exact hβ hcoeff /-! ### Section 3: Divisibility by `w - φ(y)` in `MvPolynomial` -/ /-- Equivalence `(σ ⊕ Unit) ≃ Option σ`. -/ def sumUnitEquivOption (σ : Type*) : σ ⊕ Unit ≃ Option σ where toFun | Sum.inl x => some x | Sum.inr () => none invFun | some x => Sum.inl x | none => Sum.inr () left_inv | Sum.inl _ => rfl | Sum.inr () => rfl right_inv | some _ => rfl | none => rfl /-- Algebra equivalence `MvPolynomial (σ ⊕ Unit) R ≃ₐ[R] Polynomial (MvPolynomial σ R)` treating `Sum.inr ()` as the univariate indeterminate `w`. -/ noncomputable def splitLastEquiv (R σ : Type*) [CommSemiring R] : MvPolynomial (σ ⊕ Unit) R ≃ₐ[R] Polynomial (MvPolynomial σ R) := (MvPolynomial.renameEquiv R (sumUnitEquivOption σ)).trans (MvPolynomial.optionEquivLeft R σ) theorem splitLastEquiv_X_inl {R σ : Type*} [CommSemiring R] (x : σ) : splitLastEquiv R σ (MvPolynomial.X (Sum.inl x)) = Polynomial.C (MvPolynomial.X x) := by simp [splitLastEquiv, sumUnitEquivOption] theorem splitLastEquiv_X_inr {R σ : Type*} [CommSemiring R] : splitLastEquiv R σ (MvPolynomial.X (Sum.inr ())) = Polynomial.X := by simp [splitLastEquiv, sumUnitEquivOption] theorem splitLastEquiv_rename_inl {R σ : Type*} [CommSemiring R] (φ : MvPolynomial σ R) : splitLastEquiv R σ (MvPolynomial.rename Sum.inl φ) = Polynomial.C φ := by induction φ using MvPolynomial.induction_on with | C a => simp [splitLastEquiv, sumUnitEquivOption] | add p q hp hq => simp [map_add, hp, hq] | mul_X p x hp => simp [map_mul, hp, splitLastEquiv_X_inl] theorem eval_splitLastEquiv {R σ : Type*} [CommSemiring R] (φ : MvPolynomial σ R) (g : MvPolynomial (σ ⊕ Unit) R) : Polynomial.eval φ (splitLastEquiv R σ g) = MvPolynomial.bind₁ (Sum.elim MvPolynomial.X (fun _ => φ)) g := by induction g using MvPolynomial.induction_on with | C a => simp [splitLastEquiv, sumUnitEquivOption] | add p q hp hq => simp [map_add, Polynomial.eval_add, hp, hq] | mul_X p v hp => cases v with | inl x => simp [map_mul, Polynomial.eval_mul, splitLastEquiv_X_inl, hp] | inr u => cases u simp [map_mul, Polynomial.eval_mul, splitLastEquiv_X_inr, hp] /-- **Factor divisibility by `w - φ(y)`.** If `g(y, w)` vanishes upon substituting `w ↦ φ(y)`, then `w - φ(y)` divides `g(y, w)` in `MvPolynomial (σ ⊕ Unit) R`. -/ theorem dvd_of_bind₁_eq_zero {R σ : Type*} [CommRing R] (φ : MvPolynomial σ R) (g : MvPolynomial (σ ⊕ Unit) R) (hvanish : MvPolynomial.bind₁ (Sum.elim MvPolynomial.X (fun _ => φ)) g = 0) : (MvPolynomial.X (Sum.inr ()) - MvPolynomial.rename Sum.inl φ) ∣ g := by let e := splitLastEquiv R σ have hroot : (e g).IsRoot φ := by rw [Polynomial.IsRoot, eval_splitLastEquiv, hvanish] obtain ⟨q, hq⟩ := Polynomial.dvd_iff_isRoot.mpr hroot refine ⟨e.symm q, ?_⟩ apply e.injective rw [map_mul, map_sub, splitLastEquiv_X_inr, splitLastEquiv_rename_inl, e.apply_symm_apply] exact hq /-! ### Section 4: Hybrid argument -/ /-- The `k`-th hybrid substitution: the first `k` coordinates use `G j` (in `U`), and the remaining coordinates remain independent variables `x_j` (in `Fin n`). -/ noncomputable def hybridSubst {R U : Type*} [CommSemiring R] {n : ℕ} (G : Fin n → MvPolynomial U R) (k : ℕ) : Fin n → MvPolynomial (U ⊕ Fin n) R := fun j => if (j : ℕ) < k then MvPolynomial.rename Sum.inl (G j) else MvPolynomial.X (Sum.inr j) /-- The `k`-th hybrid polynomial `f_k = f(G_0(z), ..., G_{k-1}(z), x_k, ..., x_{n-1})`. -/ noncomputable def hybridPoly {R U : Type*} [CommSemiring R] {n : ℕ} (G : Fin n → MvPolynomial U R) (f : MvPolynomial (Fin n) R) (k : ℕ) : MvPolynomial (U ⊕ Fin n) R := MvPolynomial.bind₁ (hybridSubst G k) f theorem hybridPoly_zero {R U : Type*} [CommSemiring R] {n : ℕ} (G : Fin n → MvPolynomial U R) (f : MvPolynomial (Fin n) R) : hybridPoly G f 0 = MvPolynomial.rename Sum.inr f := by have hsub : hybridSubst G 0 = fun j => MvPolynomial.X (Sum.inr j) := by funext j; simp [hybridSubst] rw [hybridPoly, hsub] induction f using MvPolynomial.induction_on with | C a => simp | add p q hp hq => rw [map_add, map_add, hp, hq] | mul_X p j hp => rw [map_mul, map_mul, hp, MvPolynomial.bind₁_X_right, MvPolynomial.rename_X] theorem hybridPoly_n {R U : Type*} [CommSemiring R] {n : ℕ} (G : Fin n → MvPolynomial U R) (f : MvPolynomial (Fin n) R) : hybridPoly G f n = MvPolynomial.rename Sum.inl (MvPolynomial.bind₁ G f) := by have hsub : hybridSubst G n = fun j => MvPolynomial.rename Sum.inl (G j) := by funext j; simp [hybridSubst, j.isLt] rw [hybridPoly, hsub] induction f using MvPolynomial.induction_on with | C a => simp | add p q hp hq => rw [map_add, map_add, map_add, hp, hq] | mul_X p j hp => rw [map_mul, map_mul, map_mul, hp, MvPolynomial.bind₁_X_right, MvPolynomial.bind₁_X_right] /-- Existence of a minimal vanishing hybrid index `i < n`: `f_k ≠ 0` for all `k ≤ i`, and `f_{i+1} = 0`. -/ theorem exists_minimal_hybrid_index {R U : Type*} [CommSemiring R] {n : ℕ} (G : Fin n → MvPolynomial U R) (f : MvPolynomial (Fin n) R) (hf : f ≠ 0) (hvanish : MvPolynomial.bind₁ G f = 0) : ∃ i : Fin n, (∀ k ≤ (i : ℕ), hybridPoly G f k ≠ 0) ∧ hybridPoly G f ((i : ℕ) + 1) = 0 := by classical have hex : ∃ k : ℕ, hybridPoly G f k = 0 := ⟨n, by rw [hybridPoly_n, hvanish, map_zero]⟩ let k₀ := Nat.find hex have hk₀_zero : hybridPoly G f k₀ = 0 := Nat.find_spec hex have hk₀_pos : 0 < k₀ := by by_contra h have hk0 : k₀ = 0 := by omega rw [hk0, hybridPoly_zero] at hk₀_zero exact hf (MvPolynomial.rename_injective Sum.inr Sum.inr_injective (by simpa using hk₀_zero)) have hk₀_le : k₀ ≤ n := Nat.find_min' hex (by rw [hybridPoly_n, hvanish, map_zero]) refine ⟨⟨k₀ - 1, by omega⟩, ?_, ?_⟩ · intro k hk dsimp only at hk exact Nat.find_min hex (by omega) · have hsucc : k₀ - 1 + 1 = k₀ := by omega simpa [hsucc] using hk₀_zero /-- Variables fixed (set to field constants) during the restriction at index `i`. -/ def FixedVars (U : Type*) {n m : ℕ} (Φ : Fin n → (Fin m × Fin m ↪ U)) (i : Fin n) : Type _ := {v : U ⊕ Fin n // match v with | Sum.inl u => u ∉ Set.range (Φ i) | Sum.inr j => j ≠ i} /-- Equivalence splitting `U ⊕ Fin n` into kept variables `(Fin m × Fin m) ⊕ Unit` (`y = z|_{S_i}` and `w = x_i`) and fixed variables `FixedVars U Φ i`. -/ noncomputable def splitVarEquiv {U : Type*} {n m : ℕ} (Φ : Fin n → (Fin m × Fin m ↪ U)) (i : Fin n) : ((Fin m × Fin m) ⊕ Unit) ⊕ FixedVars U Φ i ≃ U ⊕ Fin n := by classical refine { toFun := fun x => match x with | Sum.inl (Sum.inl p) => Sum.inl (Φ i p) | Sum.inl (Sum.inr ()) => Sum.inr i | Sum.inr v => v.1 invFun := fun v => match v with | Sum.inl u => if h : u ∈ Set.range (Φ i) then Sum.inl (Sum.inl (Classical.choose h)) else Sum.inr ⟨Sum.inl u, h⟩ | Sum.inr j => if h : j = i then Sum.inl (Sum.inr ()) else Sum.inr ⟨Sum.inr j, h⟩ left_inv := ?_ right_inv := ?_ } · intro x rcases x with (p | ⟨⟩) | ⟨v, hv⟩ · have h : Φ i p ∈ Set.range (Φ i) := ⟨p, rfl⟩ simp only [h, ↓reduceDIte] have hchoose : Φ i (Classical.choose h) = Φ i p := Classical.choose_spec h rw [(Φ i).injective hchoose] · simp · cases v with | inl u => simp only [hv, ↓reduceDIte] | inr j => simp only [hv, ↓reduceDIte] · intro v cases v with | inl u => by_cases h : u ∈ Set.range (Φ i) · simp only [h, ↓reduceDIte] exact congrArg Sum.inl (Classical.choose_spec h) · simp [h] | inr j => by_cases h : j = i · subst h; simp · simp [h] /-- Substitution restricting `U ⊕ Fin n` to `((Fin m × Fin m) ⊕ Unit)` by fixing all variables outside `S_i ∪ {x_i}` according to `β : FixedVars U Φ i → F`. -/ noncomputable def restrictSubst {F U : Type*} [CommSemiring F] {n m : ℕ} (Φ : Fin n → (Fin m × Fin m ↪ U)) (i : Fin n) (β : FixedVars U Φ i → F) : U ⊕ Fin n → MvPolynomial ((Fin m × Fin m) ⊕ Unit) F := fun v => match (splitVarEquiv Φ i).symm v with | Sum.inl y => MvPolynomial.X y | Sum.inr b => MvPolynomial.C (β b) theorem restrictSubst_inl_mem {F U : Type*} [CommSemiring F] {n m : ℕ} (Φ : Fin n → (Fin m × Fin m ↪ U)) (i : Fin n) (β : FixedVars U Φ i → F) (p : Fin m × Fin m) : restrictSubst Φ i β (Sum.inl (Φ i p)) = MvPolynomial.X (Sum.inl p) := by unfold restrictSubst have h : (splitVarEquiv Φ i).symm (Sum.inl (Φ i p)) = Sum.inl (Sum.inl p) := by apply (splitVarEquiv Φ i).injective simp [splitVarEquiv] rw [h] theorem restrictSubst_inl_not_mem {F U : Type*} [CommSemiring F] {n m : ℕ} (Φ : Fin n → (Fin m × Fin m ↪ U)) (i : Fin n) (β : FixedVars U Φ i → F) (u : U) (hu : u ∉ Set.range (Φ i)) : restrictSubst Φ i β (Sum.inl u) = MvPolynomial.C (β ⟨Sum.inl u, hu⟩) := by unfold restrictSubst have h : (splitVarEquiv Φ i).symm (Sum.inl u) = Sum.inr ⟨Sum.inl u, hu⟩ := by apply (splitVarEquiv Φ i).injective simp [splitVarEquiv, hu] rw [h] theorem restrictSubst_inr_self {F U : Type*} [CommSemiring F] {n m : ℕ} (Φ : Fin n → (Fin m × Fin m ↪ U)) (i : Fin n) (β : FixedVars U Φ i → F) : restrictSubst Φ i β (Sum.inr i) = MvPolynomial.X (Sum.inr ()) := by unfold restrictSubst have h : (splitVarEquiv Φ i).symm (Sum.inr i) = Sum.inl (Sum.inr ()) := by apply (splitVarEquiv Φ i).injective simp [splitVarEquiv] rw [h] theorem restrictSubst_inr_ne {F U : Type*} [CommSemiring F] {n m : ℕ} (Φ : Fin n → (Fin m × Fin m ↪ U)) (i : Fin n) (β : FixedVars U Φ i → F) (j : Fin n) (hji : j ≠ i) : restrictSubst Φ i β (Sum.inr j) = MvPolynomial.C (β ⟨Sum.inr j, hji⟩) := by unfold restrictSubst have h : (splitVarEquiv Φ i).symm (Sum.inr j) = Sum.inr ⟨Sum.inr j, hji⟩ := by apply (splitVarEquiv Φ i).injective simp [splitVarEquiv, hji] rw [h] /-- Key algebraic identity: substituting `w ↦ perm_m(y)` into the restricted `i`-th hybrid gives the restricted `(i + 1)`-st hybrid evaluated at `w ↦ perm_m(y)`. -/ theorem bind₁_evalW_restrict_hybrid {F U : Type*} [CommSemiring F] {n m : ℕ} (Φ : Fin n → (Fin m × Fin m ↪ U)) (i : Fin n) (β : FixedVars U Φ i → F) (f : MvPolynomial (Fin n) F) : MvPolynomial.bind₁ (Sum.elim MvPolynomial.X (fun _ => permPoly F m)) (MvPolynomial.bind₁ (restrictSubst Φ i β) (hybridPoly (nwGenerator F Φ) f (i : ℕ))) = MvPolynomial.bind₁ (Sum.elim MvPolynomial.X (fun _ => permPoly F m)) (MvPolynomial.bind₁ (restrictSubst Φ i β) (hybridPoly (nwGenerator F Φ) f ((i : ℕ) + 1))) := by let evalW : ((Fin m × Fin m) ⊕ Unit) → MvPolynomial (Fin m × Fin m) F := Sum.elim MvPolynomial.X (fun _ => permPoly F m) let σ : U ⊕ Fin n → MvPolynomial (Fin m × Fin m) F := fun v => MvPolynomial.bind₁ evalW (restrictSubst Φ i β v) have hcomp : ∀ P : MvPolynomial (U ⊕ Fin n) F, MvPolynomial.bind₁ evalW (MvPolynomial.bind₁ (restrictSubst Φ i β) P) = MvPolynomial.bind₁ σ P := by intro P induction P using MvPolynomial.induction_on with | C a => simp | add p q hp hq => simp [map_add, hp, hq] | mul_X p v hp => simp [map_mul, hp, σ] rw [hcomp, hcomp] unfold hybridPoly have hcomp2 : ∀ (s : Fin n → MvPolynomial (U ⊕ Fin n) F) (P : MvPolynomial (Fin n) F), MvPolynomial.bind₁ σ (MvPolynomial.bind₁ s P) = MvPolynomial.bind₁ (fun j => MvPolynomial.bind₁ σ (s j)) P := by intro s P induction P using MvPolynomial.induction_on with | C a => simp | add p q hp hq => simp [map_add, hp, hq] | mul_X p j hp => simp [map_mul, hp] rw [hcomp2, hcomp2] refine congrArg (fun g => MvPolynomial.bind₁ g f) (funext fun j => ?_) unfold hybridSubst by_cases hlt : (j : ℕ) < (i : ℕ) · have hlt' : (j : ℕ) < (i : ℕ) + 1 := Nat.lt_succ_of_lt hlt simp [hlt, hlt'] · by_cases heq : (j : ℕ) = (i : ℕ) · have hji : j = i := Fin.ext heq subst hji have hlt' : (j : ℕ) < (j : ℕ) + 1 := Nat.lt_succ_self _ simp only [hlt, ↓reduceIte, hlt'] rw [MvPolynomial.bind₁_X_right] have hlhs : σ (Sum.inr j) = permPoly F m := by simp [σ, restrictSubst_inr_self, evalW] rw [hlhs] unfold nwGenerator have hrhs : ∀ q : MvPolynomial (Fin m × Fin m) F, MvPolynomial.bind₁ σ (MvPolynomial.rename Sum.inl (MvPolynomial.rename (Φ j) q)) = q := by intro q induction q using MvPolynomial.induction_on with | C a => simp | add p₁ p₂ hp₁ hp₂ => rw [map_add, map_add, map_add, hp₁, hp₂] | mul_X p₁ p hp₁ => rw [map_mul, map_mul, map_mul, hp₁, MvPolynomial.rename_X, MvPolynomial.rename_X, MvPolynomial.bind₁_X_right] simp [σ, restrictSubst_inl_mem, evalW] exact (hrhs (permPoly F m)).symm · have hlt' : ¬ ((j : ℕ) < (i : ℕ) + 1) := by omega simp [hlt, hlt'] /-- **Kabanets–Impagliazzo Hybrid Reconstruction (Divisibility Part of Lemma 2).** Over any infinite field `F`, if `f ≠ 0` and `f.bind₁ (nwGenerator F Φ) = 0`, then there exist a minimal index `i : Fin n` and an assignment `β : FixedVars U Φ i → F` such that the restricted polynomial `g(y, w) = bind₁ (restrictSubst Φ i β) (hybridPoly G f i)` is nonzero and divisible by `w - perm_m(y)`. -/ theorem hybrid_reconstruction_dvd {F U : Type*} [Field F] [Infinite F] [Fintype U] [DecidableEq U] {n m : ℕ} (Φ : Fin n → (Fin m × Fin m ↪ U)) (f : MvPolynomial (Fin n) F) (hf : f ≠ 0) (hvanish : MvPolynomial.bind₁ (nwGenerator F Φ) f = 0) : ∃ (i : Fin n) (β : FixedVars U Φ i → F), (∀ k ≤ (i : ℕ), hybridPoly (nwGenerator F Φ) f k ≠ 0) ∧ hybridPoly (nwGenerator F Φ) f ((i : ℕ) + 1) = 0 ∧ let g := MvPolynomial.bind₁ (restrictSubst Φ i β) (hybridPoly (nwGenerator F Φ) f (i : ℕ)) g ≠ 0 ∧ (MvPolynomial.X (Sum.inr ()) - MvPolynomial.rename Sum.inl (permPoly F m)) ∣ g := by classical obtain ⟨i, hmin, hzero⟩ := exists_minimal_hybrid_index (nwGenerator F Φ) f hf hvanish have hi_ne : hybridPoly (nwGenerator F Φ) f (i : ℕ) ≠ 0 := hmin (i : ℕ) le_rfl let P : MvPolynomial (((Fin m × Fin m) ⊕ Unit) ⊕ FixedVars U Φ i) F := MvPolynomial.rename (splitVarEquiv Φ i).symm (hybridPoly (nwGenerator F Φ) f (i : ℕ)) have hP_ne : P ≠ 0 := by intro hP apply hi_ne exact MvPolynomial.rename_injective _ (splitVarEquiv Φ i).symm.injective (by simpa [P] using hP) have : Fintype (FixedVars U Φ i) := Subtype.fintype _ obtain ⟨β, hβ⟩ := exists_partial_eval_ne_zero P hP_ne have hbind_eq : MvPolynomial.bind₁ (Sum.elim MvPolynomial.X (fun b => MvPolynomial.C (β b))) P = MvPolynomial.bind₁ (restrictSubst Φ i β) (hybridPoly (nwGenerator F Φ) f (i : ℕ)) := by dsimp only [P] induction hybridPoly (nwGenerator F Φ) f (i : ℕ) using MvPolynomial.induction_on with | C a => simp | add p q hp hq => simp [map_add, hp, hq] | mul_X p v hp => simp only [map_mul, MvPolynomial.rename_X, MvPolynomial.bind₁_X_right, hp] congr 1 unfold restrictSubst cases (splitVarEquiv Φ i).symm v <;> rfl refine ⟨i, β, hmin, hzero, ?_, ?_⟩ · simpa [hbind_eq] using hβ · apply dvd_of_bind₁_eq_zero rw [bind₁_evalW_restrict_hybrid Φ i β f, hzero, map_zero, map_zero] /-! ### Section 5: Multilinear polynomials and `≤ 2^Δ` monomial count -/ /-- A polynomial is multilinear if every variable has exponent at most `1` in every monomial in its support. -/ def IsMultilinear {σ R : Type*} [CommSemiring R] (p : MvPolynomial σ R) : Prop := ∀ μ ∈ p.support, ∀ x, μ x ≤ 1 /-- Every permutation polynomial `permPoly R m` is multilinear. -/ theorem permPoly_isMultilinear {R : Type*} [CommSemiring R] (m : ℕ) : IsMultilinear (permPoly R m) := by classical intro μ hμ x rw [MvPolynomial.mem_support_iff] at hμ unfold permPoly at hμ rw [MvPolynomial.coeff_sum] at hμ have hex : ∃ σ ∈ (Finset.univ : Finset (Equiv.Perm (Fin m))), (∏ i : Fin m, (MvPolynomial.X (i, σ i) : MvPolynomial (Fin m × Fin m) R)).coeff μ ≠ 0 := by by_contra h push Not at h exact hμ (Finset.sum_eq_zero h) rcases hex with ⟨σ, _, hσ⟩ rw [prod_X_eq_monomial_permMonomial, MvPolynomial.coeff_monomial] at hσ have heq : permMonomial σ = μ := by by_contra hne simp [hne] at hσ rw [← heq, permMonomial_apply] split_ifs <;> omega /-- If `p` is multilinear and every monomial in `p.support` has support contained in `T`, then `p` has at most `2 ^ T.card` monomials. -/ theorem support_card_le_two_pow_of_isMultilinear {σ R : Type*} [CommSemiring R] [DecidableEq σ] {p : MvPolynomial σ R} {T : Finset σ} (hml : IsMultilinear p) (hsub : ∀ μ ∈ p.support, μ.support ⊆ T) : p.support.card ≤ 2 ^ T.card := by classical have hinj : Set.InjOn (fun μ : σ →₀ ℕ => μ.support) (p.support : Set (σ →₀ ℕ)) := by intro μ₁ hμ₁ μ₂ hμ₂ heq rw [Finset.mem_coe] at hμ₁ hμ₂ ext x have h1 := hml μ₁ hμ₁ x have h2 := hml μ₂ hμ₂ x dsimp only at heq have hiff : x ∈ μ₁.support ↔ x ∈ μ₂.support := by rw [heq] rw [Finsupp.mem_support_iff, Finsupp.mem_support_iff] at hiff omega have himg : p.support.image (fun μ : σ →₀ ℕ => μ.support) ⊆ T.powerset := by intro s hs rcases Finset.mem_image.mp hs with ⟨μ, hμ, rfl⟩ exact Finset.mem_powerset.mpr (hsub μ hμ) calc p.support.card = (p.support.image (fun μ : σ →₀ ℕ => μ.support)).card := (Finset.card_image_of_injOn hinj).symm _ ≤ T.powerset.card := Finset.card_le_card himg _ = 2 ^ T.card := Finset.card_powerset T /-- The set of `y`-variables kept alive in `G j` when restricting to `S_i`. -/ def overlapVars {U : Type*} [DecidableEq U] {n m : ℕ} (Φ : Fin n → (Fin m × Fin m ↪ U)) (i j : Fin n) : Finset ((Fin m × Fin m) ⊕ Unit) := (Finset.univ.filter fun p : Fin m × Fin m => Φ i p ∈ designSet Φ j).image Sum.inl /-- The number of overlapping `y`-variables equals `|S_j ∩ S_i|`. -/ theorem overlapVars_card {U : Type*} [DecidableEq U] {n m : ℕ} (Φ : Fin n → (Fin m × Fin m ↪ U)) (i j : Fin n) : (overlapVars Φ i j).card = (designSet Φ j ∩ designSet Φ i).card := by classical unfold overlapVars rw [Finset.card_image_of_injective _ Sum.inl_injective] have himg : (Finset.univ.filter fun p : Fin m × Fin m => Φ i p ∈ designSet Φ j).image (Φ i) = designSet Φ j ∩ designSet Φ i := by ext u simp only [Finset.mem_image, Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_inter, designSet] constructor · rintro ⟨p, ⟨q, hq⟩, rfl⟩ exact ⟨⟨q, hq⟩, ⟨p, rfl⟩⟩ · rintro ⟨⟨q, hq⟩, ⟨p, rfl⟩⟩ exact ⟨p, ⟨q, hq⟩, rfl⟩ rw [← himg, Finset.card_image_of_injective _ (Φ i).injective] /-- The restricted polynomial `q_j(y) = bind₁ (restrictSubst Φ i β) (rename Sum.inl (G j))`. -/ noncomputable def restrictedCoord {F U : Type*} [CommSemiring F] {n m : ℕ} (Φ : Fin n → (Fin m × Fin m ↪ U)) (i : Fin n) (β : FixedVars U Φ i → F) (j : Fin n) : MvPolynomial ((Fin m × Fin m) ⊕ Unit) F := MvPolynomial.bind₁ (restrictSubst Φ i β) (MvPolynomial.rename Sum.inl (nwGenerator F Φ j)) /-- Each restricted coordinate `q_j` is multilinear and supported on `overlapVars Φ i j`. -/ theorem restrictedCoord_multilinear_and_support {F U : Type*} [CommSemiring F] [DecidableEq U] {n m : ℕ} (Φ : Fin n → (Fin m × Fin m ↪ U)) (i : Fin n) (β : FixedVars U Φ i → F) (j : Fin n) : IsMultilinear (restrictedCoord Φ i β j) ∧ ∀ μ ∈ (restrictedCoord Φ i β j).support, μ.support ⊆ overlapVars Φ i j := by classical -- Express `restrictedCoord` as a sum over permutations `σ` have hexpr : restrictedCoord Φ i β j = ∑ σ : Equiv.Perm (Fin m), ∏ r : Fin m, restrictSubst Φ i β (Sum.inl (Φ j (r, σ r))) := by unfold restrictedCoord nwGenerator permPoly rw [map_sum, map_sum, map_sum] refine Finset.sum_congr rfl fun σ _ => ?_ rw [map_prod, map_prod, map_prod] refine Finset.prod_congr rfl fun r _ => ?_ simp -- For each permutation `σ`, the product is `C c * ∏ v ∈ s_σ, X v` for a subset `s_σ ⊆ overlapVars` have hterm : ∀ σ : Equiv.Perm (Fin m), ∃ (c : F) (s : Finset ((Fin m × Fin m) ⊕ Unit)), s ⊆ overlapVars Φ i j ∧ (∏ r : Fin m, restrictSubst Φ i β (Sum.inl (Φ j (r, σ r)))) = MvPolynomial.monomial (∑ v ∈ s, Finsupp.single v 1) c := by intro σ let keep : Finset (Fin m) := Finset.univ.filter fun r => Φ j (r, σ r) ∈ Set.range (Φ i) let drop : Finset (Fin m) := Finset.univ.filter fun r => Φ j (r, σ r) ∉ Set.range (Φ i) have hsplit : (∏ r : Fin m, restrictSubst Φ i β (Sum.inl (Φ j (r, σ r)))) = (∏ r ∈ drop, restrictSubst Φ i β (Sum.inl (Φ j (r, σ r)))) * (∏ r ∈ keep, restrictSubst Φ i β (Sum.inl (Φ j (r, σ r)))) := by rw [mul_comm] exact (Finset.prod_filter_mul_prod_filter_not Finset.univ (fun r => Φ j (r, σ r) ∈ Set.range (Φ i)) (fun r => restrictSubst Φ i β (Sum.inl (Φ j (r, σ r))))).symm have hdrop : ∃ c : F, (∏ r ∈ drop, restrictSubst Φ i β (Sum.inl (Φ j (r, σ r)))) = MvPolynomial.C c := by have : ∀ t : Finset (Fin m), (∀ r ∈ t, Φ j (r, σ r) ∉ Set.range (Φ i)) → ∃ c : F, (∏ r ∈ t, restrictSubst Φ i β (Sum.inl (Φ j (r, σ r)))) = MvPolynomial.C c := by intro t ht induction t using Finset.induction_on with | empty => exact ⟨1, by simp⟩ | insert a t ha ih => obtain ⟨c, hc⟩ := ih (fun r hr => ht r (Finset.mem_insert_of_mem hr)) have ha' := ht a (Finset.mem_insert_self a t) refine ⟨β ⟨Sum.inl (Φ j (a, σ a)), ha'⟩ * c, ?_⟩ rw [Finset.prod_insert ha, restrictSubst_inl_not_mem Φ i β _ ha', hc, map_mul] exact this drop (fun r hr => (Finset.mem_filter.mp hr).2) -- Map each `r ∈ keep` to its unique `Sum.inl p ∈ overlapVars Φ i j` let f : Fin m → (Fin m × Fin m) ⊕ Unit := fun r => if h : Φ j (r, σ r) ∈ Set.range (Φ i) then Sum.inl (Classical.choose h) else Sum.inr () have hf_inj : Set.InjOn f (keep : Set (Fin m)) := by intro r₁ hr₁ r₂ hr₂ heq rw [Finset.mem_coe, Finset.mem_filter] at hr₁ hr₂ simp only [f, hr₁.2, hr₂.2, ↓reduceDIte] at heq have hp : Classical.choose hr₁.2 = Classical.choose hr₂.2 := Sum.inl.inj heq have hu : Φ j (r₁, σ r₁) = Φ j (r₂, σ r₂) := by rw [← Classical.choose_spec hr₁.2, ← Classical.choose_spec hr₂.2, hp] exact (Prod.mk.inj ((Φ j).injective hu)).1 have hf_sub : keep.image f ⊆ overlapVars Φ i j := by intro v hv rcases Finset.mem_image.mp hv with ⟨r, hr, rfl⟩ have hr' := (Finset.mem_filter.mp hr).2 simp only [f, hr', ↓reduceDIte, overlapVars, Finset.mem_image, Finset.mem_filter, Finset.mem_univ, true_and] refine ⟨Classical.choose hr', ?_, rfl⟩ rw [Classical.choose_spec hr'] exact Finset.mem_image.mpr ⟨(r, σ r), Finset.mem_univ _, rfl⟩ have hkeep_eq : (∏ r ∈ keep, restrictSubst Φ i β (Sum.inl (Φ j (r, σ r)))) = ∏ v ∈ keep.image f, (MvPolynomial.X v : MvPolynomial ((Fin m × Fin m) ⊕ Unit) F) := by rw [Finset.prod_image hf_inj] refine Finset.prod_congr rfl fun r hr => ?_ have hr' := (Finset.mem_filter.mp hr).2 simp only [f, hr', ↓reduceDIte] have hspec := Classical.choose_spec hr' conv_lhs => rw [← hspec] exact restrictSubst_inl_mem Φ i β (Classical.choose hr') have hprod_X : ∀ s : Finset ((Fin m × Fin m) ⊕ Unit), (∏ v ∈ s, (MvPolynomial.X v : MvPolynomial ((Fin m × Fin m) ⊕ Unit) F)) = MvPolynomial.monomial (∑ v ∈ s, Finsupp.single v 1) 1 := by intro s induction s using Finset.induction_on with | empty => simp | insert a s ha ih => rw [Finset.prod_insert ha, Finset.sum_insert ha, ih, MvPolynomial.X, MvPolynomial.monomial_mul, one_mul] rcases hdrop with ⟨c, hc⟩ refine ⟨c, keep.image f, hf_sub, ?_⟩ rw [hsplit, hc, hkeep_eq, hprod_X, MvPolynomial.C_mul_monomial, mul_one] -- Deduce multilinearity and support inclusion for the sum have hmem_term : ∀ μ ∈ (restrictedCoord Φ i β j).support, ∃ s : Finset ((Fin m × Fin m) ⊕ Unit), s ⊆ overlapVars Φ i j ∧ μ = ∑ v ∈ s, Finsupp.single v 1 := by intro μ hμ rw [MvPolynomial.mem_support_iff, hexpr, MvPolynomial.coeff_sum] at hμ have hex : ∃ σ ∈ (Finset.univ : Finset (Equiv.Perm (Fin m))), (∏ r : Fin m, restrictSubst Φ i β (Sum.inl (Φ j (r, σ r)))).coeff μ ≠ 0 := by by_contra h push Not at h exact hμ (Finset.sum_eq_zero h) rcases hex with ⟨σ, _, hσ⟩ obtain ⟨c, s, hs_sub, hs_eq⟩ := hterm σ rw [hs_eq, MvPolynomial.coeff_monomial] at hσ have heq : (∑ v ∈ s, Finsupp.single v 1) = μ := by by_contra hne simp [hne] at hσ exact ⟨s, hs_sub, heq.symm⟩ have hsum_apply : ∀ (s : Finset ((Fin m × Fin m) ⊕ Unit)) (x : (Fin m × Fin m) ⊕ Unit), (∑ v ∈ s, Finsupp.single v (1 : ℕ)) x = if x ∈ s then 1 else 0 := by intro s x rw [Finsupp.finsetSum_apply] by_cases hx : x ∈ s · rw [Finset.sum_eq_single x] · simp [hx] · intro v _ hvx; simp [hvx] · intro h; exact absurd hx h · simp only [hx, ↓reduceIte] refine Finset.sum_eq_zero fun v hv => ?_ have hvx : v ≠ x := fun h => hx (h ▸ hv) simp [hvx] refine ⟨?_, ?_⟩ · intro μ hμ x obtain ⟨s, _, rfl⟩ := hmem_term μ hμ rw [hsum_apply] split_ifs <;> omega · intro μ hμ x hx obtain ⟨s, hs_sub, rfl⟩ := hmem_term μ hμ rw [Finsupp.mem_support_iff, hsum_apply] at hx have hxs : x ∈ s := by by_contra h simp [h] at hx exact hs_sub hxs /-- **Multilinear-restriction monomial count bound (`≤ 2^Δ`).** If `|S_j ∩ S_i| ≤ Δ`, then `restrictedCoord Φ i β j` has at most `2 ^ Δ` monomials. -/ theorem restrictedCoord_support_card_le {F U : Type*} [CommSemiring F] [DecidableEq U] {n m Δ : ℕ} (Φ : Fin n → (Fin m × Fin m ↪ U)) (i : Fin n) (β : FixedVars U Φ i → F) (j : Fin n) (hinter : (designSet Φ j ∩ designSet Φ i).card ≤ Δ) : (restrictedCoord Φ i β j).support.card ≤ 2 ^ Δ := by obtain ⟨hml, hsub⟩ := restrictedCoord_multilinear_and_support Φ i β j have hle := support_card_le_two_pow_of_isMultilinear hml hsub rw [overlapVars_card] at hle exact hle.trans (Nat.pow_le_pow_right (by omega) hinter) /-- For `Δ = Nat.clog 2 n` and `n ≥ 1`, we have `2 ^ Δ < 2 * n`. -/ theorem two_pow_clog_lt_two_mul {n : ℕ} (hn : 1 ≤ n) : 2 ^ Nat.clog 2 n < 2 * n := by by_cases h1 : n = 1 · subst h1; simp · have h2 : 1 < n := by omega have hpos : 0 < Nat.clog 2 n := Nat.clog_pos (by omega) h2 have hprev : 2 ^ (Nat.clog 2 n - 1) < n := Nat.pow_pred_clog_lt_self (by omega) h2 have heq : 2 ^ Nat.clog 2 n = 2 * 2 ^ (Nat.clog 2 n - 1) := by conv_lhs => rw [← Nat.sub_add_cancel hpos, pow_succ, mul_comm] omega /-! ### Section 6: Straight-line arithmetic circuits and size bound -/ /-- A valid arithmetic circuit over `R` is a finite list of polynomials in `MvPolynomial σ R`, each of which is a variable, a constant, or the sum or product of two earlier entries. This matches the definition in Section 1 of `main.tex`. -/ def IsValidCircuit {σ R : Type*} [CommSemiring R] (L : List (MvPolynomial σ R)) : Prop := ∀ (k : ℕ) (hk : k < L.length), (∃ v : σ, L[k] = MvPolynomial.X v) ∨ (∃ c : R, L[k] = MvPolynomial.C c) ∨ (∃ (a b : ℕ) (ha : a < k) (hb : b < k), L[k] = L[a]'(lt_trans ha hk) + L[b]'(lt_trans hb hk)) ∨ (∃ (a b : ℕ) (ha : a < k) (hb : b < k), L[k] = L[a]'(lt_trans ha hk) * L[b]'(lt_trans hb hk)) /-- A polynomial `p` is computed by a circuit of size at most `s`. -/ def Computes {σ R : Type*} [CommSemiring R] (s : ℕ) (p : MvPolynomial σ R) : Prop := ∃ L : List (MvPolynomial σ R), IsValidCircuit L ∧ L.length ≤ s ∧ p ∈ L theorem IsValidCircuit.append_single {σ R : Type*} [CommSemiring R] {L : List (MvPolynomial σ R)} (hL : IsValidCircuit L) (p : MvPolynomial σ R) (hp : (∃ v : σ, p = MvPolynomial.X v) ∨ (∃ c : R, p = MvPolynomial.C c) ∨ (∃ (a b : ℕ) (ha : a < L.length) (hb : b < L.length), p = L[a] + L[b]) ∨ (∃ (a b : ℕ) (ha : a < L.length) (hb : b < L.length), p = L[a] * L[b])) : IsValidCircuit (L ++ [p]) := by intro k hk simp only [List.length_append, List.length_singleton] at hk by_cases hlt : k < L.length · have hget : (L ++ [p])[k] = L[k] := List.getElem_append_left hlt rw [hget] rcases hL k hlt with hvar | hconst | ⟨a, b, ha, hb, heq⟩ | ⟨a, b, ha, hb, heq⟩ · exact Or.inl hvar · exact Or.inr (Or.inl hconst) · refine Or.inr (Or.inr (Or.inl ⟨a, b, ha, hb, ?_⟩)) rw [List.getElem_append_left (lt_trans ha hlt), List.getElem_append_left (lt_trans hb hlt)] exact heq · refine Or.inr (Or.inr (Or.inr ⟨a, b, ha, hb, ?_⟩)) rw [List.getElem_append_left (lt_trans ha hlt), List.getElem_append_left (lt_trans hb hlt)] exact heq · have hkeq : k = L.length := by omega subst hkeq have hget : (L ++ [p])[L.length] = p := by simp rw [hget] rcases hp with hvar | hconst | ⟨a, b, ha, hb, heq⟩ | ⟨a, b, ha, hb, heq⟩ · exact Or.inl hvar · exact Or.inr (Or.inl hconst) · refine Or.inr (Or.inr (Or.inl ⟨a, b, ha, hb, ?_⟩)) rw [List.getElem_append_left ha, List.getElem_append_left hb] exact heq · refine Or.inr (Or.inr (Or.inr ⟨a, b, ha, hb, ?_⟩)) rw [List.getElem_append_left ha, List.getElem_append_left hb] exact heq theorem IsValidCircuit.append_add_mem {σ R : Type*} [CommSemiring R] {L : List (MvPolynomial σ R)} (hL : IsValidCircuit L) {p q : MvPolynomial σ R} (hp : p ∈ L) (hq : q ∈ L) : IsValidCircuit (L ++ [p + q]) := by obtain ⟨a, ha, rfl⟩ := List.mem_iff_getElem.mp hp obtain ⟨b, hb, rfl⟩ := List.mem_iff_getElem.mp hq exact hL.append_single _ (Or.inr (Or.inr (Or.inl ⟨a, b, ha, hb, rfl⟩))) theorem IsValidCircuit.append_mul_mem {σ R : Type*} [CommSemiring R] {L : List (MvPolynomial σ R)} (hL : IsValidCircuit L) {p q : MvPolynomial σ R} (hp : p ∈ L) (hq : q ∈ L) : IsValidCircuit (L ++ [p * q]) := by obtain ⟨a, ha, rfl⟩ := List.mem_iff_getElem.mp hp obtain ⟨b, hb, rfl⟩ := List.mem_iff_getElem.mp hq exact hL.append_single _ (Or.inr (Or.inr (Or.inr ⟨a, b, ha, hb, rfl⟩))) /-- Extending a valid circuit `L` (containing `X v` for every `v ∈ s`) with a single multilinear monomial `C c * ∏ v ∈ s, X v` costs at most `s.card + 1` additional gates. -/ theorem extend_with_multilinear_monomial {σ R : Type*} [CommSemiring R] [DecidableEq σ] (L : List (MvPolynomial σ R)) (hL : IsValidCircuit L) (s : Finset σ) (hvars : ∀ v ∈ s, (MvPolynomial.X v : MvPolynomial σ R) ∈ L) (c : R) : ∃ L' : List (MvPolynomial σ R), IsValidCircuit L' ∧ L'.length ≤ L.length + s.card + 1 ∧ (∀ x ∈ L, x ∈ L') ∧ (MvPolynomial.C c * ∏ v ∈ s, (MvPolynomial.X v : MvPolynomial σ R)) ∈ L' := by induction s using Finset.induction_on with | empty => refine ⟨L ++ [MvPolynomial.C c], hL.append_single _ (Or.inr (Or.inl ⟨c, rfl⟩)), ?_, ?_, ?_⟩ · simp · intro x hx; exact List.mem_append_left _ hx · simp | insert a s ha ih => obtain ⟨L₁, hL₁, hlen₁, hsub₁, hmem₁⟩ := ih (fun v hv => hvars v (Finset.mem_insert_of_mem hv)) have ha_mem : (MvPolynomial.X a : MvPolynomial σ R) ∈ L₁ := hsub₁ _ (hvars a (Finset.mem_insert_self a s)) let p : MvPolynomial σ R := (MvPolynomial.C c * ∏ v ∈ s, MvPolynomial.X v) * MvPolynomial.X a have hp_eq : p = MvPolynomial.C c * ∏ v ∈ insert a s, MvPolynomial.X v := by rw [Finset.prod_insert ha] dsimp only [p] ring refine ⟨L₁ ++ [p], hL₁.append_mul_mem hmem₁ ha_mem, ?_, ?_, ?_⟩ · rw [List.length_append, List.length_singleton, Finset.card_insert_of_notMem ha] omega · intro x hx; exact List.mem_append_left _ (hsub₁ x hx) · rw [← hp_eq]; simp /-- Extending a valid circuit `L` (containing `0` and all variables in `T` with `|T| ≤ Δ`) with a multilinear polynomial `q` supported on `T` costs at most `q.support.card * (Δ + 2)` additional gates. -/ theorem extend_with_multilinear_poly {σ R : Type*} [CommSemiring R] [DecidableEq σ] (L : List (MvPolynomial σ R)) (hL : IsValidCircuit L) (hzero : (0 : MvPolynomial σ R) ∈ L) {T : Finset σ} {Δ : ℕ} (hT : T.card ≤ Δ) (hvars : ∀ v ∈ T, (MvPolynomial.X v : MvPolynomial σ R) ∈ L) (q : MvPolynomial σ R) (hml : IsMultilinear q) (hsupp : ∀ μ ∈ q.support, μ.support ⊆ T) : ∃ L' : List (MvPolynomial σ R), IsValidCircuit L' ∧ L'.length ≤ L.length + q.support.card * (Δ + 2) ∧ (∀ x ∈ L, x ∈ L') ∧ q ∈ L' := by classical have hpartial : ∀ B : Finset (σ →₀ ℕ), B ⊆ q.support → ∃ L' : List (MvPolynomial σ R), IsValidCircuit L' ∧ L'.length ≤ L.length + B.card * (Δ + 2) ∧ (∀ x ∈ L, x ∈ L') ∧ (∑ μ ∈ B, MvPolynomial.monomial μ (q.coeff μ)) ∈ L' := by intro B hB induction B using Finset.induction_on with | empty => exact ⟨L, hL, by simp, fun x hx => hx, by simpa using hzero⟩ | insert μ B hμB ih => have hBsub : B ⊆ q.support := (Finset.subset_insert μ B).trans hB have hμ_mem : μ ∈ q.support := hB (Finset.mem_insert_self μ B) obtain ⟨L₁, hL₁, hlen₁, hsub₁, hsum₁⟩ := ih hBsub have hμ_sub : μ.support ⊆ T := hsupp μ hμ_mem have hμ_card : μ.support.card ≤ Δ := (Finset.card_le_card hμ_sub).trans hT have hmon_eq : MvPolynomial.monomial μ (q.coeff μ) = MvPolynomial.C (q.coeff μ) * ∏ v ∈ μ.support, MvPolynomial.X v := by rw [MvPolynomial.monomial_eq, Finsupp.prod] congr 1 refine Finset.prod_congr rfl fun v hv => ?_ have hle := hml μ hμ_mem v have hpos : μ v ≠ 0 := Finsupp.mem_support_iff.mp hv have heq1 : μ v = 1 := by omega rw [heq1, pow_one] obtain ⟨L₂, hL₂, hlen₂, hsub₂, hmon₂⟩ := extend_with_multilinear_monomial L₁ hL₁ μ.support (fun v hv => hsub₁ _ (hvars v (hμ_sub hv))) (q.coeff μ) rw [← hmon_eq] at hmon₂ have hsum₂ : (∑ ν ∈ B, MvPolynomial.monomial ν (q.coeff ν)) ∈ L₂ := hsub₂ _ hsum₁ let newSum := MvPolynomial.monomial μ (q.coeff μ) + ∑ ν ∈ B, MvPolynomial.monomial ν (q.coeff ν) refine ⟨L₂ ++ [newSum], hL₂.append_add_mem hmon₂ hsum₂, ?_, ?_, ?_⟩ · rw [List.length_append, List.length_singleton, Finset.card_insert_of_notMem hμB] have : (B.card + 1) * (Δ + 2) = B.card * (Δ + 2) + (Δ + 2) := by ring omega · intro x hx; exact List.mem_append_left _ (hsub₂ _ (hsub₁ x hx)) · rw [Finset.sum_insert hμB]; simp [newSum] obtain ⟨L', hL', hlen', hsub', hmem'⟩ := hpartial q.support (Finset.Subset.refl _) rw [← q.as_sum] at hmem' exact ⟨L', hL', hlen', hsub', hmem'⟩ /-- Base circuit containing all `m^2` matrix variables `X (Sum.inl p)` plus `0 = C 0`. -/ noncomputable def baseCircuit (R : Type*) [CommSemiring R] (m : ℕ) : List (MvPolynomial ((Fin m × Fin m) ⊕ Unit) R) := (Finset.univ.toList.map fun p : Fin m × Fin m => MvPolynomial.X (Sum.inl p)) ++ [MvPolynomial.C 0] theorem baseCircuit_valid (R : Type*) [CommSemiring R] (m : ℕ) : IsValidCircuit (baseCircuit R m) := by intro k hk unfold baseCircuit at hk ⊢ rw [List.length_append, List.length_singleton] at hk by_cases hlt : k < (Finset.univ.toList.map fun p : Fin m × Fin m => (MvPolynomial.X (Sum.inl p) : MvPolynomial ((Fin m × Fin m) ⊕ Unit) R)).length · rw [List.getElem_append_left hlt, List.getElem_map] exact Or.inl ⟨Sum.inl _, rfl⟩ · have hkeq : k = (Finset.univ.toList.map fun p : Fin m × Fin m => (MvPolynomial.X (Sum.inl p) : MvPolynomial ((Fin m × Fin m) ⊕ Unit) R)).length := by omega subst hkeq rw [List.getElem_append_right le_rfl] exact Or.inr (Or.inl ⟨0, by simp⟩) theorem baseCircuit_length (R : Type*) [CommSemiring R] (m : ℕ) : (baseCircuit R m).length = m ^ 2 + 1 := by unfold baseCircuit rw [List.length_append, List.length_singleton, List.length_map, Finset.length_toList, Finset.card_univ, Fintype.card_prod, Fintype.card_fin] ring theorem baseCircuit_mem_X (R : Type*) [CommSemiring R] (m : ℕ) (p : Fin m × Fin m) : (MvPolynomial.X (Sum.inl p) : MvPolynomial ((Fin m × Fin m) ⊕ Unit) R) ∈ baseCircuit R m := by unfold baseCircuit refine List.mem_append_left _ ?_ exact List.mem_map.mpr ⟨p, Finset.mem_toList.mpr (Finset.mem_univ p), rfl⟩ theorem baseCircuit_mem_zero (R : Type*) [CommSemiring R] (m : ℕ) : (0 : MvPolynomial ((Fin m × Fin m) ⊕ Unit) R) ∈ baseCircuit R m := by unfold baseCircuit refine List.mem_append_right _ ?_ simp /-- **Circuit-size bound for the reconstructed polynomial `g(y, w)` (Lemma 2 of `main.tex`).** If `f` has a circuit of size at most `s`, pairwise design intersections are `≤ Δ`, and `2 ^ Δ ≤ 2 * n`, then the restricted hybrid polynomial `g(y, w)` has a circuit of size at most `s + m ^ 2 + 1 + 2 * n ^ 2 * (Δ + 2)`. -/ theorem restricted_hybrid_computes {F U : Type*} [CommSemiring F] [DecidableEq U] {n m Δ s : ℕ} (Φ : Fin n → (Fin m × Fin m ↪ U)) (hdesign : ∀ a b : Fin n, a ≠ b → (designSet Φ a ∩ designSet Φ b).card ≤ Δ) (h2pow : 2 ^ Δ ≤ 2 * n) (i : Fin n) (β : FixedVars U Φ i → F) (f : MvPolynomial (Fin n) F) (hf_comp : Computes s f) : Computes (s + m ^ 2 + 1 + 2 * n ^ 2 * (Δ + 2)) (MvPolynomial.bind₁ (restrictSubst Φ i β) (hybridPoly (nwGenerator F Φ) f (i : ℕ))) := by classical -- Step 1: Build prefix circuit computing all `restrictedCoord Φ i β j` for `j < i`. have hprefix : ∀ k : ℕ, k ≤ (i : ℕ) → ∃ L_pre : List (MvPolynomial ((Fin m × Fin m) ⊕ Unit) F), IsValidCircuit L_pre ∧ L_pre.length ≤ m ^ 2 + 1 + k * (2 * n * (Δ + 2)) ∧ (0 : MvPolynomial ((Fin m × Fin m) ⊕ Unit) F) ∈ L_pre ∧ (∀ p : Fin m × Fin m, MvPolynomial.X (Sum.inl p) ∈ L_pre) ∧ (∀ j : Fin n, (j : ℕ) < k → restrictedCoord Φ i β j ∈ L_pre) := by intro k hk induction k with | zero => exact ⟨baseCircuit F m, baseCircuit_valid F m, by rw [baseCircuit_length]; omega, baseCircuit_mem_zero F m, baseCircuit_mem_X F m, fun j hj => by omega⟩ | succ k ih => obtain ⟨L₁, hL₁, hlen₁, hzero₁, hvars₁, hcoords₁⟩ := ih (Nat.le_of_succ_le hk) let j : Fin n := ⟨k, lt_trans (Nat.lt_of_lt_of_le (Nat.lt_succ_self k) hk) i.isLt⟩ have hji : j ≠ i := fun h => by have := congrArg Fin.val h dsimp [j] at this omega have hinter : (designSet Φ j ∩ designSet Φ i).card ≤ Δ := hdesign j i hji have hTcard : (overlapVars Φ i j).card ≤ Δ := by rw [overlapVars_card]; exact hinter obtain ⟨hml, hsupp⟩ := restrictedCoord_multilinear_and_support Φ i β j have hcard_q : (restrictedCoord Φ i β j).support.card ≤ 2 * n := (restrictedCoord_support_card_le Φ i β j hinter).trans h2pow have hvars_T : ∀ v ∈ overlapVars Φ i j, (MvPolynomial.X v : MvPolynomial ((Fin m × Fin m) ⊕ Unit) F) ∈ L₁ := by intro v hv rcases Finset.mem_image.mp hv with ⟨p, _, rfl⟩ exact hvars₁ p obtain ⟨L₂, hL₂, hlen₂, hsub₂, hmem_j⟩ := extend_with_multilinear_poly L₁ hL₁ hzero₁ hTcard hvars_T (restrictedCoord Φ i β j) hml hsupp refine ⟨L₂, hL₂, ?_, hsub₂ _ hzero₁, fun p => hsub₂ _ (hvars₁ p), ?_⟩ · have hmul : (restrictedCoord Φ i β j).support.card * (Δ + 2) ≤ 2 * n * (Δ + 2) := Nat.mul_le_mul_right (Δ + 2) hcard_q have hstep : (k + 1) * (2 * n * (Δ + 2)) = k * (2 * n * (Δ + 2)) + 2 * n * (Δ + 2) := by ring omega · intro j' hj' by_cases hlt : (j' : ℕ) < k · exact hsub₂ _ (hcoords₁ j' hlt) · have heq : j' = j := Fin.ext (by dsimp [j]; omega) subst heq exact hmem_j obtain ⟨L_pre, hL_pre, hlen_pre, hzero_pre, _, hcoords_pre⟩ := hprefix (i : ℕ) le_rfl -- Step 2: Map the circuit `L_f` for `f` through the combined substitution `σ_g`. let σ_g : Fin n → MvPolynomial ((Fin m × Fin m) ⊕ Unit) F := fun j => MvPolynomial.bind₁ (restrictSubst Φ i β) (hybridSubst (nwGenerator F Φ) (i : ℕ) j) have hcomp_g : ∀ P : MvPolynomial (Fin n) F, MvPolynomial.bind₁ σ_g P = MvPolynomial.bind₁ (restrictSubst Φ i β) (hybridPoly (nwGenerator F Φ) P (i : ℕ)) := by intro P unfold hybridPoly induction P using MvPolynomial.induction_on with | C a => simp | add p q hp hq => simp [map_add, hp, hq] | mul_X p j hp => simp [map_mul, hp, σ_g] rcases hf_comp with ⟨L_f, hL_f, hlen_f, hf_mem⟩ let L_full : List (MvPolynomial ((Fin m × Fin m) ⊕ Unit) F) := L_pre ++ L_f.map (MvPolynomial.bind₁ σ_g) have hL_full : IsValidCircuit L_full := by intro k hk dsimp only [L_full] at hk ⊢ rw [List.length_append, List.length_map] at hk by_cases hlt : k < L_pre.length · rw [List.getElem_append_left hlt] rcases hL_pre k hlt with hvar | hconst | ⟨a, b, ha, hb, heq⟩ | ⟨a, b, ha, hb, heq⟩ · exact Or.inl hvar · exact Or.inr (Or.inl hconst) · refine Or.inr (Or.inr (Or.inl ⟨a, b, ha, hb, ?_⟩)) rw [List.getElem_append_left (lt_trans ha hlt), List.getElem_append_left (lt_trans hb hlt)] exact heq · refine Or.inr (Or.inr (Or.inr ⟨a, b, ha, hb, ?_⟩)) rw [List.getElem_append_left (lt_trans ha hlt), List.getElem_append_left (lt_trans hb hlt)] exact heq · have hk' : k - L_pre.length < L_f.length := by omega rw [List.getElem_append_right (Nat.le_of_not_lt hlt), List.getElem_map] rcases hL_f (k - L_pre.length) hk' with ⟨j, hj⟩ | ⟨c, hc⟩ | ⟨a, b, ha, hb, heq⟩ | ⟨a, b, ha, hb, heq⟩ · rw [hj, MvPolynomial.bind₁_X_right] by_cases hji : (j : ℕ) < (i : ℕ) · have hσj : σ_g j = restrictedCoord Φ i β j := by dsimp only [σ_g, hybridSubst, restrictedCoord] rw [if_pos hji] have hmem_q : restrictedCoord Φ i β j ∈ L_pre := hcoords_pre j hji obtain ⟨a, ha, ha_eq⟩ := List.mem_iff_getElem.mp hmem_q obtain ⟨b, hb, hb_eq⟩ := List.mem_iff_getElem.mp hzero_pre refine Or.inr (Or.inr (Or.inl ⟨a, b, by omega, by omega, ?_⟩)) rw [hσj, List.getElem_append_left ha, List.getElem_append_left hb, ha_eq, hb_eq, add_zero] · have hσj : σ_g j = restrictSubst Φ i β (Sum.inr j) := by dsimp only [σ_g, hybridSubst] rw [if_neg hji, MvPolynomial.bind₁_X_right] rw [hσj] by_cases heq_i : j = i · subst heq_i exact Or.inl ⟨Sum.inr (), restrictSubst_inr_self Φ j β⟩ · exact Or.inr (Or.inl ⟨β ⟨Sum.inr j, heq_i⟩, restrictSubst_inr_ne Φ i β j heq_i⟩) · rw [hc, MvPolynomial.bind₁_C_right] exact Or.inr (Or.inl ⟨c, rfl⟩) · refine Or.inr (Or.inr (Or.inl ⟨L_pre.length + a, L_pre.length + b, by omega, by omega, ?_⟩)) rw [heq, map_add] rw [List.getElem_append_right (Nat.le_add_right _ _), List.getElem_append_right (Nat.le_add_right _ _)] simp · refine Or.inr (Or.inr (Or.inr ⟨L_pre.length + a, L_pre.length + b, by omega, by omega, ?_⟩)) rw [heq, map_mul] rw [List.getElem_append_right (Nat.le_add_right _ _), List.getElem_append_right (Nat.le_add_right _ _)] simp refine ⟨L_full, hL_full, ?_, ?_⟩ · dsimp only [L_full] rw [List.length_append, List.length_map] have hi_le : (i : ℕ) ≤ n := Nat.le_of_lt i.isLt have hmul_le : (i : ℕ) * (2 * n * (Δ + 2)) ≤ 2 * n ^ 2 * (Δ + 2) := by calc (i : ℕ) * (2 * n * (Δ + 2)) ≤ n * (2 * n * (Δ + 2)) := Nat.mul_le_mul_right _ hi_le _ = 2 * n ^ 2 * (Δ + 2) := by ring omega · rw [← hcomp_g f] exact List.mem_append_right _ (List.mem_map.mpr ⟨f, hf_mem, rfl⟩) /-- **Full Lemma 2 of `main.tex` (Hybrid Reconstruction + Circuit Bound + Bürgisser Bridge).** Combines: 1. Minimal hybrid index `i < n` and assignment `β` yielding nonzero `g(y, w)` with `(w - perm_m(y)) ∣ g(y, w)`. 2. Explicit arithmetic circuit for `g` of size `s' = s + m^2 + 1 + 2 * n^2 * (Δ + 2)`. 3. Conditional on any abstract Bürgisser graph-factorization predicate `ApproxComputes` satisfying `(I2)`, concludes `ApproxComputes (C₁ * m^4 * s') (permPoly F m)`. -/ theorem lemma2_reconstruction {F U : Type*} [Field F] [Infinite F] [Fintype U] [DecidableEq U] {n m Δ s C₁ : ℕ} (Φ : Fin n → (Fin m × Fin m ↪ U)) (hdesign : ∀ a b : Fin n, a ≠ b → (designSet Φ a ∩ designSet Φ b).card ≤ Δ) (h2pow : 2 ^ Δ ≤ 2 * n) (f : MvPolynomial (Fin n) F) (hf_ne : f ≠ 0) (hf_comp : Computes s f) (hvanish : MvPolynomial.bind₁ (nwGenerator F Φ) f = 0) (ApproxComputes : ℕ → MvPolynomial (Fin m × Fin m) F → Prop) (hBurgisser : ∀ (g : MvPolynomial ((Fin m × Fin m) ⊕ Unit) F) (s' : ℕ), g ≠ 0 → (MvPolynomial.X (Sum.inr ()) - MvPolynomial.rename Sum.inl (permPoly F m)) ∣ g → Computes s' g → ApproxComputes (C₁ * m ^ 4 * s') (permPoly F m)) : ApproxComputes (C₁ * m ^ 4 * (s + m ^ 2 + 1 + 2 * n ^ 2 * (Δ + 2))) (permPoly F m) := by obtain ⟨i, β, -, -, hg_ne, hg_dvd⟩ := hybrid_reconstruction_dvd Φ f hf_ne hvanish have hg_comp := restricted_hybrid_computes Φ hdesign h2pow i β f hf_comp exact hBurgisser _ _ hg_ne hg_dvd hg_comp end PermanentPIT.HybridReconstruction #print axioms PermanentPIT.HybridReconstruction.hybrid_reconstruction_dvd #print axioms PermanentPIT.HybridReconstruction.restrictedCoord_support_card_le #print axioms PermanentPIT.HybridReconstruction.two_pow_clog_lt_two_mul #print axioms PermanentPIT.HybridReconstruction.restricted_hybrid_computes #print axioms PermanentPIT.HybridReconstruction.lemma2_reconstruction