l3lab/ntp-mathlib huggingface dataset:
/-- The **Four Functions Theorem** on a powerset algebra. See `four_functions_theorem` for the
finite distributive lattice generalisation. -/
protected lemma Finset.four_functions_theorem (u : Finset α)
    (h₁ : 0 ≤ f₁) (h₂ : 0 ≤ f₂) (h₃ : 0 ≤ f₃) (h₄ : 0 ≤ f₄)
    (h : ∀ ⦃s⦄, s ⊆ u → ∀ ⦃t⦄, t ⊆ u → f₁ s * f₂ t ≤ f₃ (s ∩ t) * f₄ (s ∪ t))
    {𝒜 ℬ : Finset (Finset α)} (h𝒜 : 𝒜 ⊆ u.powerset) (hℬ : ℬ ⊆ u.powerset) :
    (∑ s in 𝒜, f₁ s) * ∑ s in ℬ, f₂ s ≤ (∑ s in 𝒜 ⊼ ℬ, f₃ s) * ∑ s in 𝒜 ⊻ ℬ, f₄ s := by
  induction' u using Finset.induction with a u hu ih generalizing f₁ f₂ f₃ f₄ 𝒜 ℬ
  · simp only [Finset.powerset_empty, Finset.subset_singleton_iff] at h𝒜 hℬ
    obtain rfl | rfl := h𝒜 <;> obtain rfl | rfl := hℬ <;> simp; exact h (subset_refl ∅) subset_rfl
  specialize ih (collapse_nonneg h₁) (collapse_nonneg h₂) (collapse_nonneg h₃) (collapse_nonneg h₄)
    (collapse_modular hu h₁ h₂ h₃ h₄ h 𝒜 ℬ) Subset.rfl Subset.rfl
  have : 𝒜 ⊼ ℬ ⊆ powerset (insert a u) := by 

Proof state:
α : Type u_1
β : Type u_2
inst✝² : DecidableEq α
inst✝¹ : LinearOrderedCommSemiring β
inst✝ : ExistsAddOfLE β
𝒜✝ ℬ✝ : Finset (Finset α)
a✝ : α
f g μ : Finset α → β
s t u✝ : Finset α
a : α
u : Finset α
hu : a ∉ u
f₁ f₂ f₃ f₄ : Finset α → β
h₁ : 0 ≤ f₁
h₂ : 0 ≤ f₂
h₃ : 0 ≤ f₃
h₄ : 0 ≤ f₄
h : ∀ ⦃s : Finset α⦄, s ⊆ insert a u → ∀ ⦃t : Finset α⦄, t ⊆ insert a u → f₁ s * f₂ t ≤ f₃ (s ∩ t) * f₄ (s ∪ t)
𝒜 ℬ : Finset (Finset α)
h𝒜 : 𝒜 ⊆ powerset (insert a u)
hℬ : ℬ ⊆ powerset (insert a u)
ih :
  (∑ s in powerset u, collapse 𝒜 a f₁ s) * ∑ s in powerset u, collapse ℬ a f₂ s ≤
    (∑ s in powerset u ⊼ powerset u, collapse (𝒜 ⊼ ℬ) a f₃ s) * ∑ s in powerset u ⊻ powerset u, collapse (𝒜 ⊻ ℬ) a f₄ s
⊢ 𝒜 ⊼ ℬ ⊆ powerset (insert a u)

Next tactic:
simpa using infs_subset h𝒜 hℬ
/-- The **Four Functions Theorem** on a powerset algebra. See `four_functions_theorem` for the
finite distributive lattice generalisation. -/
protected lemma Finset.four_functions_theorem (u : Finset α)
    (h₁ : 0 ≤ f₁) (h₂ : 0 ≤ f₂) (h₃ : 0 ≤ f₃) (h₄ : 0 ≤ f₄)
    (h : ∀ ⦃s⦄, s ⊆ u → ∀ ⦃t⦄, t ⊆ u → f₁ s * f₂ t ≤ f₃ (s ∩ t) * f₄ (s ∪ t))
    {𝒜 ℬ : Finset (Finset α)} (h𝒜 : 𝒜 ⊆ u.powerset) (hℬ : ℬ ⊆ u.powerset) :
    (∑ s in 𝒜, f₁ s) * ∑ s in ℬ, f₂ s ≤ (∑ s in 𝒜 ⊼ ℬ, f₃ s) * ∑ s in 𝒜 ⊻ ℬ, f₄ s := by
  induction' u using Finset.induction with a u hu ih generalizing f₁ f₂ f₃ f₄ 𝒜 ℬ
  · simp only [Finset.powerset_empty, Finset.subset_singleton_iff] at h𝒜 hℬ
    obtain rfl | rfl := h𝒜 <;> obtain rfl | rfl := hℬ <;> simp; exact h (subset_refl ∅) subset_rfl
  specialize ih (collapse_nonneg h₁) (collapse_nonneg h₂) (collapse_nonneg h₃) (collapse_nonneg h₄)
    (collapse_modular hu h₁ h₂ h₃ h₄ h 𝒜 ℬ) Subset.rfl Subset.rfl
  have : 𝒜 ⊼ ℬ ⊆ powerset (insert a u) := by simpa using infs_subset h𝒜 hℬ
  

Proof state:
case insert
α : Type u_1
β : Type u_2
inst✝² : DecidableEq α
inst✝¹ : LinearOrderedCommSemiring β
inst✝ : ExistsAddOfLE β
𝒜✝ ℬ✝ : Finset (Finset α)
a✝ : α
f g μ : Finset α → β
s t u✝ : Finset α
a : α
u : Finset α
hu : a ∉ u
f₁ f₂ f₃ f₄ : Finset α → β
h₁ : 0 ≤ f₁
h₂ : 0 ≤ f₂
h₃ : 0 ≤ f₃
h₄ : 0 ≤ f₄
h : ∀ ⦃s : Finset α⦄, s ⊆ insert a u → ∀ ⦃t : Finset α⦄, t ⊆ insert a u → f₁ s * f₂ t ≤ f₃ (s ∩ t) * f₄ (s ∪ t)
𝒜 ℬ : Finset (Finset α)
h𝒜 : 𝒜 ⊆ powerset (insert a u)
hℬ : ℬ ⊆ powerset (insert a u)
ih :
  (∑ s in powerset u, collapse 𝒜 a f₁ s) * ∑ s in powerset u, collapse ℬ a f₂ s ≤
    (∑ s in powerset u ⊼ powerset u, collapse (𝒜 ⊼ ℬ) a f₃ s) * ∑ s in powerset u ⊻ powerset u, collapse (𝒜 ⊻ ℬ) a f₄ s
this : 𝒜 ⊼ ℬ ⊆ powerset (insert a u)
⊢ (∑ s in 𝒜, f₁ s) * ∑ s in ℬ, f₂ s ≤ (∑ s in 𝒜 ⊼ ℬ, f₃ s) * ∑ s in 𝒜 ⊻ ℬ, f₄ s

Next tactic:
have : 𝒜 ⊻ ℬ ⊆ powerset (insert a u) := by simpa using sups_subset h𝒜 hℬ
/-- The **Four Functions Theorem** on a powerset algebra. See `four_functions_theorem` for the
finite distributive lattice generalisation. -/
protected lemma Finset.four_functions_theorem (u : Finset α)
    (h₁ : 0 ≤ f₁) (h₂ : 0 ≤ f₂) (h₃ : 0 ≤ f₃) (h₄ : 0 ≤ f₄)
    (h : ∀ ⦃s⦄, s ⊆ u → ∀ ⦃t⦄, t ⊆ u → f₁ s * f₂ t ≤ f₃ (s ∩ t) * f₄ (s ∪ t))
    {𝒜 ℬ : Finset (Finset α)} (h𝒜 : 𝒜 ⊆ u.powerset) (hℬ : ℬ ⊆ u.powerset) :
    (∑ s in 𝒜, f₁ s) * ∑ s in ℬ, f₂ s ≤ (∑ s in 𝒜 ⊼ ℬ, f₃ s) * ∑ s in 𝒜 ⊻ ℬ, f₄ s := by
  induction' u using Finset.induction with a u hu ih generalizing f₁ f₂ f₃ f₄ 𝒜 ℬ
  · simp only [Finset.powerset_empty, Finset.subset_singleton_iff] at h𝒜 hℬ
    obtain rfl | rfl := h𝒜 <;> obtain rfl | rfl := hℬ <;> simp; exact h (subset_refl ∅) subset_rfl
  specialize ih (collapse_nonneg h₁) (collapse_nonneg h₂) (collapse_nonneg h₃) (collapse_nonneg h₄)
    (collapse_modular hu h₁ h₂ h₃ h₄ h 𝒜 ℬ) Subset.rfl Subset.rfl
  have : 𝒜 ⊼ ℬ ⊆ powerset (insert a u) := by simpa using infs_subset h𝒜 hℬ
  have : 𝒜 ⊻ ℬ ⊆ powerset (insert a u) := by 

Proof state:
α : Type u_1
β : Type u_2
inst✝² : DecidableEq α
inst✝¹ : LinearOrderedCommSemiring β
inst✝ : ExistsAddOfLE β
𝒜✝ ℬ✝ : Finset (Finset α)
a✝ : α
f g μ : Finset α → β
s t u✝ : Finset α
a : α
u : Finset α
hu : a ∉ u
f₁ f₂ f₃ f₄ : Finset α → β
h₁ : 0 ≤ f₁
h₂ : 0 ≤ f₂
h₃ : 0 ≤ f₃
h₄ : 0 ≤ f₄
h : ∀ ⦃s : Finset α⦄, s ⊆ insert a u → ∀ ⦃t : Finset α⦄, t ⊆ insert a u → f₁ s * f₂ t ≤ f₃ (s ∩ t) * f₄ (s ∪ t)
𝒜 ℬ : Finset (Finset α)
h𝒜 : 𝒜 ⊆ powerset (insert a u)
hℬ : ℬ ⊆ powerset (insert a u)
ih :
  (∑ s in powerset u, collapse 𝒜 a f₁ s) * ∑ s in powerset u, collapse ℬ a f₂ s ≤
    (∑ s in powerset u ⊼ powerset u, collapse (𝒜 ⊼ ℬ) a f₃ s) * ∑ s in powerset u ⊻ powerset u, collapse (𝒜 ⊻ ℬ) a f₄ s
this : 𝒜 ⊼ ℬ ⊆ powerset (insert a u)
⊢ 𝒜 ⊻ ℬ ⊆ powerset (insert a u)

Next tactic:
simpa using sups_subset h𝒜 hℬ
/-- The **Four Functions Theorem** on a powerset algebra. See `four_functions_theorem` for the
finite distributive lattice generalisation. -/
protected lemma Finset.four_functions_theorem (u : Finset α)
    (h₁ : 0 ≤ f₁) (h₂ : 0 ≤ f₂) (h₃ : 0 ≤ f₃) (h₄ : 0 ≤ f₄)
    (h : ∀ ⦃s⦄, s ⊆ u → ∀ ⦃t⦄, t ⊆ u → f₁ s * f₂ t ≤ f₃ (s ∩ t) * f₄ (s ∪ t))
    {𝒜 ℬ : Finset (Finset α)} (h𝒜 : 𝒜 ⊆ u.powerset) (hℬ : ℬ ⊆ u.powerset) :
    (∑ s in 𝒜, f₁ s) * ∑ s in ℬ, f₂ s ≤ (∑ s in 𝒜 ⊼ ℬ, f₃ s) * ∑ s in 𝒜 ⊻ ℬ, f₄ s := by
  induction' u using Finset.induction with a u hu ih generalizing f₁ f₂ f₃ f₄ 𝒜 ℬ
  · simp only [Finset.powerset_empty, Finset.subset_singleton_iff] at h𝒜 hℬ
    obtain rfl | rfl := h𝒜 <;> obtain rfl | rfl := hℬ <;> simp; exact h (subset_refl ∅) subset_rfl
  specialize ih (collapse_nonneg h₁) (collapse_nonneg h₂) (collapse_nonneg h₃) (collapse_nonneg h₄)
    (collapse_modular hu h₁ h₂ h₃ h₄ h 𝒜 ℬ) Subset.rfl Subset.rfl
  have : 𝒜 ⊼ ℬ ⊆ powerset (insert a u) := by simpa using infs_subset h𝒜 hℬ
  have : 𝒜 ⊻ ℬ ⊆ powerset (insert a u) := by simpa using sups_subset h𝒜 hℬ
  

Proof state:
case insert
α : Type u_1
β : Type u_2
inst✝² : DecidableEq α
inst✝¹ : LinearOrderedCommSemiring β
inst✝ : ExistsAddOfLE β
𝒜✝ ℬ✝ : Finset (Finset α)
a✝ : α
f g μ : Finset α → β
s t u✝ : Finset α
a : α
u : Finset α
hu : a ∉ u
f₁ f₂ f₃ f₄ : Finset α → β
h₁ : 0 ≤ f₁
h₂ : 0 ≤ f₂
h₃ : 0 ≤ f₃
h₄ : 0 ≤ f₄
h : ∀ ⦃s : Finset α⦄, s ⊆ insert a u → ∀ ⦃t : Finset α⦄, t ⊆ insert a u → f₁ s * f₂ t ≤ f₃ (s ∩ t) * f₄ (s ∪ t)
𝒜 ℬ : Finset (Finset α)
h𝒜 : 𝒜 ⊆ powerset (insert a u)
hℬ : ℬ ⊆ powerset (insert a u)
ih :
  (∑ s in powerset u, collapse 𝒜 a f₁ s) * ∑ s in powerset u, collapse ℬ a f₂ s ≤
    (∑ s in powerset u ⊼ powerset u, collapse (𝒜 ⊼ ℬ) a f₃ s) * ∑ s in powerset u ⊻ powerset u, collapse (𝒜 ⊻ ℬ) a f₄ s
this✝ : 𝒜 ⊼ ℬ ⊆ powerset (insert a u)
this : 𝒜 ⊻ ℬ ⊆ powerset (insert a u)
⊢ (∑ s in 𝒜, f₁ s) * ∑ s in ℬ, f₂ s ≤ (∑ s in 𝒜 ⊼ ℬ, f₃ s) * ∑ s in 𝒜 ⊻ ℬ, f₄ s

Next tactic:
simpa only [powerset_sups_powerset_self, powerset_infs_powerset_self, sum_collapse,
    not_false_eq_true, *] using ih
private lemma four_functions_theorem_aux (h₁ : 0 ≤ f₁) (h₂ : 0 ≤ f₂) (h₃ : 0 ≤ f₃) (h₄ : 0 ≤ f₄)
    (h : ∀ s t, f₁ s * f₂ t ≤ f₃ (s ∩ t) * f₄ (s ∪ t)) (𝒜 ℬ : Finset (Finset α)) :
    (∑ s in 𝒜, f₁ s) * ∑ s in ℬ, f₂ s ≤ (∑ s in 𝒜 ⊼ ℬ, f₃ s) * ∑ s in 𝒜 ⊻ ℬ, f₄ s := by
  

Proof state:
α : Type u_1
β : Type u_2
inst✝³ : DecidableEq α
inst✝² : LinearOrderedCommSemiring β
inst✝¹ : ExistsAddOfLE β
𝒜✝ ℬ✝ : Finset (Finset α)
a : α
f f₁ f₂ f₃ f₄ g μ : Finset α → β
s t u : Finset α
inst✝ : Fintype α
h₁ : 0 ≤ f₁
h₂ : 0 ≤ f₂
h₃ : 0 ≤ f₃
h₄ : 0 ≤ f₄
h : ∀ (s t : Finset α), f₁ s * f₂ t ≤ f₃ (s ∩ t) * f₄ (s ∪ t)
𝒜 ℬ : Finset (Finset α)
⊢ (∑ s in 𝒜, f₁ s) * ∑ s in ℬ, f₂ s ≤ (∑ s in 𝒜 ⊼ ℬ, f₃ s) * ∑ s in 𝒜 ⊻ ℬ, f₄ s

Next tactic:
refine' univ.four_functions_theorem h₁ h₂ h₃ h₄ _ _ _
private lemma four_functions_theorem_aux (h₁ : 0 ≤ f₁) (h₂ : 0 ≤ f₂) (h₃ : 0 ≤ f₃) (h₄ : 0 ≤ f₄)
    (h : ∀ s t, f₁ s * f₂ t ≤ f₃ (s ∩ t) * f₄ (s ∪ t)) (𝒜 ℬ : Finset (Finset α)) :
    (∑ s in 𝒜, f₁ s) * ∑ s in ℬ, f₂ s ≤ (∑ s in 𝒜 ⊼ ℬ, f₃ s) * ∑ s in 𝒜 ⊻ ℬ, f₄ s := by
  refine' univ.four_functions_theorem h₁ h₂ h₃ h₄ _ _ _ <;> 

Proof state:
case refine'_1
α : Type u_1
β : Type u_2
inst✝³ : DecidableEq α
inst✝² : LinearOrderedCommSemiring β
inst✝¹ : ExistsAddOfLE β
𝒜✝ ℬ✝ : Finset (Finset α)
a : α
f f₁ f₂ f₃ f₄ g μ : Finset α → β
s t u : Finset α
inst✝ : Fintype α
h₁ : 0 ≤ f₁
h₂ : 0 ≤ f₂
h₃ : 0 ≤ f₃
h₄ : 0 ≤ f₄
h : ∀ (s t : Finset α), f₁ s * f₂ t ≤ f₃ (s ∩ t) * f₄ (s ∪ t)
𝒜 ℬ : Finset (Finset α)
⊢ ∀ ⦃s : Finset α⦄, s ⊆ univ → ∀ ⦃t : Finset α⦄, t ⊆ univ → f₁ s * f₂ t ≤ f₃ (s ∩ t) * f₄ (s ∪ t)

Next tactic:
simp [h]
private lemma four_functions_theorem_aux (h₁ : 0 ≤ f₁) (h₂ : 0 ≤ f₂) (h₃ : 0 ≤ f₃) (h₄ : 0 ≤ f₄)
    (h : ∀ s t, f₁ s * f₂ t ≤ f₃ (s ∩ t) * f₄ (s ∪ t)) (𝒜 ℬ : Finset (Finset α)) :
    (∑ s in 𝒜, f₁ s) * ∑ s in ℬ, f₂ s ≤ (∑ s in 𝒜 ⊼ ℬ, f₃ s) * ∑ s in 𝒜 ⊻ ℬ, f₄ s := by
  refine' univ.four_functions_theorem h₁ h₂ h₃ h₄ _ _ _ <;> 

Proof state:
case refine'_2
α : Type u_1
β : Type u_2
inst✝³ : DecidableEq α
inst✝² : LinearOrderedCommSemiring β
inst✝¹ : ExistsAddOfLE β
𝒜✝ ℬ✝ : Finset (Finset α)
a : α
f f₁ f₂ f₃ f₄ g μ : Finset α → β
s t u : Finset α
inst✝ : Fintype α
h₁ : 0 ≤ f₁
h₂ : 0 ≤ f₂
h₃ : 0 ≤ f₃
h₄ : 0 ≤ f₄
h : ∀ (s t : Finset α), f₁ s * f₂ t ≤ f₃ (s ∩ t) * f₄ (s ∪ t)
𝒜 ℬ : Finset (Finset α)
⊢ 𝒜 ⊆ powerset univ

Next tactic:
simp [h]
private lemma four_functions_theorem_aux (h₁ : 0 ≤ f₁) (h₂ : 0 ≤ f₂) (h₃ : 0 ≤ f₃) (h₄ : 0 ≤ f₄)
    (h : ∀ s t, f₁ s * f₂ t ≤ f₃ (s ∩ t) * f₄ (s ∪ t)) (𝒜 ℬ : Finset (Finset α)) :
    (∑ s in 𝒜, f₁ s) * ∑ s in ℬ, f₂ s ≤ (∑ s in 𝒜 ⊼ ℬ, f₃ s) * ∑ s in 𝒜 ⊻ ℬ, f₄ s := by
  refine' univ.four_functions_theorem h₁ h₂ h₃ h₄ _ _ _ <;> 

Proof state:
case refine'_3
α : Type u_1
β : Type u_2
inst✝³ : DecidableEq α
inst✝² : LinearOrderedCommSemiring β
inst✝¹ : ExistsAddOfLE β
𝒜✝ ℬ✝ : Finset (Finset α)
a : α
f f₁ f₂ f₃ f₄ g μ : Finset α → β
s t u : Finset α
inst✝ : Fintype α
h₁ : 0 ≤ f₁
h₂ : 0 ≤ f₂
h₃ : 0 ≤ f₃
h₄ : 0 ≤ f₄
h : ∀ (s t : Finset α), f₁ s * f₂ t ≤ f₃ (s ∩ t) * f₄ (s ∪ t)
𝒜 ℬ : Finset (Finset α)
⊢ ℬ ⊆ powerset univ

Next tactic:
simp [h]
/-- The **Four Functions Theorem**, aka **Ahlswede-Daykin Inequality**. -/
lemma four_functions_theorem (h₁ : 0 ≤ f₁) (h₂ : 0 ≤ f₂) (h₃ : 0 ≤ f₃) (h₄ : 0 ≤ f₄)
    (h : ∀ a b, f₁ a * f₂ b ≤ f₃ (a ⊓ b) * f₄ (a ⊔ b)) (s t : Finset α) :
    (∑ a in s, f₁ a) * ∑ a in t, f₂ a ≤ (∑ a in s ⊼ t, f₃ a) * ∑ a in s ⊻ t, f₄ a := by
  

Proof state:
α : Type u_1
β : Type u_2
inst✝³ : DistribLattice α
inst✝² : DecidableEq α
inst✝¹ : LinearOrderedCommSemiring β
inst✝ : ExistsAddOfLE β
f f₁ f₂ f₃ f₄ g μ : α → β
h₁ : 0 ≤ f₁
h₂ : 0 ≤ f₂
h₃ : 0 ≤ f₃
h₄ : 0 ≤ f₄
h : ∀ (a b : α), f₁ a * f₂ b ≤ f₃ (a ⊓ b) * f₄ (a ⊔ b)
s t : Finset α
⊢ (∑ a in s, f₁ a) * ∑ a in t, f₂ a ≤ (∑ a in s ⊼ t, f₃ a) * ∑ a in s ⊻ t, f₄ a

Next tactic:
classical
  set L : Sublattice α := ⟨latticeClosure (s ∪ t), isSublattice_latticeClosure.1,
    isSublattice_latticeClosure.2⟩
  have : Finite L := (s.finite_toSet.union t.finite_toSet).latticeClosure.to_subtype
  set s' : Finset L := s.preimage (↑) $ Subtype.coe_injective.injOn _
  set t' : Finset L := t.preimage (↑) $ Subtype.coe_injective.injOn _
  have hs' : s'.map ⟨L.subtype, Subtype.coe_injective⟩ = s := by
    simp [map_eq_image, image_preimage, filter_eq_self]
    exact fun a ha ↦ subset_latticeClosure $ Set.subset_union_left _ _ ha
  have ht' : t'.map ⟨L.subtype, Subtype.coe_injective⟩ = t := by
    simp [map_eq_image, image_preimage, filter_eq_self]
    exact fun a ha ↦ subset_latticeClosure $ Set.subset_union_right _ _ ha
  clear_value s' t'
  obtain ⟨β, _, _, g, hg⟩ := exists_birkhoff_representation L
  have := four_functions_theorem_aux (extend g (f₁ ∘ (↑)) 0) (extend g (f₂ ∘ (↑)) 0)
    (extend g (f₃ ∘ (↑)) 0) (extend g (f₄ ∘ (↑)) 0) (extend_nonneg (fun _ ↦ h₁ _) le_rfl)
    (extend_nonneg (fun _ ↦ h₂ _) le_rfl) (extend_nonneg (fun _ ↦ h₃ _) le_rfl)
    (extend_nonneg (fun _ ↦ h₄ _) le_rfl) ?_ (s'.map ⟨g, hg⟩) (t'.map ⟨g, hg⟩)
  simpa only [← hs', ← ht', ← map_sups, ← map_infs, sum_map, Embedding.coeFn_mk, hg.extend_apply]
    using this
  rintro s t
  classical
  obtain ⟨a, rfl⟩ | hs := em (∃ a, g a = s)
  · obtain ⟨b, rfl⟩ | ht := em (∃ b, g b = t)
    · simp_rw [← sup_eq_union, ← inf_eq_inter, ← map_sup, ← map_inf, hg.extend_apply]
      exact h _ _
    · simpa [extend_apply' _ _ _ ht] using mul_nonneg
        (extend_nonneg (fun a : L ↦ h₃ a) le_rfl _) (extend_nonneg (fun a : L ↦ h₄ a) le_rfl _)
  · simpa [extend_apply' _ _ _ hs] using mul_nonneg
      (extend_nonneg (fun a : L ↦ h₃ a) le_rfl _) (extend_nonneg (fun a : L ↦ h₄ a) le_rfl _)
/-- The **Four Functions Theorem**, aka **Ahlswede-Daykin Inequality**. -/
lemma four_functions_theorem (h₁ : 0 ≤ f₁) (h₂ : 0 ≤ f₂) (h₃ : 0 ≤ f₃) (h₄ : 0 ≤ f₄)
    (h : ∀ a b, f₁ a * f₂ b ≤ f₃ (a ⊓ b) * f₄ (a ⊔ b)) (s t : Finset α) :
    (∑ a in s, f₁ a) * ∑ a in t, f₂ a ≤ (∑ a in s ⊼ t, f₃ a) * ∑ a in s ⊻ t, f₄ a := by
  classical
  

Proof state:
α : Type u_1
β : Type u_2
inst✝³ : DistribLattice α
inst✝² : DecidableEq α
inst✝¹ : LinearOrderedCommSemiring β
inst✝ : ExistsAddOfLE β
f f₁ f₂ f₃ f₄ g μ : α → β
h₁ : 0 ≤ f₁
h₂ : 0 ≤ f₂
h₃ : 0 ≤ f₃
h₄ : 0 ≤ f₄
h : ∀ (a b : α), f₁ a * f₂ b ≤ f₃ (a ⊓ b) * f₄ (a ⊔ b)
s t : Finset α
⊢ (∑ a in s, f₁ a) * ∑ a in t, f₂ a ≤ (∑ a in s ⊼ t, f₃ a) * ∑ a in s ⊻ t, f₄ a

Next tactic:
set L : Sublattice α := ⟨latticeClosure (s ∪ t), isSublattice_latticeClosure.1,
    isSublattice_latticeClosure.2⟩
/-- The **Four Functions Theorem**, aka **Ahlswede-Daykin Inequality**. -/
lemma four_functions_theorem (h₁ : 0 ≤ f₁) (h₂ : 0 ≤ f₂) (h₃ : 0 ≤ f₃) (h₄ : 0 ≤ f₄)
    (h : ∀ a b, f₁ a * f₂ b ≤ f₃ (a ⊓ b) * f₄ (a ⊔ b)) (s t : Finset α) :
    (∑ a in s, f₁ a) * ∑ a in t, f₂ a ≤ (∑ a in s ⊼ t, f₃ a) * ∑ a in s ⊻ t, f₄ a := by
  classical
  set L : Sublattice α := ⟨latticeClosure (s ∪ t), isSublattice_latticeClosure.1,
    isSublattice_latticeClosure.2⟩
  

Proof state:
α : Type u_1
β : Type u_2
inst✝³ : DistribLattice α
inst✝² : DecidableEq α
inst✝¹ : LinearOrderedCommSemiring β
inst✝ : ExistsAddOfLE β
f f₁ f₂ f₃ f₄ g μ : α → β
h₁ : 0 ≤ f₁
h₂ : 0 ≤ f₂
h₃ : 0 ≤ f₃
h₄ : 0 ≤ f₄
h : ∀ (a b : α), f₁ a * f₂ b ≤ f₃ (a ⊓ b) * f₄ (a ⊔ b)
s t : Finset α
L : Sublattice α :=
  { carrier := latticeClosure (↑s ∪ ↑t), supClosed' := (_ : SupClosed (latticeClosure (↑s ∪ ↑t))),
    infClosed' := (_ : InfClosed (latticeClosure (↑s ∪ ↑t))) }
⊢ (∑ a in s, f₁ a) * ∑ a in t, f₂ a ≤ (∑ a in s ⊼ t, f₃ a) * ∑ a in s ⊻ t, f₄ a

Next tactic:
have : Finite L := (s.finite_toSet.union t.finite_toSet).latticeClosure.to_subtype
/-- The **Four Functions Theorem**, aka **Ahlswede-Daykin Inequality**. -/
lemma four_functions_theorem (h₁ : 0 ≤ f₁) (h₂ : 0 ≤ f₂) (h₃ : 0 ≤ f₃) (h₄ : 0 ≤ f₄)
    (h : ∀ a b, f₁ a * f₂ b ≤ f₃ (a ⊓ b) * f₄ (a ⊔ b)) (s t : Finset α) :
    (∑ a in s, f₁ a) * ∑ a in t, f₂ a ≤ (∑ a in s ⊼ t, f₃ a) * ∑ a in s ⊻ t, f₄ a := by
  classical
  set L : Sublattice α := ⟨latticeClosure (s ∪ t), isSublattice_latticeClosure.1,
    isSublattice_latticeClosure.2⟩
  have : Finite L := (s.finite_toSet.union t.finite_toSet).latticeClosure.to_subtype
  

Proof state:
α : Type u_1
β : Type u_2
inst✝³ : DistribLattice α
inst✝² : DecidableEq α
inst✝¹ : LinearOrderedCommSemiring β
inst✝ : ExistsAddOfLE β
f f₁ f₂ f₃ f₄ g μ : α → β
h₁ : 0 ≤ f₁
h₂ : 0 ≤ f₂
h₃ : 0 ≤ f₃
h₄ : 0 ≤ f₄
h : ∀ (a b : α), f₁ a * f₂ b ≤ f₃ (a ⊓ b) * f₄ (a ⊔ b)
s t : Finset α
L : Sublattice α :=
  { carrier := latticeClosure (↑s ∪ ↑t), supClosed' := (_ : SupClosed (latticeClosure (↑s ∪ ↑t))),
    infClosed' := (_ : InfClosed (latticeClosure (↑s ∪ ↑t))) }
this : Finite ↥L
⊢ (∑ a in s, f₁ a) * ∑ a in t, f₂ a ≤ (∑ a in s ⊼ t, f₃ a) * ∑ a in s ⊻ t, f₄ a

Next tactic:
set s' : Finset L := s.preimage (↑) $ Subtype.coe_injective.injOn _
/-- The **Four Functions Theorem**, aka **Ahlswede-Daykin Inequality**. -/
lemma four_functions_theorem (h₁ : 0 ≤ f₁) (h₂ : 0 ≤ f₂) (h₃ : 0 ≤ f₃) (h₄ : 0 ≤ f₄)
    (h : ∀ a b, f₁ a * f₂ b ≤ f₃ (a ⊓ b) * f₄ (a ⊔ b)) (s t : Finset α) :
    (∑ a in s, f₁ a) * ∑ a in t, f₂ a ≤ (∑ a in s ⊼ t, f₃ a) * ∑ a in s ⊻ t, f₄ a := by
  classical
  set L : Sublattice α := ⟨latticeClosure (s ∪ t), isSublattice_latticeClosure.1,
    isSublattice_latticeClosure.2⟩
  have : Finite L := (s.finite_toSet.union t.finite_toSet).latticeClosure.to_subtype
  set s' : Finset L := s.preimage (↑) $ Subtype.coe_injective.injOn _
  

Proof state:
α : Type u_1
β : Type u_2
inst✝³ : DistribLattice α
inst✝² : DecidableEq α
inst✝¹ : LinearOrderedCommSemiring β
inst✝ : ExistsAddOfLE β
f f₁ f₂ f₃ f₄ g μ : α → β
h₁ : 0 ≤ f₁
h₂ : 0 ≤ f₂
h₃ : 0 ≤ f₃
h₄ : 0 ≤ f₄
h : ∀ (a b : α), f₁ a * f₂ b ≤ f₃ (a ⊓ b) * f₄ (a ⊔ b)
s t : Finset α
L : Sublattice α :=
  { carrier := latticeClosure (↑s ∪ ↑t), supClosed' := (_ : SupClosed (latticeClosure (↑s ∪ ↑t))),
    infClosed' := (_ : InfClosed (latticeClosure (↑s ∪ ↑t))) }
this : Finite ↥L
s' : Finset ↥L := preimage s Subtype.val (_ : Set.InjOn (fun a => ↑a) (Subtype.val ⁻¹' ↑s))
⊢ (∑ a in s, f₁ a) * ∑ a in t, f₂ a ≤ (∑ a in s ⊼ t, f₃ a) * ∑ a in s ⊻ t, f₄ a

Next tactic:
set t' : Finset L := t.preimage (↑) $ Subtype.coe_injective.injOn _
/-- The **Four Functions Theorem**, aka **Ahlswede-Daykin Inequality**. -/
lemma four_functions_theorem (h₁ : 0 ≤ f₁) (h₂ : 0 ≤ f₂) (h₃ : 0 ≤ f₃) (h₄ : 0 ≤ f₄)
    (h : ∀ a b, f₁ a * f₂ b ≤ f₃ (a ⊓ b) * f₄ (a ⊔ b)) (s t : Finset α) :
    (∑ a in s, f₁ a) * ∑ a in t, f₂ a ≤ (∑ a in s ⊼ t, f₃ a) * ∑ a in s ⊻ t, f₄ a := by
  classical
  set L : Sublattice α := ⟨latticeClosure (s ∪ t), isSublattice_latticeClosure.1,
    isSublattice_latticeClosure.2⟩
  have : Finite L := (s.finite_toSet.union t.finite_toSet).latticeClosure.to_subtype
  set s' : Finset L := s.preimage (↑) $ Subtype.coe_injective.injOn _
  set t' : Finset L := t.preimage (↑) $ Subtype.coe_injective.injOn _
  

Proof state:
α : Type u_1
β : Type u_2
inst✝³ : DistribLattice α
inst✝² : DecidableEq α
inst✝¹ : LinearOrderedCommSemiring β
inst✝ : ExistsAddOfLE β
f f₁ f₂ f₃ f₄ g μ : α → β
h₁ : 0 ≤ f₁
h₂ : 0 ≤ f₂
h₃ : 0 ≤ f₃
h₄ : 0 ≤ f₄
h : ∀ (a b : α), f₁ a * f₂ b ≤ f₃ (a ⊓ b) * f₄ (a ⊔ b)
s t : Finset α
L : Sublattice α :=
  { carrier := latticeClosure (↑s ∪ ↑t), supClosed' := (_ : SupClosed (latticeClosure (↑s ∪ ↑t))),
    infClosed' := (_ : InfClosed (latticeClosure (↑s ∪ ↑t))) }
this : Finite ↥L
s' : Finset ↥L := preimage s Subtype.val (_ : Set.InjOn (fun a => ↑a) (Subtype.val ⁻¹' ↑s))
t' : Finset ↥L := preimage t Subtype.val (_ : Set.InjOn (fun a => ↑a) (Subtype.val ⁻¹' ↑t))
⊢ (∑ a in s, f₁ a) * ∑ a in t, f₂ a ≤ (∑ a in s ⊼ t, f₃ a) * ∑ a in s ⊻ t, f₄ a

Next tactic:
have hs' : s'.map ⟨L.subtype, Subtype.coe_injective⟩ = s := by
    simp [map_eq_image, image_preimage, filter_eq_self]
    exact fun a ha ↦ subset_latticeClosure $ Set.subset_union_left _ _ ha
/-- The **Four Functions Theorem**, aka **Ahlswede-Daykin Inequality**. -/
lemma four_functions_theorem (h₁ : 0 ≤ f₁) (h₂ : 0 ≤ f₂) (h₃ : 0 ≤ f₃) (h₄ : 0 ≤ f₄)
    (h : ∀ a b, f₁ a * f₂ b ≤ f₃ (a ⊓ b) * f₄ (a ⊔ b)) (s t : Finset α) :
    (∑ a in s, f₁ a) * ∑ a in t, f₂ a ≤ (∑ a in s ⊼ t, f₃ a) * ∑ a in s ⊻ t, f₄ a := by
  classical
  set L : Sublattice α := ⟨latticeClosure (s ∪ t), isSublattice_latticeClosure.1,
    isSublattice_latticeClosure.2⟩
  have : Finite L := (s.finite_toSet.union t.finite_toSet).latticeClosure.to_subtype
  set s' : Finset L := s.preimage (↑) $ Subtype.coe_injective.injOn _
  set t' : Finset L := t.preimage (↑) $ Subtype.coe_injective.injOn _
  have hs' : s'.map ⟨L.subtype, Subtype.coe_injective⟩ = s := by
    

Proof state:
α : Type u_1
β : Type u_2
inst✝³ : DistribLattice α
inst✝² : DecidableEq α
inst✝¹ : LinearOrderedCommSemiring β
inst✝ : ExistsAddOfLE β
f f₁ f₂ f₃ f₄ g μ : α → β
h₁ : 0 ≤ f₁
h₂ : 0 ≤ f₂
h₃ : 0 ≤ f₃
h₄ : 0 ≤ f₄
h : ∀ (a b : α), f₁ a * f₂ b ≤ f₃ (a ⊓ b) * f₄ (a ⊔ b)
s t : Finset α
L : Sublattice α :=
  { carrier := latticeClosure (↑s ∪ ↑t), supClosed' := (_ : SupClosed (latticeClosure (↑s ∪ ↑t))),
    infClosed' := (_ : InfClosed (latticeClosure (↑s ∪ ↑t))) }
this : Finite ↥L
s' : Finset ↥L := preimage s Subtype.val (_ : Set.InjOn (fun a => ↑a) (Subtype.val ⁻¹' ↑s))
t' : Finset ↥L := preimage t Subtype.val (_ : Set.InjOn (fun a => ↑a) (Subtype.val ⁻¹' ↑t))
⊢ map { toFun := ⇑(Sublattice.subtype L), inj' := (_ : Injective fun a => ↑a) } s' = s

Next tactic:
simp [map_eq_image, image_preimage, filter_eq_self]
/-- The **Four Functions Theorem**, aka **Ahlswede-Daykin Inequality**. -/
lemma four_functions_theorem (h₁ : 0 ≤ f₁) (h₂ : 0 ≤ f₂) (h₃ : 0 ≤ f₃) (h₄ : 0 ≤ f₄)
    (h : ∀ a b, f₁ a * f₂ b ≤ f₃ (a ⊓ b) * f₄ (a ⊔ b)) (s t : Finset α) :
    (∑ a in s, f₁ a) * ∑ a in t, f₂ a ≤ (∑ a in s ⊼ t, f₃ a) * ∑ a in s ⊻ t, f₄ a := by
  classical
  set L : Sublattice α := ⟨latticeClosure (s ∪ t), isSublattice_latticeClosure.1,
    isSublattice_latticeClosure.2⟩
  have : Finite L := (s.finite_toSet.union t.finite_toSet).latticeClosure.to_subtype
  set s' : Finset L := s.preimage (↑) $ Subtype.coe_injective.injOn _
  set t' : Finset L := t.preimage (↑) $ Subtype.coe_injective.injOn _
  have hs' : s'.map ⟨L.subtype, Subtype.coe_injective⟩ = s := by
    simp [map_eq_image, image_preimage, filter_eq_self]
    

Proof state:
α : Type u_1
β : Type u_2
inst✝³ : DistribLattice α
inst✝² : DecidableEq α
inst✝¹ : LinearOrderedCommSemiring β
inst✝ : ExistsAddOfLE β
f f₁ f₂ f₃ f₄ g μ : α → β
h₁ : 0 ≤ f₁
h₂ : 0 ≤ f₂
h₃ : 0 ≤ f₃
h₄ : 0 ≤ f₄
h : ∀ (a b : α), f₁ a * f₂ b ≤ f₃ (a ⊓ b) * f₄ (a ⊔ b)
s t : Finset α
L : Sublattice α :=
  { carrier := latticeClosure (↑s ∪ ↑t), supClosed' := (_ : SupClosed (latticeClosure (↑s ∪ ↑t))),
    infClosed' := (_ : InfClosed (latticeClosure (↑s ∪ ↑t))) }
this : Finite ↥L
s' : Finset ↥L := preimage s Subtype.val (_ : Set.InjOn (fun a => ↑a) (Subtype.val ⁻¹' ↑s))
t' : Finset ↥L := preimage t Subtype.val (_ : Set.InjOn (fun a => ↑a) (Subtype.val ⁻¹' ↑t))
⊢ ∀ x ∈ s, x ∈ latticeClosure (↑s ∪ ↑t)

Next tactic:
exact fun a ha ↦ subset_latticeClosure $ Set.subset_union_left _ _ ha
/-- The **Four Functions Theorem**, aka **Ahlswede-Daykin Inequality**. -/
lemma four_functions_theorem (h₁ : 0 ≤ f₁) (h₂ : 0 ≤ f₂) (h₃ : 0 ≤ f₃) (h₄ : 0 ≤ f₄)
    (h : ∀ a b, f₁ a * f₂ b ≤ f₃ (a ⊓ b) * f₄ (a ⊔ b)) (s t : Finset α) :
    (∑ a in s, f₁ a) * ∑ a in t, f₂ a ≤ (∑ a in s ⊼ t, f₃ a) * ∑ a in s ⊻ t, f₄ a := by
  classical
  set L : Sublattice α := ⟨latticeClosure (s ∪ t), isSublattice_latticeClosure.1,
    isSublattice_latticeClosure.2⟩
  have : Finite L := (s.finite_toSet.union t.finite_toSet).latticeClosure.to_subtype
  set s' : Finset L := s.preimage (↑) $ Subtype.coe_injective.injOn _
  set t' : Finset L := t.preimage (↑) $ Subtype.coe_injective.injOn _
  have hs' : s'.map ⟨L.subtype, Subtype.coe_injective⟩ = s := by
    simp [map_eq_image, image_preimage, filter_eq_self]
    exact fun a ha ↦ subset_latticeClosure $ Set.subset_union_left _ _ ha
  

Proof state:
α : Type u_1
β : Type u_2
inst✝³ : DistribLattice α
inst✝² : DecidableEq α
inst✝¹ : LinearOrderedCommSemiring β
inst✝ : ExistsAddOfLE β
f f₁ f₂ f₃ f₄ g μ : α → β
h₁ : 0 ≤ f₁
h₂ : 0 ≤ f₂
h₃ : 0 ≤ f₃
h₄ : 0 ≤ f₄
h : ∀ (a b : α), f₁ a * f₂ b ≤ f₃ (a ⊓ b) * f₄ (a ⊔ b)
s t : Finset α
L : Sublattice α :=
  { carrier := latticeClosure (↑s ∪ ↑t), supClosed' := (_ : SupClosed (latticeClosure (↑s ∪ ↑t))),
    infClosed' := (_ : InfClosed (latticeClosure (↑s ∪ ↑t))) }
this : Finite ↥L
s' : Finset ↥L := preimage s Subtype.val (_ : Set.InjOn (fun a => ↑a) (Subtype.val ⁻¹' ↑s))
t' : Finset ↥L := preimage t Subtype.val (_ : Set.InjOn (fun a => ↑a) (Subtype.val ⁻¹' ↑t))
hs' : map { toFun := ⇑(Sublattice.subtype L), inj' := (_ : Injective fun a => ↑a) } s' = s
⊢ (∑ a in s, f₁ a) * ∑ a in t, f₂ a ≤ (∑ a in s ⊼ t, f₃ a) * ∑ a in s ⊻ t, f₄ a

Next tactic:
have ht' : t'.map ⟨L.subtype, Subtype.coe_injective⟩ = t := by
    simp [map_eq_image, image_preimage, filter_eq_self]
    exact fun a ha ↦ subset_latticeClosure $ Set.subset_union_right _ _ ha