Normalized finite averages and finite-set indicators
DefinitionGreenTaoPort_Wikipedia_SzemeredisTheorem_Finite_Meanarithmetic-progressionscombinatoricsgreen-tao-port-8822
For a real-valued function on a finite type, the mean is the normalized finite sum. For two finite variable types, the two-variable mean is the iterated normalized average. The finite-set indicator takes value one on the given finite subset and zero outside it.
The underlying finite-average convention is total: an average over an empty type is zero. The bundle supplies these operations together with the algebraic support required by the later definition constructions.
Definition code
import Mathlib.Algebra.BigOperators.Expect
import Mathlib.Data.Fintype.Card
import Mathlib.Tactic
import Lean
set_option autoImplicit true
set_option relaxedAutoImplicit false
set_option maxSynthPendingDepth 3
/-!
# Normalized averages on finite types
The Green--Tao argument repeatedly averages real-valued functions over finite
cyclic groups and finite products of such groups. This file fixes one
normalization and records the elementary algebraic and order lemmas used by
the transference layer.
-/
namespace Wikipedia.SzemeredisTheorem
open scoped BigOperators
/-- The normalized average of a real-valued function on a finite type. -/
noncomputable def mean {α : Type*} [Fintype α] (f : α → ℝ) : ℝ :=
𝔼 x, f x
/-- Real-valued indicator of a finite subset of a finite type. -/
def finsetIndicator {α : Type*} [DecidableEq α]
(A : Finset α) (x : α) : ℝ :=
if x ∈ A then 1 else 0
@[simp]
theorem finsetIndicator_of_mem {α : Type*} [DecidableEq α]
{A : Finset α} {x : α} (hx : x ∈ A) :
finsetIndicator A x = 1 := by
simp [finsetIndicator, hx]
@[simp]
theorem finsetIndicator_of_not_mem {α : Type*} [DecidableEq α]
{A : Finset α} {x : α} (hx : x ∉ A) :
finsetIndicator A x = 0 := by
simp [finsetIndicator, hx]
@[simp]
theorem mean_const {α : Type*} [Fintype α] [Nonempty α] (c : ℝ) :
mean (fun _ : α => c) = c := by
exact Fintype.expect_const c
theorem mean_add {α : Type*} [Fintype α] (f g : α → ℝ) :
mean (fun x => f x + g x) = mean f + mean g := by
exact Finset.expect_add_distrib Finset.univ f g
theorem mean_sub {α : Type*} [Fintype α] (f g : α → ℝ) :
mean (fun x => f x - g x) = mean f - mean g := by
exact Finset.expect_sub_distrib Finset.univ f g
theorem mean_smul {α : Type*} [Fintype α] (c : ℝ) (f : α → ℝ) :
mean (fun x => c * f x) = c * mean f := by
exact (Finset.mul_expect Finset.univ f c).symm
theorem mean_nonneg {α : Type*} [Fintype α] {f : α → ℝ}
(hf : ∀ x, 0 ≤ f x) : 0 ≤ mean f := by
rw [mean, Fintype.expect_eq_sum_div_card]
exact div_nonneg (Finset.sum_nonneg fun x _ => hf x) (Nat.cast_nonneg _)
theorem mean_mono {α : Type*} [Fintype α] {f g : α → ℝ}
(hfg : ∀ x, f x ≤ g x) : mean f ≤ mean g := by
rw [mean, mean, Fintype.expect_eq_sum_div_card, Fintype.expect_eq_sum_div_card]
exact div_le_div_of_nonneg_right
(Finset.sum_le_sum fun x _ => hfg x) (Nat.cast_nonneg _)
theorem mean_le_of_le_const {α : Type*} [Fintype α] [Nonempty α]
{f : α → ℝ} {c : ℝ} (hf : ∀ x, f x ≤ c) :
mean f ≤ c := by
simpa using mean_mono (f := f) (g := fun _ => c) hf
/-- The normalized average over two independent finite variables. -/
noncomputable def mean₂ {α β : Type*} [Fintype α] [Fintype β]
(f : α → β → ℝ) : ℝ :=
mean (fun x => mean (f x))
end Wikipedia.SzemeredisTheorem
/- Materialize compiler-generated declarations promised by this bundle. -/
run_meta do
for requiredName in #[
`Wikipedia.SzemeredisTheorem.finsetIndicator.eq_1,
`Wikipedia.SzemeredisTheorem.mean.eq_1
] do
let actualName ← Lean.realizeGlobalConstNoOverloadCore requiredName
unless actualName == requiredName do
throwError "Generated companion resolved to an unexpected name"
Source