math / data /lean /OAI /Algorithms /SubexponentialSAT /SqrtLogSpace /BooleanDifferences.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
12.7 kB
import Mathlib.Algebra.MvPolynomial.Degrees
import Mathlib.Algebra.MvPolynomial.Eval
import Mathlib.Algebra.Polynomial.Eval.Coeff
import Mathlib.Algebra.BigOperators.Group.Finset.Powerset
import Mathlib.Data.Fintype.Powerset
/-! Boolean finite differences (ETH, Lemma `boolean-differences`).
The finite sets in this module specify sums; they are not operational enumerators. -/
namespace OAI.Algorithms.SubexponentialSAT.SqrtLogSpace.BooleanDifferences
open scoped BigOperators
/-- The original support counting envelope. -/
def supportFamily (n J : β„•) : Finset (Finset (Fin n)) :=
Finset.univ.filter (fun E => E.card < J)
/-- Valid correction pairs form a subset of the square of the support envelope. -/
def pairFamily (n J : β„•) : Finset (Finset (Fin n) Γ— Finset (Fin n)) :=
(supportFamily n J Γ—Λ’ supportFamily n J).filter (fun p => p.2 βŠ† p.1)
@[simp] theorem mem_supportFamily {n J : β„•} {E : Finset (Fin n)} :
E ∈ supportFamily n J ↔ E.card < J := by
simp [supportFamily]
@[simp] theorem mem_pairFamily {n J : β„•} {E U : Finset (Fin n)} :
(E, U) ∈ pairFamily n J ↔ E.card < J ∧ U βŠ† E := by
simp only [pairFamily, Finset.mem_filter, Finset.mem_product, mem_supportFamily]
exact ⟨fun h => ⟨h.1.1, h.2⟩,
fun h => ⟨⟨h.1, (Finset.card_le_card h.2).trans_lt h.1⟩, h.2⟩⟩
theorem pairFamily_card_le (n J : β„•) :
(pairFamily n J).card ≀ (supportFamily n J).card ^ 2 := by
calc
_ ≀ (supportFamily n J Γ—Λ’ supportFamily n J).card := Finset.card_filter_le _ _
_ = _ := by simp [pow_two]
theorem pairFamily_eq_biUnion (n J : β„•) :
pairFamily n J = (supportFamily n J).biUnion
(fun E => E.powerset.image (fun U => (E, U))) := by
ext p
rcases p with ⟨E, U⟩
simp [Finset.mem_biUnion, Finset.mem_image]
/-- Coordinate transport preserves the exact support counting envelope. -/
theorem supportFamily_map_equiv {V : Type*} [Fintype V] [DecidableEq V]
{n : β„•} (e : Fin n ≃ V) (J : β„•) :
(supportFamily n J).map e.finsetCongr.toEmbedding =
Finset.univ.filter (fun E : Finset V => E.card < J) := by
ext E
simp [Finset.mem_map_equiv, Equiv.finsetCongr]
/-- A coordinate equivalence transports the iterator's pairs exactly. This is
an internal indexing change, not a change of the ambient assignment universe. -/
theorem pairFamily_map_equiv {V : Type*} [Fintype V] [DecidableEq V]
{n : β„•} (e : Fin n ≃ V) (J : β„•) :
(pairFamily n J).map (Equiv.prodCongr e.finsetCongr e.finsetCongr).toEmbedding =
Finset.univ.filter (fun p : Finset V Γ— Finset V => p.1.card < J ∧ p.2 βŠ† p.1) := by
ext p
rcases p with ⟨E, U⟩
simp [Finset.mem_map_equiv, Equiv.prodCongr, Equiv.finsetCongr]
variable {V R : Type*} [DecidableEq V] [CommRing R]
/-- Substitution of the Boolean characteristic vector of a set. -/
def evalAt (U : Finset V) : MvPolynomial V R β†’+* R :=
MvPolynomial.eval (fun v => if v ∈ U then 1 else 0)
/-- The coefficient of the Boolean multilinearization indexed by `E`. -/
def difference (E : Finset V) (p : MvPolynomial V R) : R :=
βˆ‘ U ∈ E.powerset, (-1 : R) ^ (E.card - U.card) * evalAt U p
private theorem subset_sign_sum (E T : Finset V) :
(βˆ‘ U ∈ E.powerset, (-1 : R) ^ (E.card - U.card) *
(if T βŠ† U then 1 else 0)) = if T = E then 1 else 0 := by
induction E using Finset.induction_on generalizing T with
| empty => simp only [Finset.powerset_empty, Finset.sum_singleton,
Finset.card_empty, Nat.sub_self, pow_zero, one_mul, Finset.subset_empty]
| @insert a E ha ih =>
rw [Finset.sum_powerset_insert ha]
have hcard (U : Finset V) (hU : U ∈ E.powerset) : U.card ≀ E.card :=
Finset.card_le_card (Finset.mem_powerset.mp hU)
have hnot (U : Finset V) (hU : U ∈ E.powerset) : a βˆ‰ U :=
fun h => ha (Finset.mem_powerset.mp hU h)
by_cases hat : a ∈ T
Β· have hzero : (βˆ‘ U ∈ E.powerset, (-1 : R) ^ ((insert a E).card - U.card) *
(if T βŠ† U then 1 else 0)) = 0 := by
apply Finset.sum_eq_zero
intro U hU
simp [show Β¬T βŠ† U from fun h => hnot U hU (h hat)]
rw [hzero, zero_add]
calc
_ = βˆ‘ U ∈ E.powerset, (-1 : R) ^ (E.card - U.card) *
(if T.erase a βŠ† U then 1 else 0) := by
apply Finset.sum_congr rfl
intro U hU
rw [Finset.card_insert_of_notMem ha, Finset.card_insert_of_notMem (hnot U hU)]
have hsub : T βŠ† insert a U ↔ T.erase a βŠ† U := by
constructor
Β· intro h v hv
exact (Finset.mem_insert.mp (h (Finset.mem_erase.mp hv).2)).resolve_left
(Finset.mem_erase.mp hv).1
Β· intro h v hv
by_cases hav : v = a
Β· simp [hav]
· exact Finset.mem_insert_of_mem (h (Finset.mem_erase.mpr ⟨hav, hv⟩))
simp [hsub]
_ = if T.erase a = E then 1 else 0 := ih _
_ = _ := by
have heq : T.erase a = E ↔ T = insert a E := by
constructor
Β· intro h; rw [← h, Finset.insert_erase hat]
Β· intro h; subst T; simp [ha]
simp only [heq]
Β· have hsub (U : Finset V) : T βŠ† insert a U ↔ T βŠ† U := by
constructor
Β· intro h v hv
exact (Finset.mem_insert.mp (h hv)).resolve_left (fun h => hat (h β–Έ hv))
Β· exact fun h => h.trans (Finset.subset_insert _ _)
have hfirst : (βˆ‘ U ∈ E.powerset, (-1 : R) ^ ((insert a E).card - U.card) *
(if T βŠ† U then 1 else 0)) =
-(βˆ‘ U ∈ E.powerset, (-1 : R) ^ (E.card - U.card) *
(if T βŠ† U then 1 else 0)) := by
rw [← Finset.sum_neg_distrib]
apply Finset.sum_congr rfl
intro U hU
rw [Finset.card_insert_of_notMem ha,
show E.card + 1 - U.card = E.card - U.card + 1 by
have := hcard U hU
omega, pow_succ]
split_ifs <;> simp
rw [hfirst]
have hsecond : (βˆ‘ U ∈ E.powerset,
(-1 : R) ^ ((insert a E).card - (insert a U).card) *
(if T βŠ† insert a U then 1 else 0)) =
βˆ‘ U ∈ E.powerset, (-1 : R) ^ (E.card - U.card) *
(if T βŠ† U then 1 else 0) := by
apply Finset.sum_congr rfl
intro U hU
simp [Finset.card_insert_of_notMem ha,
Finset.card_insert_of_notMem (hnot U hU), hsub]
rw [hsecond, neg_add_cancel]
simp [show T β‰  insert a E from fun h => hat (h.symm β–Έ Finset.mem_insert_self a E)]
@[simp] theorem evalAt_monomial (U : Finset V) (d : V β†’β‚€ β„•) (c : R) :
evalAt U (MvPolynomial.monomial d c) = if d.support βŠ† U then c else 0 := by
classical
rw [evalAt, MvPolynomial.eval_monomial, Finsupp.prod]
by_cases h : d.support βŠ† U
Β· rw [ite_eq_left h, Finset.prod_eq_one (fun v hv => by simp [h hv]), mul_one]
· obtain ⟨v, hv, hvU⟩ := Finset.not_subset.mp h
have hd : d v β‰  0 := Finsupp.mem_support_iff.mp hv
rw [Finset.prod_eq_zero hv (by simp [hvU, hd]), mul_zero, ite_eq_right h]
theorem difference_monomial (E : Finset V) (d : V β†’β‚€ β„•) (c : R) :
difference E (MvPolynomial.monomial d c) = if d.support = E then c else 0 := by
classical
simp only [difference, evalAt_monomial]
calc
_ = (βˆ‘ U ∈ E.powerset, (-1 : R) ^ (E.card - U.card) *
(if d.support βŠ† U then 1 else 0)) * c := by
rw [Finset.sum_mul]
apply Finset.sum_congr rfl
intro U _
split_ifs <;> simp
_ = _ := by rw [subset_sign_sum]; split_ifs <;> simp
theorem difference_eq_sum_coeff (E : Finset V) (p : MvPolynomial V R) :
difference E p = βˆ‘ d ∈ p.support,
if d.support = E then p.coeff d else 0 := by
classical
conv_lhs => rw [← MvPolynomial.support_sum_monomial_coeff p]
simp only [difference, map_sum, Finset.mul_sum]
rw [Finset.sum_comm]
apply Finset.sum_congr rfl
intro d _
exact difference_monomial E d (p.coeff d)
omit [DecidableEq V] in
/-- Degree controls the number of distinct variables in every monomial. -/
theorem support_card_le_totalDegree (p : MvPolynomial V R) {d : V β†’β‚€ β„•}
(hd : d ∈ p.support) : d.support.card ≀ p.totalDegree := by
calc
d.support.card = βˆ‘ v ∈ d.support, 1 := by simp
_ ≀ βˆ‘ v ∈ d.support, d v := Finset.sum_le_sum (fun v hv =>
Nat.one_le_iff_ne_zero.mpr (Finsupp.mem_support_iff.mp hv))
_ ≀ p.totalDegree := MvPolynomial.le_totalDegree hd
/-- Recovery at one Boolean point; high-degree supports do not contribute. -/
theorem evalAt_eq_sum_differences [Fintype V] {J : β„•} (X : Finset V)
(p : MvPolynomial V R) (hp : p.totalDegree < J) :
evalAt X p = βˆ‘ E ∈ Finset.univ.filter (fun E : Finset V => E.card < J),
if E βŠ† X then difference E p else 0 := by
classical
simp only [difference_eq_sum_coeff]
simp_rw [Finset.ite_sum_zero]
rw [Finset.sum_comm]
conv_lhs => rw [← MvPolynomial.support_sum_monomial_coeff p]
rw [map_sum]
apply Finset.sum_congr rfl
intro d hd
have hcard : d.support.card < J := (support_card_le_totalDegree p hd).trans_lt hp
rw [evalAt_monomial]
by_cases hsub : d.support βŠ† X
Β· rw [ite_eq_left hsub]
symm
rw [Finset.sum_eq_single d.support]
Β· simp [hsub]
Β· intro E _ hE
simp [Ne.symm hE]
Β· simp [hcard]
Β· rw [ite_eq_right hsub]
symm
apply Finset.sum_eq_zero
intro E _
by_cases he : d.support = E
Β· subst E; simp [hsub]
Β· simp [he]
/-- Boolean assignments retain all ambient variables, including unused ones. -/
def trueSet [Fintype V] (x : V β†’ Bool) : Finset V :=
Finset.univ.filter (fun i => x i = true)
omit [DecidableEq V] in
@[simp] theorem subset_trueSet [Fintype V] (E : Finset V) (x : V β†’ Bool) :
E βŠ† trueSet x ↔ βˆ€ i ∈ E, x i = true := by
simp [Finset.subset_iff, trueSet]
/-- ETH Boolean finite differences over an arbitrary commutative ring.
The polynomial is allowed to depend on the assignment being summed. -/
theorem sum_eval_eq_sum_differences [Fintype V] {J : β„•}
(p : (V β†’ Bool) β†’ MvPolynomial V R)
(hp : βˆ€ x, (p x).totalDegree < J) :
(βˆ‘ x, evalAt (trueSet x) (p x)) =
βˆ‘ E ∈ Finset.univ.filter (fun E : Finset V => E.card < J), βˆ‘ U ∈ E.powerset,
(-1 : R) ^ (E.card - U.card) *
βˆ‘ x ∈ Finset.univ.filter (fun x : V β†’ Bool => βˆ€ i ∈ E, x i = true),
evalAt U (p x) := by
classical
conv_lhs =>
arg 2
ext x
rw [evalAt_eq_sum_differences _ _ (hp x)]
rw [Finset.sum_comm]
apply Finset.sum_congr rfl
intro E _
simp only [difference, Finset.sum_filter, subset_trueSet]
simp_rw [Finset.ite_sum_zero]
rw [Finset.sum_comm]
apply Finset.sum_congr rfl
intro U _
rw [Finset.mul_sum]
apply Finset.sum_congr rfl
intro x _
split_ifs <;> simp
/-- Every retained Taylor coefficient is recovered using the same pair family.
The hypothesis is the precise degree cost: each formal correction variable carries Z. -/
theorem coeff_sum_eval_eq_sum_differences [Fintype V] {J j : β„•}
(P : (V β†’ Bool) β†’ Polynomial (MvPolynomial V R)) (hj : j < J)
(hP : βˆ€ x, ((P x).coeff j).totalDegree ≀ j) :
(βˆ‘ x, (P x).map (evalAt (trueSet x))).coeff j =
(βˆ‘ E ∈ Finset.univ.filter (fun E : Finset V => E.card < J),
βˆ‘ U ∈ E.powerset, Polynomial.C ((-1 : R) ^ (E.card - U.card)) *
βˆ‘ x ∈ Finset.univ.filter (fun x : V β†’ Bool => βˆ€ i ∈ E, x i = true),
(P x).map (evalAt U)).coeff j := by
classical
simp only [Polynomial.finsetSum_coeff, Polynomial.coeff_C_mul, Polynomial.coeff_map]
exact sum_eval_eq_sum_differences (fun x => (P x).coeff j)
(fun x => (hP x).trans_lt hj)
/-- The entire truncated Taylor polynomial, also for J = 0 and an empty variable type. -/
theorem truncated_sum_eval_eq_sum_differences [Fintype V] (J : β„•)
(P : (V β†’ Bool) β†’ Polynomial (MvPolynomial V R))
(hP : βˆ€ x j, j < J β†’ ((P x).coeff j).totalDegree ≀ j) :
(βˆ‘ j ∈ Finset.range J, Polynomial.monomial j
((βˆ‘ x, (P x).map (evalAt (trueSet x))).coeff j)) =
βˆ‘ j ∈ Finset.range J, Polynomial.monomial j
((βˆ‘ E ∈ Finset.univ.filter (fun E : Finset V => E.card < J),
βˆ‘ U ∈ E.powerset, Polynomial.C ((-1 : R) ^ (E.card - U.card)) *
βˆ‘ x ∈ Finset.univ.filter (fun x : V β†’ Bool => βˆ€ i ∈ E, x i = true),
(P x).map (evalAt U)).coeff j) := by
classical
apply Finset.sum_congr rfl
intro j hj
rw [coeff_sum_eval_eq_sum_differences P (Finset.mem_range.mp hj)
(fun x => hP x j (Finset.mem_range.mp hj))]
end OAI.Algorithms.SubexponentialSAT.SqrtLogSpace.BooleanDifferences