srcContext
stringlengths 44
89.6k
| theoremStatement
stringlengths 28
895
| theoremName
stringlengths 3
58
⌀ | fileCreated
stringclasses 15
values | theoremCreated
stringclasses 50
values | file
stringclasses 23
values | positionMetadata
dict | dependencyMetadata
dict | proofMetadata
dict | split
stringclasses 4
values |
---|---|---|---|---|---|---|---|---|---|
import Mathlib.Analysis.Complex.CauchyIntegral
import Mathlib.Analysis.Complex.Convex
import Mathlib.Analysis.Complex.RemovableSingularity
import Mathlib.Analysis.Analytic.Meromorphic
import Mathlib.Analysis.SpecialFunctions.Integrals
import Mathlib.MeasureTheory.Measure.Lebesgue.Integral
import PrimeNumberTheoremAnd.Rectangle
open Complex BigOperators Nat Classical Real Topology Filter Set MeasureTheory intervalIntegral
open scoped Interval
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f g : ℂ → E}
{z w p c A : ℂ} {x x₁ x₂ y y₁ y₂ σ : ℝ}
noncomputable def HIntegral (f : ℂ → E) (x₁ x₂ y : ℝ) : E := ∫ x in x₁..x₂, f (x + y * I)
noncomputable def VIntegral (f : ℂ → E) (x y₁ y₂ : ℝ) : E := I • ∫ y in y₁..y₂, f (x + y * I)
noncomputable def HIntegral' (f : ℂ → E) (x₁ x₂ y : ℝ) : E := (1 / (2 * π * I)) • HIntegral f x₁ x₂ y
noncomputable def VIntegral' (f : ℂ → E) (x y₁ y₂ : ℝ) : E := (1 / (2 * π * I)) • VIntegral f x y₁ y₂
lemma HIntegral_symm : HIntegral f x₁ x₂ y = - HIntegral f x₂ x₁ y := integral_symm _ _
lemma VIntegral_symm : VIntegral f x y₁ y₂ = - VIntegral f x y₂ y₁ := by
simp_rw [VIntegral, integral_symm y₁ y₂, smul_neg, neg_neg]
/-%%
\begin{definition}[RectangleIntegral]\label{RectangleIntegral}\lean{RectangleIntegral}\leanok
A RectangleIntegral of a function $f$ is one over a rectangle determined by $z$ and $w$ in $\C$.
We will sometimes denote it by $\int_{z}^{w} f$. (There is also a primed version, which is $1/(2\pi i)$ times the original.)
\end{definition}
%%-/
/-- A `RectangleIntegral` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`. -/
noncomputable def RectangleIntegral (f : ℂ → E) (z w : ℂ) : E := HIntegral f z.re w.re z.im -
HIntegral f z.re w.re w.im + VIntegral f w.re z.im w.im - VIntegral f z.re z.im w.im
/-- A `RectangleIntegral'` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`, divided by `2 * π * I`. -/
noncomputable abbrev RectangleIntegral' (f : ℂ → E) (z w : ℂ) : E :=
(1 / (2 * π * I)) • RectangleIntegral f z w
/-% ** Wrong delimiter on purpose **
An UpperUIntegral is the integral of a function over a |\_| shape.
\begin{definition}\label{UpperUIntegral}\lean{UpperUIntegral}\leanok
An UpperUIntegral of a function $f$ comes from $\sigma+i\infty$ down to $\sigma+iT$, over to $\sigma'+iT$, and back up to $\sigma'+i\infty$.
\end{definition}
%-/
noncomputable def UpperUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' T +
I • (∫ y : ℝ in Ici T, f (σ' + y * I)) - I • (∫ y : ℝ in Ici T, f (σ + y * I))
/-% ** Wrong delimiter on purpose **
A LowerUIntegral is the integral of a function over a |-| shape.
\begin{definition}[LowerUIntegral]\label{LowerUIntegral}\lean{LowerUIntegral}\leanok
A LowerUIntegral of a function $f$ comes from $\sigma-i\infty$ up to $\sigma-iT$, over to $\sigma'-iT$, and back down to $\sigma'-i\infty$.
\end{definition}
%-/
noncomputable def LowerUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' (-T) -
I • (∫ y : ℝ in Iic (-T), f (σ' + y * I)) + I • (∫ y : ℝ in Iic (-T), f (σ + y * I))
/-%%
It is very convenient to define integrals along vertical lines in the complex plane, as follows.
\begin{definition}[VerticalIntegral]\label{VerticalIntegral}\lean{VerticalIntegral}\leanok
Let $f$ be a function from $\mathbb{C}$ to $\mathbb{C}$, and let $\sigma$ be a real number. Then we define
$$\int_{(\sigma)}f(s)ds = \int_{\sigma-i\infty}^{\sigma+i\infty}f(s)ds.$$
\end{definition}
%%-/
noncomputable def VerticalIntegral (f : ℂ → E) (σ : ℝ) : E := I • ∫ t : ℝ, f (σ + t * I)
--%% We also have a version with a factor of $1/(2\pi i)$.
noncomputable abbrev VerticalIntegral' (f : ℂ → E) (σ : ℝ) : E :=
(1 / (2 * π * I)) • VerticalIntegral f σ
lemma verticalIntegral_split_three (a b : ℝ) (hf : Integrable (fun t : ℝ ↦ f (σ + t * I))) :
VerticalIntegral f σ = I • (∫ t in Iic a, f (σ + t * I)) + VIntegral f σ a b
+ I • ∫ t in Ici b, f (σ + t * I) := by
simp_rw [VerticalIntegral, VIntegral, ← smul_add]
congr
rw [← intervalIntegral.integral_Iic_sub_Iic hf.restrict hf.restrict, add_sub_cancel,
integral_Iic_eq_integral_Iio, intervalIntegral.integral_Iio_add_Ici hf.restrict hf.restrict]
/-% ** Wrong delimiter on purpose **
\begin{lemma}[DiffVertRect_eq_UpperLowerUs]\label{DiffVertRect_eq_UpperLowerUs}\lean{DiffVertRect_eq_UpperLowerUs}\leanok
The difference of two vertical integrals and a rectangle is the difference of an upper and a lower U integrals.
\end{lemma}
%-/
lemma DiffVertRect_eq_UpperLowerUs {σ σ' T : ℝ}
(f_int_σ : Integrable (fun (t : ℝ) ↦ f (σ + t * I)))
(f_int_σ' : Integrable (fun (t : ℝ) ↦ f (σ' + t * I))) :
(VerticalIntegral f σ') - (VerticalIntegral f σ) - (RectangleIntegral f (σ - I * T) (σ' + I * T)) =
(UpperUIntegral f σ σ' T) - (LowerUIntegral f σ σ' T) := by
rw [verticalIntegral_split_three (-T) T f_int_σ, verticalIntegral_split_three (-T) T f_int_σ']
simp only [smul_eq_mul, RectangleIntegral, sub_re, ofReal_re, mul_re, I_re, zero_mul, I_im,
ofReal_im, mul_zero, sub_self, sub_zero, add_re, add_zero, sub_im, mul_im, one_mul, zero_add,
zero_sub, add_im, UpperUIntegral, LowerUIntegral]
abel
/-%
\begin{proof}\uses{UpperUIntegral, LowerUIntegral}\leanok
Follows directly from the definitions.
\end{proof}
%-/
/-- A function is `HolomorphicOn` a set if it is complex differentiable on that set. -/
abbrev HolomorphicOn (f : ℂ → E) (s : Set ℂ) : Prop := DifferentiableOn ℂ f s
/-%%
\begin{theorem}[existsDifferentiableOn_of_bddAbove]\label{existsDifferentiableOn_of_bddAbove}\lean{existsDifferentiableOn_of_bddAbove}\leanok
If $f$ is differentiable on a set $s$ except at $c\in s$, and $f$ is bounded above on $s\setminus\{c\}$, then there exists a differentiable function $g$ on $s$ such that $f$ and $g$ agree on $s\setminus\{c\}$.
\end{theorem}
%%-/
theorem existsDifferentiableOn_of_bddAbove [CompleteSpace E] {s : Set ℂ} {c : ℂ} (hc : s ∈ nhds c)
(hd : HolomorphicOn f (s \ {c})) (hb : BddAbove (norm ∘ f '' (s \ {c}))) :
∃ (g : ℂ → E), HolomorphicOn g s ∧ (Set.EqOn f g (s \ {c})) :=
⟨Function.update f c (limUnder (𝓝[{c}ᶜ] c) f),
differentiableOn_update_limUnder_of_bddAbove hc hd hb,
fun z hz ↦ if h : z = c then (hz.2 h).elim else by simp [h]⟩
/-%%
\begin{proof}\leanok
This is the Riemann Removable Singularity Theorem, slightly rephrased from what's in Mathlib. (We don't care what the function $g$ is, just that it's holomorphic.)
\end{proof}
%%-/
/-%%
\begin{theorem}[HolomorphicOn.vanishesOnRectangle]\label{HolomorphicOn.vanishesOnRectangle}\lean{HolomorphicOn.vanishesOnRectangle}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$, then the integral of $f$ over the rectangle with corners $z$ and $w$ is $0$.
\end{theorem}
%%-/
theorem HolomorphicOn.vanishesOnRectangle [CompleteSpace E] {U : Set ℂ}
(f_holo : HolomorphicOn f U) (hU : Rectangle z w ⊆ U) :
RectangleIntegral f z w = 0 :=
integral_boundary_rect_eq_zero_of_differentiableOn f z w (f_holo.mono hU)
/-%%
\begin{proof}\leanok
This is in a Mathlib PR.
\end{proof}
%%-/
theorem RectangleIntegral_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral f z w = RectangleIntegral g z w := by
unfold RectangleIntegral VIntegral
congr 2; swap; congr 1; swap; congr 1
all_goals refine intervalIntegral.integral_congr fun _ _ ↦ h ?_
· exact Or.inl <| Or.inl <| Or.inl ⟨by simpa, by simp⟩
· exact Or.inl <| Or.inr ⟨by simpa, by simp⟩
· exact Or.inr ⟨by simp, by simpa⟩
· exact Or.inl <| Or.inl <| Or.inr ⟨by simp, by simpa⟩
theorem RectangleIntegral'_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral' f z w = RectangleIntegral' g z w := by
rw [RectangleIntegral', RectangleIntegral_congr h]
theorem rectangleIntegral_symm (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f z w = RectangleIntegral f w z := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, intervalIntegral.integral_symm w.re,
intervalIntegral.integral_symm w.im, sub_neg_eq_add, smul_neg, sub_neg_eq_add, ← sub_eq_add_neg,
neg_add_eq_sub, sub_add_eq_add_sub]
theorem rectangleIntegral_symm_re (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f (w.re + z.im * I) (z.re + w.im * I) = - RectangleIntegral f z w := by
simp [RectangleIntegral, ← sub_eq_zero]
rw [HIntegral_symm (y := z.im), HIntegral_symm (y := w.im)]
abel
def RectangleBorderIntegrable (f : ℂ → E) (z w : ℂ) : Prop :=
IntervalIntegrable (fun x => f (x + z.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun x => f (x + w.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun y => f (w.re + y * I)) volume z.im w.im ∧
IntervalIntegrable (fun y => f (z.re + y * I)) volume z.im w.im
theorem RectangleBorderIntegrable.add {f g : ℂ → E} (hf : RectangleBorderIntegrable f z w)
(hg : RectangleBorderIntegrable g z w) :
RectangleIntegral (f + g) z w = RectangleIntegral f z w + RectangleIntegral g z w := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
rw [intervalIntegral.integral_add hf.1 hg.1, intervalIntegral.integral_add hf.2.1 hg.2.1,
intervalIntegral.integral_add hf.2.2.1 hg.2.2.1, intervalIntegral.integral_add hf.2.2.2 hg.2.2.2]
rw [← sub_eq_zero]
simp only [smul_add]; abel
theorem ContinuousOn.rectangleBorder_integrable (hf : ContinuousOn f (RectangleBorder z w)) :
RectangleBorderIntegrable f z w :=
⟨(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_re z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_re z w)).intervalIntegrable⟩
theorem ContinuousOn.rectangleBorderIntegrable (hf : ContinuousOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
(hf.mono (rectangleBorder_subset_rectangle z w)).rectangleBorder_integrable
theorem ContinuousOn.rectangleBorderNoPIntegrable (hf : ContinuousOn f (Rectangle z w \ {p}))
(pNotOnBorder : p ∉ RectangleBorder z w) : RectangleBorderIntegrable f z w := by
refine (hf.mono (Set.subset_diff.mpr ?_)).rectangleBorder_integrable
exact ⟨rectangleBorder_subset_rectangle z w, disjoint_singleton_right.mpr pNotOnBorder⟩
theorem HolomorphicOn.rectangleBorderIntegrable' (hf : HolomorphicOn f (Rectangle z w \ {p}))
(hp : Rectangle z w ∈ nhds p) : RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderNoPIntegrable (not_mem_rectangleBorder_of_rectangle_mem_nhds hp)
theorem HolomorphicOn.rectangleBorderIntegrable (hf : HolomorphicOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderIntegrable
/--
Given `x₀ a x₁ : ℝ`, and `y₀ y₁ : ℝ` and a function `f : ℂ → ℂ` so that
both `(t : ℝ) ↦ f(t + y₀ * I)` and `(t : ℝ) ↦ f(t + y₁ * I)` are integrable over both
`t ∈ Icc x₀ a` and `t ∈ Icc a x₁`, we have that
`RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I)` is the sum of
`RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I)` and
`RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I)`.
-/
lemma RectangleIntegralHSplit {a x₀ x₁ y₀ y₁ : ℝ}
(f_int_x₀_a_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume x₀ a)
(f_int_a_x₁_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume a x₁)
(f_int_x₀_a_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume x₀ a)
(f_int_a_x₁_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume a x₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_bot f_int_a_x₁_bot,
← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_top f_int_a_x₁_top]
abel
lemma RectangleIntegralHSplit' {a x₀ x₁ y₀ y₁ : ℝ} (ha : a ∈ [[x₀, x₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) :=
RectangleIntegralHSplit
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
lemma RectangleIntegralVSplit {b x₀ x₁ y₀ y₁ : ℝ}
(f_int_y₀_b_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume y₀ b)
(f_int_b_y₁_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume b y₁)
(f_int_y₀_b_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume y₀ b)
(f_int_b_y₁_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume b y₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_left f_int_b_y₁_left,
← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_right f_int_b_y₁_right, ← sub_eq_zero]
simp only [smul_add]; abel
| lemma RectangleIntegralVSplit' {b x₀ x₁ y₀ y₁ : ℝ} (hb : b ∈ [[y₀, y₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) | RectangleIntegralVSplit' | f36a520 20240122 | 1909a40 20240209 | PrimeNumberTheoremAnd/PrimeNumberTheoremAnd/ResidueCalcOnRectangles.lean | {
"lineInFile": 252,
"tokenPositionInFile": 13512,
"theoremPositionInFile": 31
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": ":=\n RectangleIntegralVSplit\n (IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)\n (IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)\n (IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)\n (IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)",
"proofType": "term",
"proofLengthLines": 5,
"proofLengthTokens": 426
} | prime |
import Mathlib.Analysis.Complex.CauchyIntegral
import Mathlib.Analysis.Complex.Convex
import Mathlib.Analysis.Complex.RemovableSingularity
import Mathlib.Analysis.Analytic.Meromorphic
import Mathlib.Analysis.SpecialFunctions.Integrals
import Mathlib.MeasureTheory.Measure.Lebesgue.Integral
import PrimeNumberTheoremAnd.Rectangle
open Complex BigOperators Nat Classical Real Topology Filter Set MeasureTheory intervalIntegral
open scoped Interval
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f g : ℂ → E}
{z w p c A : ℂ} {x x₁ x₂ y y₁ y₂ σ : ℝ}
noncomputable def HIntegral (f : ℂ → E) (x₁ x₂ y : ℝ) : E := ∫ x in x₁..x₂, f (x + y * I)
noncomputable def VIntegral (f : ℂ → E) (x y₁ y₂ : ℝ) : E := I • ∫ y in y₁..y₂, f (x + y * I)
noncomputable def HIntegral' (f : ℂ → E) (x₁ x₂ y : ℝ) : E := (1 / (2 * π * I)) • HIntegral f x₁ x₂ y
noncomputable def VIntegral' (f : ℂ → E) (x y₁ y₂ : ℝ) : E := (1 / (2 * π * I)) • VIntegral f x y₁ y₂
lemma HIntegral_symm : HIntegral f x₁ x₂ y = - HIntegral f x₂ x₁ y := integral_symm _ _
lemma VIntegral_symm : VIntegral f x y₁ y₂ = - VIntegral f x y₂ y₁ := by
simp_rw [VIntegral, integral_symm y₁ y₂, smul_neg, neg_neg]
/-%%
\begin{definition}[RectangleIntegral]\label{RectangleIntegral}\lean{RectangleIntegral}\leanok
A RectangleIntegral of a function $f$ is one over a rectangle determined by $z$ and $w$ in $\C$.
We will sometimes denote it by $\int_{z}^{w} f$. (There is also a primed version, which is $1/(2\pi i)$ times the original.)
\end{definition}
%%-/
/-- A `RectangleIntegral` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`. -/
noncomputable def RectangleIntegral (f : ℂ → E) (z w : ℂ) : E := HIntegral f z.re w.re z.im -
HIntegral f z.re w.re w.im + VIntegral f w.re z.im w.im - VIntegral f z.re z.im w.im
/-- A `RectangleIntegral'` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`, divided by `2 * π * I`. -/
noncomputable abbrev RectangleIntegral' (f : ℂ → E) (z w : ℂ) : E :=
(1 / (2 * π * I)) • RectangleIntegral f z w
/-% ** Wrong delimiter on purpose **
An UpperUIntegral is the integral of a function over a |\_| shape.
\begin{definition}\label{UpperUIntegral}\lean{UpperUIntegral}\leanok
An UpperUIntegral of a function $f$ comes from $\sigma+i\infty$ down to $\sigma+iT$, over to $\sigma'+iT$, and back up to $\sigma'+i\infty$.
\end{definition}
%-/
noncomputable def UpperUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' T +
I • (∫ y : ℝ in Ici T, f (σ' + y * I)) - I • (∫ y : ℝ in Ici T, f (σ + y * I))
/-% ** Wrong delimiter on purpose **
A LowerUIntegral is the integral of a function over a |-| shape.
\begin{definition}[LowerUIntegral]\label{LowerUIntegral}\lean{LowerUIntegral}\leanok
A LowerUIntegral of a function $f$ comes from $\sigma-i\infty$ up to $\sigma-iT$, over to $\sigma'-iT$, and back down to $\sigma'-i\infty$.
\end{definition}
%-/
noncomputable def LowerUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' (-T) -
I • (∫ y : ℝ in Iic (-T), f (σ' + y * I)) + I • (∫ y : ℝ in Iic (-T), f (σ + y * I))
/-%%
It is very convenient to define integrals along vertical lines in the complex plane, as follows.
\begin{definition}[VerticalIntegral]\label{VerticalIntegral}\lean{VerticalIntegral}\leanok
Let $f$ be a function from $\mathbb{C}$ to $\mathbb{C}$, and let $\sigma$ be a real number. Then we define
$$\int_{(\sigma)}f(s)ds = \int_{\sigma-i\infty}^{\sigma+i\infty}f(s)ds.$$
\end{definition}
%%-/
noncomputable def VerticalIntegral (f : ℂ → E) (σ : ℝ) : E := I • ∫ t : ℝ, f (σ + t * I)
--%% We also have a version with a factor of $1/(2\pi i)$.
noncomputable abbrev VerticalIntegral' (f : ℂ → E) (σ : ℝ) : E :=
(1 / (2 * π * I)) • VerticalIntegral f σ
lemma verticalIntegral_split_three (a b : ℝ) (hf : Integrable (fun t : ℝ ↦ f (σ + t * I))) :
VerticalIntegral f σ = I • (∫ t in Iic a, f (σ + t * I)) + VIntegral f σ a b
+ I • ∫ t in Ici b, f (σ + t * I) := by
simp_rw [VerticalIntegral, VIntegral, ← smul_add]
congr
rw [← intervalIntegral.integral_Iic_sub_Iic hf.restrict hf.restrict, add_sub_cancel,
integral_Iic_eq_integral_Iio, intervalIntegral.integral_Iio_add_Ici hf.restrict hf.restrict]
/-% ** Wrong delimiter on purpose **
\begin{lemma}[DiffVertRect_eq_UpperLowerUs]\label{DiffVertRect_eq_UpperLowerUs}\lean{DiffVertRect_eq_UpperLowerUs}\leanok
The difference of two vertical integrals and a rectangle is the difference of an upper and a lower U integrals.
\end{lemma}
%-/
lemma DiffVertRect_eq_UpperLowerUs {σ σ' T : ℝ}
(f_int_σ : Integrable (fun (t : ℝ) ↦ f (σ + t * I)))
(f_int_σ' : Integrable (fun (t : ℝ) ↦ f (σ' + t * I))) :
(VerticalIntegral f σ') - (VerticalIntegral f σ) - (RectangleIntegral f (σ - I * T) (σ' + I * T)) =
(UpperUIntegral f σ σ' T) - (LowerUIntegral f σ σ' T) := by
rw [verticalIntegral_split_three (-T) T f_int_σ, verticalIntegral_split_three (-T) T f_int_σ']
simp only [smul_eq_mul, RectangleIntegral, sub_re, ofReal_re, mul_re, I_re, zero_mul, I_im,
ofReal_im, mul_zero, sub_self, sub_zero, add_re, add_zero, sub_im, mul_im, one_mul, zero_add,
zero_sub, add_im, UpperUIntegral, LowerUIntegral]
abel
/-%
\begin{proof}\uses{UpperUIntegral, LowerUIntegral}\leanok
Follows directly from the definitions.
\end{proof}
%-/
/-- A function is `HolomorphicOn` a set if it is complex differentiable on that set. -/
abbrev HolomorphicOn (f : ℂ → E) (s : Set ℂ) : Prop := DifferentiableOn ℂ f s
/-%%
\begin{theorem}[existsDifferentiableOn_of_bddAbove]\label{existsDifferentiableOn_of_bddAbove}\lean{existsDifferentiableOn_of_bddAbove}\leanok
If $f$ is differentiable on a set $s$ except at $c\in s$, and $f$ is bounded above on $s\setminus\{c\}$, then there exists a differentiable function $g$ on $s$ such that $f$ and $g$ agree on $s\setminus\{c\}$.
\end{theorem}
%%-/
theorem existsDifferentiableOn_of_bddAbove [CompleteSpace E] {s : Set ℂ} {c : ℂ} (hc : s ∈ nhds c)
(hd : HolomorphicOn f (s \ {c})) (hb : BddAbove (norm ∘ f '' (s \ {c}))) :
∃ (g : ℂ → E), HolomorphicOn g s ∧ (Set.EqOn f g (s \ {c})) :=
⟨Function.update f c (limUnder (𝓝[{c}ᶜ] c) f),
differentiableOn_update_limUnder_of_bddAbove hc hd hb,
fun z hz ↦ if h : z = c then (hz.2 h).elim else by simp [h]⟩
/-%%
\begin{proof}\leanok
This is the Riemann Removable Singularity Theorem, slightly rephrased from what's in Mathlib. (We don't care what the function $g$ is, just that it's holomorphic.)
\end{proof}
%%-/
/-%%
\begin{theorem}[HolomorphicOn.vanishesOnRectangle]\label{HolomorphicOn.vanishesOnRectangle}\lean{HolomorphicOn.vanishesOnRectangle}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$, then the integral of $f$ over the rectangle with corners $z$ and $w$ is $0$.
\end{theorem}
%%-/
theorem HolomorphicOn.vanishesOnRectangle [CompleteSpace E] {U : Set ℂ}
(f_holo : HolomorphicOn f U) (hU : Rectangle z w ⊆ U) :
RectangleIntegral f z w = 0 :=
integral_boundary_rect_eq_zero_of_differentiableOn f z w (f_holo.mono hU)
/-%%
\begin{proof}\leanok
This is in a Mathlib PR.
\end{proof}
%%-/
theorem RectangleIntegral_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral f z w = RectangleIntegral g z w := by
unfold RectangleIntegral VIntegral
congr 2; swap; congr 1; swap; congr 1
all_goals refine intervalIntegral.integral_congr fun _ _ ↦ h ?_
· exact Or.inl <| Or.inl <| Or.inl ⟨by simpa, by simp⟩
· exact Or.inl <| Or.inr ⟨by simpa, by simp⟩
· exact Or.inr ⟨by simp, by simpa⟩
· exact Or.inl <| Or.inl <| Or.inr ⟨by simp, by simpa⟩
theorem RectangleIntegral'_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral' f z w = RectangleIntegral' g z w := by
rw [RectangleIntegral', RectangleIntegral_congr h]
theorem rectangleIntegral_symm (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f z w = RectangleIntegral f w z := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, intervalIntegral.integral_symm w.re,
intervalIntegral.integral_symm w.im, sub_neg_eq_add, smul_neg, sub_neg_eq_add, ← sub_eq_add_neg,
neg_add_eq_sub, sub_add_eq_add_sub]
theorem rectangleIntegral_symm_re (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f (w.re + z.im * I) (z.re + w.im * I) = - RectangleIntegral f z w := by
simp [RectangleIntegral, ← sub_eq_zero]
rw [HIntegral_symm (y := z.im), HIntegral_symm (y := w.im)]
abel
def RectangleBorderIntegrable (f : ℂ → E) (z w : ℂ) : Prop :=
IntervalIntegrable (fun x => f (x + z.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun x => f (x + w.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun y => f (w.re + y * I)) volume z.im w.im ∧
IntervalIntegrable (fun y => f (z.re + y * I)) volume z.im w.im
theorem RectangleBorderIntegrable.add {f g : ℂ → E} (hf : RectangleBorderIntegrable f z w)
(hg : RectangleBorderIntegrable g z w) :
RectangleIntegral (f + g) z w = RectangleIntegral f z w + RectangleIntegral g z w := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
rw [intervalIntegral.integral_add hf.1 hg.1, intervalIntegral.integral_add hf.2.1 hg.2.1,
intervalIntegral.integral_add hf.2.2.1 hg.2.2.1, intervalIntegral.integral_add hf.2.2.2 hg.2.2.2]
rw [← sub_eq_zero]
simp only [smul_add]; abel
theorem ContinuousOn.rectangleBorder_integrable (hf : ContinuousOn f (RectangleBorder z w)) :
RectangleBorderIntegrable f z w :=
⟨(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_re z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_re z w)).intervalIntegrable⟩
theorem ContinuousOn.rectangleBorderIntegrable (hf : ContinuousOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
(hf.mono (rectangleBorder_subset_rectangle z w)).rectangleBorder_integrable
theorem ContinuousOn.rectangleBorderNoPIntegrable (hf : ContinuousOn f (Rectangle z w \ {p}))
(pNotOnBorder : p ∉ RectangleBorder z w) : RectangleBorderIntegrable f z w := by
refine (hf.mono (Set.subset_diff.mpr ?_)).rectangleBorder_integrable
exact ⟨rectangleBorder_subset_rectangle z w, disjoint_singleton_right.mpr pNotOnBorder⟩
theorem HolomorphicOn.rectangleBorderIntegrable' (hf : HolomorphicOn f (Rectangle z w \ {p}))
(hp : Rectangle z w ∈ nhds p) : RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderNoPIntegrable (not_mem_rectangleBorder_of_rectangle_mem_nhds hp)
theorem HolomorphicOn.rectangleBorderIntegrable (hf : HolomorphicOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderIntegrable
/--
Given `x₀ a x₁ : ℝ`, and `y₀ y₁ : ℝ` and a function `f : ℂ → ℂ` so that
both `(t : ℝ) ↦ f(t + y₀ * I)` and `(t : ℝ) ↦ f(t + y₁ * I)` are integrable over both
`t ∈ Icc x₀ a` and `t ∈ Icc a x₁`, we have that
`RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I)` is the sum of
`RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I)` and
`RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I)`.
-/
lemma RectangleIntegralHSplit {a x₀ x₁ y₀ y₁ : ℝ}
(f_int_x₀_a_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume x₀ a)
(f_int_a_x₁_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume a x₁)
(f_int_x₀_a_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume x₀ a)
(f_int_a_x₁_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume a x₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_bot f_int_a_x₁_bot,
← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_top f_int_a_x₁_top]
abel
lemma RectangleIntegralHSplit' {a x₀ x₁ y₀ y₁ : ℝ} (ha : a ∈ [[x₀, x₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) :=
RectangleIntegralHSplit
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
lemma RectangleIntegralVSplit {b x₀ x₁ y₀ y₁ : ℝ}
(f_int_y₀_b_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume y₀ b)
(f_int_b_y₁_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume b y₁)
(f_int_y₀_b_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume y₀ b)
(f_int_b_y₁_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume b y₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_left f_int_b_y₁_left,
← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_right f_int_b_y₁_right, ← sub_eq_zero]
simp only [smul_add]; abel
lemma RectangleIntegralVSplit' {b x₀ x₁ y₀ y₁ : ℝ} (hb : b ∈ [[y₀, y₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) :=
RectangleIntegralVSplit
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
| lemma RectanglePullToNhdOfPole' [CompleteSpace E] {z₀ z₁ z₂ z₃ p : ℂ}
(h_orientation : z₀.re ≤ z₃.re ∧ z₀.im ≤ z₃.im ∧ z₁.re ≤ z₂.re ∧ z₁.im ≤ z₂.im)
(hp : Rectangle z₁ z₂ ∈ 𝓝 p) (hz : Rectangle z₁ z₂ ⊆ Rectangle z₀ z₃)
(fHolo : HolomorphicOn f (Rectangle z₀ z₃ \ {p})) :
RectangleIntegral f z₀ z₃ = RectangleIntegral f z₁ z₂ | RectanglePullToNhdOfPole' | f36a520 20240122 | 1909a40 20240209 | PrimeNumberTheoremAnd/PrimeNumberTheoremAnd/ResidueCalcOnRectangles.lean | {
"lineInFile": 263,
"tokenPositionInFile": 14248,
"theoremPositionInFile": 32
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": ":= by\n obtain ⟨hz₀_re, hz₀_im, hz₁_re, hz₁_im⟩ := h_orientation\n have := rect_subset_iff.mp hz\n rw [Rectangle, uIcc_of_le hz₀_re, uIcc_of_le hz₀_im] at this\n obtain ⟨⟨⟨_, _⟩, ⟨_, _⟩⟩, ⟨_, _⟩, ⟨_, _⟩⟩ := this\n obtain ⟨⟨_, _⟩, ⟨_, _⟩⟩ := (uIoo_of_le hz₁_re) ▸ (uIoo_of_le hz₁_im) ▸ rectangle_mem_nhds_iff.mp hp\n obtain ⟨_, _, _, _⟩ := show p.re < z₂.re ∧ p.re < z₃.re ∧ p.im < z₂.im ∧ p.im < z₃.im from\n ⟨by linarith, by linarith, by linarith, by linarith⟩\n obtain ⟨_, _, _, _⟩ := show z₀.re < p.re ∧ z₁.re < p.re ∧ z₀.im < p.im ∧ z₁.im < p.im from\n ⟨by linarith, by linarith, by linarith, by linarith⟩\n\n have fCont := fHolo.continuousOn\n\n have hbot : RectangleBorderIntegrable f (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₃.im * I) := ?_\n have htop : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₃.im * I) := ?_\n have hleft : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_\n have hright : RectangleBorderIntegrable f (↑z₁.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_\n all_goals try {\n refine (fCont.mono (rectangleBorder_subset_punctured_rect ?_ ?_)).rectangleBorder_integrable\n · simp_all\n · simpa using ⟨by linarith, by linarith, by linarith, by linarith⟩\n }\n have hbot' : z₁.im ∈ [[z₀.im, z₃.im]] := ?_\n have htop' : z₂.im ∈ [[z₁.im, z₃.im]] := ?_\n have hleft' : z₁.re ∈ [[z₀.re, z₃.re]] := ?_\n have hright' : z₂.re ∈ [[z₁.re, z₃.re]] := ?_\n all_goals try { rw [Set.uIcc_of_le]; constructor; all_goals assumption }\n have hbot'' : Rectangle (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₁.im * I) ⊆ Rectangle z₀ z₃ \\ {p} := ?_\n have htop'' : Rectangle (↑z₀.re + ↑z₂.im * I) (↑z₃.re + ↑z₃.im * I) ⊆ Rectangle z₀ z₃ \\ {p} := ?_\n have hleft'' : Rectangle (↑z₀.re + ↑z₁.im * I) (↑z₁.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \\ {p} := ?_\n have hright'' : Rectangle (↑z₂.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \\ {p} := ?_\n all_goals try { apply rectangle_subset_punctured_rect <;> simp_all }\n\n rw [← re_add_im z₀, ← re_add_im z₃,\n RectangleIntegralVSplit' hbot' hbot, fHolo.vanishesOnRectangle hbot'', zero_add,\n RectangleIntegralVSplit' htop' htop, fHolo.vanishesOnRectangle htop'', add_zero,\n RectangleIntegralHSplit' hleft' hleft, fHolo.vanishesOnRectangle hleft'', zero_add,\n RectangleIntegralHSplit' hright' hright, fHolo.vanishesOnRectangle hright'', add_zero,\n re_add_im, re_add_im]",
"proofType": "tactic",
"proofLengthLines": 38,
"proofLengthTokens": 2376
} | prime |
import Mathlib.Analysis.Complex.CauchyIntegral
import Mathlib.Analysis.Complex.Convex
import Mathlib.Analysis.Complex.RemovableSingularity
import Mathlib.Analysis.Analytic.Meromorphic
import Mathlib.Analysis.SpecialFunctions.Integrals
import Mathlib.MeasureTheory.Measure.Lebesgue.Integral
import PrimeNumberTheoremAnd.Rectangle
open Complex BigOperators Nat Classical Real Topology Filter Set MeasureTheory intervalIntegral
open scoped Interval
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f g : ℂ → E}
{z w p c A : ℂ} {x x₁ x₂ y y₁ y₂ σ : ℝ}
noncomputable def HIntegral (f : ℂ → E) (x₁ x₂ y : ℝ) : E := ∫ x in x₁..x₂, f (x + y * I)
noncomputable def VIntegral (f : ℂ → E) (x y₁ y₂ : ℝ) : E := I • ∫ y in y₁..y₂, f (x + y * I)
noncomputable def HIntegral' (f : ℂ → E) (x₁ x₂ y : ℝ) : E := (1 / (2 * π * I)) • HIntegral f x₁ x₂ y
noncomputable def VIntegral' (f : ℂ → E) (x y₁ y₂ : ℝ) : E := (1 / (2 * π * I)) • VIntegral f x y₁ y₂
lemma HIntegral_symm : HIntegral f x₁ x₂ y = - HIntegral f x₂ x₁ y := integral_symm _ _
lemma VIntegral_symm : VIntegral f x y₁ y₂ = - VIntegral f x y₂ y₁ := by
simp_rw [VIntegral, integral_symm y₁ y₂, smul_neg, neg_neg]
/-%%
\begin{definition}[RectangleIntegral]\label{RectangleIntegral}\lean{RectangleIntegral}\leanok
A RectangleIntegral of a function $f$ is one over a rectangle determined by $z$ and $w$ in $\C$.
We will sometimes denote it by $\int_{z}^{w} f$. (There is also a primed version, which is $1/(2\pi i)$ times the original.)
\end{definition}
%%-/
/-- A `RectangleIntegral` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`. -/
noncomputable def RectangleIntegral (f : ℂ → E) (z w : ℂ) : E := HIntegral f z.re w.re z.im -
HIntegral f z.re w.re w.im + VIntegral f w.re z.im w.im - VIntegral f z.re z.im w.im
/-- A `RectangleIntegral'` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`, divided by `2 * π * I`. -/
noncomputable abbrev RectangleIntegral' (f : ℂ → E) (z w : ℂ) : E :=
(1 / (2 * π * I)) • RectangleIntegral f z w
/-% ** Wrong delimiter on purpose **
An UpperUIntegral is the integral of a function over a |\_| shape.
\begin{definition}\label{UpperUIntegral}\lean{UpperUIntegral}\leanok
An UpperUIntegral of a function $f$ comes from $\sigma+i\infty$ down to $\sigma+iT$, over to $\sigma'+iT$, and back up to $\sigma'+i\infty$.
\end{definition}
%-/
noncomputable def UpperUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' T +
I • (∫ y : ℝ in Ici T, f (σ' + y * I)) - I • (∫ y : ℝ in Ici T, f (σ + y * I))
/-% ** Wrong delimiter on purpose **
A LowerUIntegral is the integral of a function over a |-| shape.
\begin{definition}[LowerUIntegral]\label{LowerUIntegral}\lean{LowerUIntegral}\leanok
A LowerUIntegral of a function $f$ comes from $\sigma-i\infty$ up to $\sigma-iT$, over to $\sigma'-iT$, and back down to $\sigma'-i\infty$.
\end{definition}
%-/
noncomputable def LowerUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' (-T) -
I • (∫ y : ℝ in Iic (-T), f (σ' + y * I)) + I • (∫ y : ℝ in Iic (-T), f (σ + y * I))
/-%%
It is very convenient to define integrals along vertical lines in the complex plane, as follows.
\begin{definition}[VerticalIntegral]\label{VerticalIntegral}\lean{VerticalIntegral}\leanok
Let $f$ be a function from $\mathbb{C}$ to $\mathbb{C}$, and let $\sigma$ be a real number. Then we define
$$\int_{(\sigma)}f(s)ds = \int_{\sigma-i\infty}^{\sigma+i\infty}f(s)ds.$$
\end{definition}
%%-/
noncomputable def VerticalIntegral (f : ℂ → E) (σ : ℝ) : E := I • ∫ t : ℝ, f (σ + t * I)
--%% We also have a version with a factor of $1/(2\pi i)$.
noncomputable abbrev VerticalIntegral' (f : ℂ → E) (σ : ℝ) : E :=
(1 / (2 * π * I)) • VerticalIntegral f σ
lemma verticalIntegral_split_three (a b : ℝ) (hf : Integrable (fun t : ℝ ↦ f (σ + t * I))) :
VerticalIntegral f σ = I • (∫ t in Iic a, f (σ + t * I)) + VIntegral f σ a b
+ I • ∫ t in Ici b, f (σ + t * I) := by
simp_rw [VerticalIntegral, VIntegral, ← smul_add]
congr
rw [← intervalIntegral.integral_Iic_sub_Iic hf.restrict hf.restrict, add_sub_cancel,
integral_Iic_eq_integral_Iio, intervalIntegral.integral_Iio_add_Ici hf.restrict hf.restrict]
/-% ** Wrong delimiter on purpose **
\begin{lemma}[DiffVertRect_eq_UpperLowerUs]\label{DiffVertRect_eq_UpperLowerUs}\lean{DiffVertRect_eq_UpperLowerUs}\leanok
The difference of two vertical integrals and a rectangle is the difference of an upper and a lower U integrals.
\end{lemma}
%-/
lemma DiffVertRect_eq_UpperLowerUs {σ σ' T : ℝ}
(f_int_σ : Integrable (fun (t : ℝ) ↦ f (σ + t * I)))
(f_int_σ' : Integrable (fun (t : ℝ) ↦ f (σ' + t * I))) :
(VerticalIntegral f σ') - (VerticalIntegral f σ) - (RectangleIntegral f (σ - I * T) (σ' + I * T)) =
(UpperUIntegral f σ σ' T) - (LowerUIntegral f σ σ' T) := by
rw [verticalIntegral_split_three (-T) T f_int_σ, verticalIntegral_split_three (-T) T f_int_σ']
simp only [smul_eq_mul, RectangleIntegral, sub_re, ofReal_re, mul_re, I_re, zero_mul, I_im,
ofReal_im, mul_zero, sub_self, sub_zero, add_re, add_zero, sub_im, mul_im, one_mul, zero_add,
zero_sub, add_im, UpperUIntegral, LowerUIntegral]
abel
/-%
\begin{proof}\uses{UpperUIntegral, LowerUIntegral}\leanok
Follows directly from the definitions.
\end{proof}
%-/
/-- A function is `HolomorphicOn` a set if it is complex differentiable on that set. -/
abbrev HolomorphicOn (f : ℂ → E) (s : Set ℂ) : Prop := DifferentiableOn ℂ f s
/-%%
\begin{theorem}[existsDifferentiableOn_of_bddAbove]\label{existsDifferentiableOn_of_bddAbove}\lean{existsDifferentiableOn_of_bddAbove}\leanok
If $f$ is differentiable on a set $s$ except at $c\in s$, and $f$ is bounded above on $s\setminus\{c\}$, then there exists a differentiable function $g$ on $s$ such that $f$ and $g$ agree on $s\setminus\{c\}$.
\end{theorem}
%%-/
theorem existsDifferentiableOn_of_bddAbove [CompleteSpace E] {s : Set ℂ} {c : ℂ} (hc : s ∈ nhds c)
(hd : HolomorphicOn f (s \ {c})) (hb : BddAbove (norm ∘ f '' (s \ {c}))) :
∃ (g : ℂ → E), HolomorphicOn g s ∧ (Set.EqOn f g (s \ {c})) :=
⟨Function.update f c (limUnder (𝓝[{c}ᶜ] c) f),
differentiableOn_update_limUnder_of_bddAbove hc hd hb,
fun z hz ↦ if h : z = c then (hz.2 h).elim else by simp [h]⟩
/-%%
\begin{proof}\leanok
This is the Riemann Removable Singularity Theorem, slightly rephrased from what's in Mathlib. (We don't care what the function $g$ is, just that it's holomorphic.)
\end{proof}
%%-/
/-%%
\begin{theorem}[HolomorphicOn.vanishesOnRectangle]\label{HolomorphicOn.vanishesOnRectangle}\lean{HolomorphicOn.vanishesOnRectangle}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$, then the integral of $f$ over the rectangle with corners $z$ and $w$ is $0$.
\end{theorem}
%%-/
theorem HolomorphicOn.vanishesOnRectangle [CompleteSpace E] {U : Set ℂ}
(f_holo : HolomorphicOn f U) (hU : Rectangle z w ⊆ U) :
RectangleIntegral f z w = 0 :=
integral_boundary_rect_eq_zero_of_differentiableOn f z w (f_holo.mono hU)
/-%%
\begin{proof}\leanok
This is in a Mathlib PR.
\end{proof}
%%-/
theorem RectangleIntegral_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral f z w = RectangleIntegral g z w := by
unfold RectangleIntegral VIntegral
congr 2; swap; congr 1; swap; congr 1
all_goals refine intervalIntegral.integral_congr fun _ _ ↦ h ?_
· exact Or.inl <| Or.inl <| Or.inl ⟨by simpa, by simp⟩
· exact Or.inl <| Or.inr ⟨by simpa, by simp⟩
· exact Or.inr ⟨by simp, by simpa⟩
· exact Or.inl <| Or.inl <| Or.inr ⟨by simp, by simpa⟩
theorem RectangleIntegral'_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral' f z w = RectangleIntegral' g z w := by
rw [RectangleIntegral', RectangleIntegral_congr h]
theorem rectangleIntegral_symm (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f z w = RectangleIntegral f w z := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, intervalIntegral.integral_symm w.re,
intervalIntegral.integral_symm w.im, sub_neg_eq_add, smul_neg, sub_neg_eq_add, ← sub_eq_add_neg,
neg_add_eq_sub, sub_add_eq_add_sub]
theorem rectangleIntegral_symm_re (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f (w.re + z.im * I) (z.re + w.im * I) = - RectangleIntegral f z w := by
simp [RectangleIntegral, ← sub_eq_zero]
rw [HIntegral_symm (y := z.im), HIntegral_symm (y := w.im)]
abel
def RectangleBorderIntegrable (f : ℂ → E) (z w : ℂ) : Prop :=
IntervalIntegrable (fun x => f (x + z.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun x => f (x + w.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun y => f (w.re + y * I)) volume z.im w.im ∧
IntervalIntegrable (fun y => f (z.re + y * I)) volume z.im w.im
theorem RectangleBorderIntegrable.add {f g : ℂ → E} (hf : RectangleBorderIntegrable f z w)
(hg : RectangleBorderIntegrable g z w) :
RectangleIntegral (f + g) z w = RectangleIntegral f z w + RectangleIntegral g z w := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
rw [intervalIntegral.integral_add hf.1 hg.1, intervalIntegral.integral_add hf.2.1 hg.2.1,
intervalIntegral.integral_add hf.2.2.1 hg.2.2.1, intervalIntegral.integral_add hf.2.2.2 hg.2.2.2]
rw [← sub_eq_zero]
simp only [smul_add]; abel
theorem ContinuousOn.rectangleBorder_integrable (hf : ContinuousOn f (RectangleBorder z w)) :
RectangleBorderIntegrable f z w :=
⟨(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_re z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_re z w)).intervalIntegrable⟩
theorem ContinuousOn.rectangleBorderIntegrable (hf : ContinuousOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
(hf.mono (rectangleBorder_subset_rectangle z w)).rectangleBorder_integrable
theorem ContinuousOn.rectangleBorderNoPIntegrable (hf : ContinuousOn f (Rectangle z w \ {p}))
(pNotOnBorder : p ∉ RectangleBorder z w) : RectangleBorderIntegrable f z w := by
refine (hf.mono (Set.subset_diff.mpr ?_)).rectangleBorder_integrable
exact ⟨rectangleBorder_subset_rectangle z w, disjoint_singleton_right.mpr pNotOnBorder⟩
theorem HolomorphicOn.rectangleBorderIntegrable' (hf : HolomorphicOn f (Rectangle z w \ {p}))
(hp : Rectangle z w ∈ nhds p) : RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderNoPIntegrable (not_mem_rectangleBorder_of_rectangle_mem_nhds hp)
theorem HolomorphicOn.rectangleBorderIntegrable (hf : HolomorphicOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderIntegrable
/--
Given `x₀ a x₁ : ℝ`, and `y₀ y₁ : ℝ` and a function `f : ℂ → ℂ` so that
both `(t : ℝ) ↦ f(t + y₀ * I)` and `(t : ℝ) ↦ f(t + y₁ * I)` are integrable over both
`t ∈ Icc x₀ a` and `t ∈ Icc a x₁`, we have that
`RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I)` is the sum of
`RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I)` and
`RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I)`.
-/
lemma RectangleIntegralHSplit {a x₀ x₁ y₀ y₁ : ℝ}
(f_int_x₀_a_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume x₀ a)
(f_int_a_x₁_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume a x₁)
(f_int_x₀_a_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume x₀ a)
(f_int_a_x₁_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume a x₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_bot f_int_a_x₁_bot,
← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_top f_int_a_x₁_top]
abel
lemma RectangleIntegralHSplit' {a x₀ x₁ y₀ y₁ : ℝ} (ha : a ∈ [[x₀, x₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) :=
RectangleIntegralHSplit
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
lemma RectangleIntegralVSplit {b x₀ x₁ y₀ y₁ : ℝ}
(f_int_y₀_b_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume y₀ b)
(f_int_b_y₁_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume b y₁)
(f_int_y₀_b_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume y₀ b)
(f_int_b_y₁_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume b y₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_left f_int_b_y₁_left,
← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_right f_int_b_y₁_right, ← sub_eq_zero]
simp only [smul_add]; abel
lemma RectangleIntegralVSplit' {b x₀ x₁ y₀ y₁ : ℝ} (hb : b ∈ [[y₀, y₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) :=
RectangleIntegralVSplit
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
lemma RectanglePullToNhdOfPole' [CompleteSpace E] {z₀ z₁ z₂ z₃ p : ℂ}
(h_orientation : z₀.re ≤ z₃.re ∧ z₀.im ≤ z₃.im ∧ z₁.re ≤ z₂.re ∧ z₁.im ≤ z₂.im)
(hp : Rectangle z₁ z₂ ∈ 𝓝 p) (hz : Rectangle z₁ z₂ ⊆ Rectangle z₀ z₃)
(fHolo : HolomorphicOn f (Rectangle z₀ z₃ \ {p})) :
RectangleIntegral f z₀ z₃ = RectangleIntegral f z₁ z₂ := by
obtain ⟨hz₀_re, hz₀_im, hz₁_re, hz₁_im⟩ := h_orientation
have := rect_subset_iff.mp hz
rw [Rectangle, uIcc_of_le hz₀_re, uIcc_of_le hz₀_im] at this
obtain ⟨⟨⟨_, _⟩, ⟨_, _⟩⟩, ⟨_, _⟩, ⟨_, _⟩⟩ := this
obtain ⟨⟨_, _⟩, ⟨_, _⟩⟩ := (uIoo_of_le hz₁_re) ▸ (uIoo_of_le hz₁_im) ▸ rectangle_mem_nhds_iff.mp hp
obtain ⟨_, _, _, _⟩ := show p.re < z₂.re ∧ p.re < z₃.re ∧ p.im < z₂.im ∧ p.im < z₃.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
obtain ⟨_, _, _, _⟩ := show z₀.re < p.re ∧ z₁.re < p.re ∧ z₀.im < p.im ∧ z₁.im < p.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
have fCont := fHolo.continuousOn
have hbot : RectangleBorderIntegrable f (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have htop : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have hleft : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
have hright : RectangleBorderIntegrable f (↑z₁.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
all_goals try {
refine (fCont.mono (rectangleBorder_subset_punctured_rect ?_ ?_)).rectangleBorder_integrable
· simp_all
· simpa using ⟨by linarith, by linarith, by linarith, by linarith⟩
}
have hbot' : z₁.im ∈ [[z₀.im, z₃.im]] := ?_
have htop' : z₂.im ∈ [[z₁.im, z₃.im]] := ?_
have hleft' : z₁.re ∈ [[z₀.re, z₃.re]] := ?_
have hright' : z₂.re ∈ [[z₁.re, z₃.re]] := ?_
all_goals try { rw [Set.uIcc_of_le]; constructor; all_goals assumption }
have hbot'' : Rectangle (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₁.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have htop'' : Rectangle (↑z₀.re + ↑z₂.im * I) (↑z₃.re + ↑z₃.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hleft'' : Rectangle (↑z₀.re + ↑z₁.im * I) (↑z₁.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hright'' : Rectangle (↑z₂.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
all_goals try { apply rectangle_subset_punctured_rect <;> simp_all }
rw [← re_add_im z₀, ← re_add_im z₃,
RectangleIntegralVSplit' hbot' hbot, fHolo.vanishesOnRectangle hbot'', zero_add,
RectangleIntegralVSplit' htop' htop, fHolo.vanishesOnRectangle htop'', add_zero,
RectangleIntegralHSplit' hleft' hleft, fHolo.vanishesOnRectangle hleft'', zero_add,
RectangleIntegralHSplit' hright' hright, fHolo.vanishesOnRectangle hright'', add_zero,
re_add_im, re_add_im]
/-%%
The next lemma allows to zoom a big rectangle down to a small square, centered at a pole.
\begin{lemma}[RectanglePullToNhdOfPole]\label{RectanglePullToNhdOfPole}\lean{RectanglePullToNhdOfPole}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$ except at a point $p$, then the integral of $f$
over the rectangle with corners $z$ and $w$ is the same as the integral of $f$ over a small square
centered at $p$.
\end{lemma}
%%-/
/-- Given `f` holomorphic on a rectangle `z` and `w` except at a point `p`, the integral of `f` over
the rectangle with corners `z` and `w` is the same as the integral of `f` over a small square
centered at `p`. -/
lemma RectanglePullToNhdOfPole [CompleteSpace E] {z w p : ℂ} (zRe_lt_wRe : z.re ≤ w.re)
(zIm_lt_wIm : z.im ≤ w.im) (hp : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral f z w = RectangleIntegral f (-c - I * c + p) (c + I * c + p) := by
/-%%
\begin{proof}\uses{HolomorphicOn.vanishesOnRectangle}\leanok
Chop the big rectangle with two vertical cuts and two horizontal cuts into smaller rectangles,
the middle one being the desired square. The integral over each of the outer rectangles
vanishes, since $f$ is holomorphic there. (The constant $c$ being ``small enough'' here just means
that the inner square is strictly contained in the big rectangle.)
%%-/
filter_upwards [Ioo_mem_nhdsWithin_Ioi' zero_lt_one, SmallSquareInRectangle hp]
intro c ⟨cpos, _⟩ hc
simp_rw [mul_comm I]
exact RectanglePullToNhdOfPole' (by simp_all [cpos.le])
(square_mem_nhds p (ne_of_gt cpos)) hc fHolo
--%%\end{proof}
| lemma RectanglePullToNhdOfPole'' [CompleteSpace E] {z w p : ℂ} (zRe_le_wRe : z.re ≤ w.re)
(zIm_le_wIm : z.im ≤ w.im) (pInRectInterior : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral' f z w = RectangleIntegral' f (-c - I * c + p) (c + I * c + p) | RectanglePullToNhdOfPole'' | f36a520 20240122 | 1909a40 20240209 | PrimeNumberTheoremAnd/PrimeNumberTheoremAnd/ResidueCalcOnRectangles.lean | {
"lineInFile": 338,
"tokenPositionInFile": 18605,
"theoremPositionInFile": 34
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": ":= by\n filter_upwards [RectanglePullToNhdOfPole zRe_le_wRe zIm_le_wIm pInRectInterior fHolo] with c h\n simp_rw [RectangleIntegral', h]",
"proofType": "tactic",
"proofLengthLines": 2,
"proofLengthTokens": 136
} | prime |
import Mathlib.Analysis.Complex.CauchyIntegral
import Mathlib.Analysis.Complex.Convex
import Mathlib.Analysis.Complex.RemovableSingularity
import Mathlib.Analysis.Analytic.Meromorphic
import Mathlib.Analysis.SpecialFunctions.Integrals
import Mathlib.MeasureTheory.Measure.Lebesgue.Integral
import PrimeNumberTheoremAnd.Rectangle
open Complex BigOperators Nat Classical Real Topology Filter Set MeasureTheory intervalIntegral
open scoped Interval
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f g : ℂ → E}
{z w p c A : ℂ} {x x₁ x₂ y y₁ y₂ σ : ℝ}
noncomputable def HIntegral (f : ℂ → E) (x₁ x₂ y : ℝ) : E := ∫ x in x₁..x₂, f (x + y * I)
noncomputable def VIntegral (f : ℂ → E) (x y₁ y₂ : ℝ) : E := I • ∫ y in y₁..y₂, f (x + y * I)
noncomputable def HIntegral' (f : ℂ → E) (x₁ x₂ y : ℝ) : E := (1 / (2 * π * I)) • HIntegral f x₁ x₂ y
noncomputable def VIntegral' (f : ℂ → E) (x y₁ y₂ : ℝ) : E := (1 / (2 * π * I)) • VIntegral f x y₁ y₂
lemma HIntegral_symm : HIntegral f x₁ x₂ y = - HIntegral f x₂ x₁ y := integral_symm _ _
lemma VIntegral_symm : VIntegral f x y₁ y₂ = - VIntegral f x y₂ y₁ := by
simp_rw [VIntegral, integral_symm y₁ y₂, smul_neg, neg_neg]
/-%%
\begin{definition}[RectangleIntegral]\label{RectangleIntegral}\lean{RectangleIntegral}\leanok
A RectangleIntegral of a function $f$ is one over a rectangle determined by $z$ and $w$ in $\C$.
We will sometimes denote it by $\int_{z}^{w} f$. (There is also a primed version, which is $1/(2\pi i)$ times the original.)
\end{definition}
%%-/
/-- A `RectangleIntegral` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`. -/
noncomputable def RectangleIntegral (f : ℂ → E) (z w : ℂ) : E := HIntegral f z.re w.re z.im -
HIntegral f z.re w.re w.im + VIntegral f w.re z.im w.im - VIntegral f z.re z.im w.im
/-- A `RectangleIntegral'` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`, divided by `2 * π * I`. -/
noncomputable abbrev RectangleIntegral' (f : ℂ → E) (z w : ℂ) : E :=
(1 / (2 * π * I)) • RectangleIntegral f z w
/-% ** Wrong delimiter on purpose **
An UpperUIntegral is the integral of a function over a |\_| shape.
\begin{definition}\label{UpperUIntegral}\lean{UpperUIntegral}\leanok
An UpperUIntegral of a function $f$ comes from $\sigma+i\infty$ down to $\sigma+iT$, over to $\sigma'+iT$, and back up to $\sigma'+i\infty$.
\end{definition}
%-/
noncomputable def UpperUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' T +
I • (∫ y : ℝ in Ici T, f (σ' + y * I)) - I • (∫ y : ℝ in Ici T, f (σ + y * I))
/-% ** Wrong delimiter on purpose **
A LowerUIntegral is the integral of a function over a |-| shape.
\begin{definition}[LowerUIntegral]\label{LowerUIntegral}\lean{LowerUIntegral}\leanok
A LowerUIntegral of a function $f$ comes from $\sigma-i\infty$ up to $\sigma-iT$, over to $\sigma'-iT$, and back down to $\sigma'-i\infty$.
\end{definition}
%-/
noncomputable def LowerUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' (-T) -
I • (∫ y : ℝ in Iic (-T), f (σ' + y * I)) + I • (∫ y : ℝ in Iic (-T), f (σ + y * I))
/-%%
It is very convenient to define integrals along vertical lines in the complex plane, as follows.
\begin{definition}[VerticalIntegral]\label{VerticalIntegral}\lean{VerticalIntegral}\leanok
Let $f$ be a function from $\mathbb{C}$ to $\mathbb{C}$, and let $\sigma$ be a real number. Then we define
$$\int_{(\sigma)}f(s)ds = \int_{\sigma-i\infty}^{\sigma+i\infty}f(s)ds.$$
\end{definition}
%%-/
noncomputable def VerticalIntegral (f : ℂ → E) (σ : ℝ) : E := I • ∫ t : ℝ, f (σ + t * I)
--%% We also have a version with a factor of $1/(2\pi i)$.
noncomputable abbrev VerticalIntegral' (f : ℂ → E) (σ : ℝ) : E :=
(1 / (2 * π * I)) • VerticalIntegral f σ
lemma verticalIntegral_split_three (a b : ℝ) (hf : Integrable (fun t : ℝ ↦ f (σ + t * I))) :
VerticalIntegral f σ = I • (∫ t in Iic a, f (σ + t * I)) + VIntegral f σ a b
+ I • ∫ t in Ici b, f (σ + t * I) := by
simp_rw [VerticalIntegral, VIntegral, ← smul_add]
congr
rw [← intervalIntegral.integral_Iic_sub_Iic hf.restrict hf.restrict, add_sub_cancel,
integral_Iic_eq_integral_Iio, intervalIntegral.integral_Iio_add_Ici hf.restrict hf.restrict]
/-% ** Wrong delimiter on purpose **
\begin{lemma}[DiffVertRect_eq_UpperLowerUs]\label{DiffVertRect_eq_UpperLowerUs}\lean{DiffVertRect_eq_UpperLowerUs}\leanok
The difference of two vertical integrals and a rectangle is the difference of an upper and a lower U integrals.
\end{lemma}
%-/
lemma DiffVertRect_eq_UpperLowerUs {σ σ' T : ℝ}
(f_int_σ : Integrable (fun (t : ℝ) ↦ f (σ + t * I)))
(f_int_σ' : Integrable (fun (t : ℝ) ↦ f (σ' + t * I))) :
(VerticalIntegral f σ') - (VerticalIntegral f σ) - (RectangleIntegral f (σ - I * T) (σ' + I * T)) =
(UpperUIntegral f σ σ' T) - (LowerUIntegral f σ σ' T) := by
rw [verticalIntegral_split_three (-T) T f_int_σ, verticalIntegral_split_three (-T) T f_int_σ']
simp only [smul_eq_mul, RectangleIntegral, sub_re, ofReal_re, mul_re, I_re, zero_mul, I_im,
ofReal_im, mul_zero, sub_self, sub_zero, add_re, add_zero, sub_im, mul_im, one_mul, zero_add,
zero_sub, add_im, UpperUIntegral, LowerUIntegral]
abel
/-%
\begin{proof}\uses{UpperUIntegral, LowerUIntegral}\leanok
Follows directly from the definitions.
\end{proof}
%-/
/-- A function is `HolomorphicOn` a set if it is complex differentiable on that set. -/
abbrev HolomorphicOn (f : ℂ → E) (s : Set ℂ) : Prop := DifferentiableOn ℂ f s
/-%%
\begin{theorem}[existsDifferentiableOn_of_bddAbove]\label{existsDifferentiableOn_of_bddAbove}\lean{existsDifferentiableOn_of_bddAbove}\leanok
If $f$ is differentiable on a set $s$ except at $c\in s$, and $f$ is bounded above on $s\setminus\{c\}$, then there exists a differentiable function $g$ on $s$ such that $f$ and $g$ agree on $s\setminus\{c\}$.
\end{theorem}
%%-/
theorem existsDifferentiableOn_of_bddAbove [CompleteSpace E] {s : Set ℂ} {c : ℂ} (hc : s ∈ nhds c)
(hd : HolomorphicOn f (s \ {c})) (hb : BddAbove (norm ∘ f '' (s \ {c}))) :
∃ (g : ℂ → E), HolomorphicOn g s ∧ (Set.EqOn f g (s \ {c})) :=
⟨Function.update f c (limUnder (𝓝[{c}ᶜ] c) f),
differentiableOn_update_limUnder_of_bddAbove hc hd hb,
fun z hz ↦ if h : z = c then (hz.2 h).elim else by simp [h]⟩
/-%%
\begin{proof}\leanok
This is the Riemann Removable Singularity Theorem, slightly rephrased from what's in Mathlib. (We don't care what the function $g$ is, just that it's holomorphic.)
\end{proof}
%%-/
/-%%
\begin{theorem}[HolomorphicOn.vanishesOnRectangle]\label{HolomorphicOn.vanishesOnRectangle}\lean{HolomorphicOn.vanishesOnRectangle}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$, then the integral of $f$ over the rectangle with corners $z$ and $w$ is $0$.
\end{theorem}
%%-/
theorem HolomorphicOn.vanishesOnRectangle [CompleteSpace E] {U : Set ℂ}
(f_holo : HolomorphicOn f U) (hU : Rectangle z w ⊆ U) :
RectangleIntegral f z w = 0 :=
integral_boundary_rect_eq_zero_of_differentiableOn f z w (f_holo.mono hU)
/-%%
\begin{proof}\leanok
This is in a Mathlib PR.
\end{proof}
%%-/
theorem RectangleIntegral_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral f z w = RectangleIntegral g z w := by
unfold RectangleIntegral VIntegral
congr 2; swap; congr 1; swap; congr 1
all_goals refine intervalIntegral.integral_congr fun _ _ ↦ h ?_
· exact Or.inl <| Or.inl <| Or.inl ⟨by simpa, by simp⟩
· exact Or.inl <| Or.inr ⟨by simpa, by simp⟩
· exact Or.inr ⟨by simp, by simpa⟩
· exact Or.inl <| Or.inl <| Or.inr ⟨by simp, by simpa⟩
theorem RectangleIntegral'_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral' f z w = RectangleIntegral' g z w := by
rw [RectangleIntegral', RectangleIntegral_congr h]
theorem rectangleIntegral_symm (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f z w = RectangleIntegral f w z := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, intervalIntegral.integral_symm w.re,
intervalIntegral.integral_symm w.im, sub_neg_eq_add, smul_neg, sub_neg_eq_add, ← sub_eq_add_neg,
neg_add_eq_sub, sub_add_eq_add_sub]
theorem rectangleIntegral_symm_re (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f (w.re + z.im * I) (z.re + w.im * I) = - RectangleIntegral f z w := by
simp [RectangleIntegral, ← sub_eq_zero]
rw [HIntegral_symm (y := z.im), HIntegral_symm (y := w.im)]
abel
def RectangleBorderIntegrable (f : ℂ → E) (z w : ℂ) : Prop :=
IntervalIntegrable (fun x => f (x + z.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun x => f (x + w.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun y => f (w.re + y * I)) volume z.im w.im ∧
IntervalIntegrable (fun y => f (z.re + y * I)) volume z.im w.im
theorem RectangleBorderIntegrable.add {f g : ℂ → E} (hf : RectangleBorderIntegrable f z w)
(hg : RectangleBorderIntegrable g z w) :
RectangleIntegral (f + g) z w = RectangleIntegral f z w + RectangleIntegral g z w := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
rw [intervalIntegral.integral_add hf.1 hg.1, intervalIntegral.integral_add hf.2.1 hg.2.1,
intervalIntegral.integral_add hf.2.2.1 hg.2.2.1, intervalIntegral.integral_add hf.2.2.2 hg.2.2.2]
rw [← sub_eq_zero]
simp only [smul_add]; abel
theorem ContinuousOn.rectangleBorder_integrable (hf : ContinuousOn f (RectangleBorder z w)) :
RectangleBorderIntegrable f z w :=
⟨(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_re z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_re z w)).intervalIntegrable⟩
theorem ContinuousOn.rectangleBorderIntegrable (hf : ContinuousOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
(hf.mono (rectangleBorder_subset_rectangle z w)).rectangleBorder_integrable
theorem ContinuousOn.rectangleBorderNoPIntegrable (hf : ContinuousOn f (Rectangle z w \ {p}))
(pNotOnBorder : p ∉ RectangleBorder z w) : RectangleBorderIntegrable f z w := by
refine (hf.mono (Set.subset_diff.mpr ?_)).rectangleBorder_integrable
exact ⟨rectangleBorder_subset_rectangle z w, disjoint_singleton_right.mpr pNotOnBorder⟩
theorem HolomorphicOn.rectangleBorderIntegrable' (hf : HolomorphicOn f (Rectangle z w \ {p}))
(hp : Rectangle z w ∈ nhds p) : RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderNoPIntegrable (not_mem_rectangleBorder_of_rectangle_mem_nhds hp)
theorem HolomorphicOn.rectangleBorderIntegrable (hf : HolomorphicOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderIntegrable
/--
Given `x₀ a x₁ : ℝ`, and `y₀ y₁ : ℝ` and a function `f : ℂ → ℂ` so that
both `(t : ℝ) ↦ f(t + y₀ * I)` and `(t : ℝ) ↦ f(t + y₁ * I)` are integrable over both
`t ∈ Icc x₀ a` and `t ∈ Icc a x₁`, we have that
`RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I)` is the sum of
`RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I)` and
`RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I)`.
-/
lemma RectangleIntegralHSplit {a x₀ x₁ y₀ y₁ : ℝ}
(f_int_x₀_a_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume x₀ a)
(f_int_a_x₁_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume a x₁)
(f_int_x₀_a_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume x₀ a)
(f_int_a_x₁_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume a x₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_bot f_int_a_x₁_bot,
← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_top f_int_a_x₁_top]
abel
lemma RectangleIntegralHSplit' {a x₀ x₁ y₀ y₁ : ℝ} (ha : a ∈ [[x₀, x₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) :=
RectangleIntegralHSplit
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
lemma RectangleIntegralVSplit {b x₀ x₁ y₀ y₁ : ℝ}
(f_int_y₀_b_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume y₀ b)
(f_int_b_y₁_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume b y₁)
(f_int_y₀_b_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume y₀ b)
(f_int_b_y₁_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume b y₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_left f_int_b_y₁_left,
← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_right f_int_b_y₁_right, ← sub_eq_zero]
simp only [smul_add]; abel
lemma RectangleIntegralVSplit' {b x₀ x₁ y₀ y₁ : ℝ} (hb : b ∈ [[y₀, y₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) :=
RectangleIntegralVSplit
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
lemma RectanglePullToNhdOfPole' [CompleteSpace E] {z₀ z₁ z₂ z₃ p : ℂ}
(h_orientation : z₀.re ≤ z₃.re ∧ z₀.im ≤ z₃.im ∧ z₁.re ≤ z₂.re ∧ z₁.im ≤ z₂.im)
(hp : Rectangle z₁ z₂ ∈ 𝓝 p) (hz : Rectangle z₁ z₂ ⊆ Rectangle z₀ z₃)
(fHolo : HolomorphicOn f (Rectangle z₀ z₃ \ {p})) :
RectangleIntegral f z₀ z₃ = RectangleIntegral f z₁ z₂ := by
obtain ⟨hz₀_re, hz₀_im, hz₁_re, hz₁_im⟩ := h_orientation
have := rect_subset_iff.mp hz
rw [Rectangle, uIcc_of_le hz₀_re, uIcc_of_le hz₀_im] at this
obtain ⟨⟨⟨_, _⟩, ⟨_, _⟩⟩, ⟨_, _⟩, ⟨_, _⟩⟩ := this
obtain ⟨⟨_, _⟩, ⟨_, _⟩⟩ := (uIoo_of_le hz₁_re) ▸ (uIoo_of_le hz₁_im) ▸ rectangle_mem_nhds_iff.mp hp
obtain ⟨_, _, _, _⟩ := show p.re < z₂.re ∧ p.re < z₃.re ∧ p.im < z₂.im ∧ p.im < z₃.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
obtain ⟨_, _, _, _⟩ := show z₀.re < p.re ∧ z₁.re < p.re ∧ z₀.im < p.im ∧ z₁.im < p.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
have fCont := fHolo.continuousOn
have hbot : RectangleBorderIntegrable f (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have htop : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have hleft : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
have hright : RectangleBorderIntegrable f (↑z₁.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
all_goals try {
refine (fCont.mono (rectangleBorder_subset_punctured_rect ?_ ?_)).rectangleBorder_integrable
· simp_all
· simpa using ⟨by linarith, by linarith, by linarith, by linarith⟩
}
have hbot' : z₁.im ∈ [[z₀.im, z₃.im]] := ?_
have htop' : z₂.im ∈ [[z₁.im, z₃.im]] := ?_
have hleft' : z₁.re ∈ [[z₀.re, z₃.re]] := ?_
have hright' : z₂.re ∈ [[z₁.re, z₃.re]] := ?_
all_goals try { rw [Set.uIcc_of_le]; constructor; all_goals assumption }
have hbot'' : Rectangle (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₁.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have htop'' : Rectangle (↑z₀.re + ↑z₂.im * I) (↑z₃.re + ↑z₃.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hleft'' : Rectangle (↑z₀.re + ↑z₁.im * I) (↑z₁.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hright'' : Rectangle (↑z₂.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
all_goals try { apply rectangle_subset_punctured_rect <;> simp_all }
rw [← re_add_im z₀, ← re_add_im z₃,
RectangleIntegralVSplit' hbot' hbot, fHolo.vanishesOnRectangle hbot'', zero_add,
RectangleIntegralVSplit' htop' htop, fHolo.vanishesOnRectangle htop'', add_zero,
RectangleIntegralHSplit' hleft' hleft, fHolo.vanishesOnRectangle hleft'', zero_add,
RectangleIntegralHSplit' hright' hright, fHolo.vanishesOnRectangle hright'', add_zero,
re_add_im, re_add_im]
/-%%
The next lemma allows to zoom a big rectangle down to a small square, centered at a pole.
\begin{lemma}[RectanglePullToNhdOfPole]\label{RectanglePullToNhdOfPole}\lean{RectanglePullToNhdOfPole}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$ except at a point $p$, then the integral of $f$
over the rectangle with corners $z$ and $w$ is the same as the integral of $f$ over a small square
centered at $p$.
\end{lemma}
%%-/
/-- Given `f` holomorphic on a rectangle `z` and `w` except at a point `p`, the integral of `f` over
the rectangle with corners `z` and `w` is the same as the integral of `f` over a small square
centered at `p`. -/
lemma RectanglePullToNhdOfPole [CompleteSpace E] {z w p : ℂ} (zRe_lt_wRe : z.re ≤ w.re)
(zIm_lt_wIm : z.im ≤ w.im) (hp : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral f z w = RectangleIntegral f (-c - I * c + p) (c + I * c + p) := by
/-%%
\begin{proof}\uses{HolomorphicOn.vanishesOnRectangle}\leanok
Chop the big rectangle with two vertical cuts and two horizontal cuts into smaller rectangles,
the middle one being the desired square. The integral over each of the outer rectangles
vanishes, since $f$ is holomorphic there. (The constant $c$ being ``small enough'' here just means
that the inner square is strictly contained in the big rectangle.)
%%-/
filter_upwards [Ioo_mem_nhdsWithin_Ioi' zero_lt_one, SmallSquareInRectangle hp]
intro c ⟨cpos, _⟩ hc
simp_rw [mul_comm I]
exact RectanglePullToNhdOfPole' (by simp_all [cpos.le])
(square_mem_nhds p (ne_of_gt cpos)) hc fHolo
--%%\end{proof}
lemma RectanglePullToNhdOfPole'' [CompleteSpace E] {z w p : ℂ} (zRe_le_wRe : z.re ≤ w.re)
(zIm_le_wIm : z.im ≤ w.im) (pInRectInterior : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral' f z w = RectangleIntegral' f (-c - I * c + p) (c + I * c + p) := by
filter_upwards [RectanglePullToNhdOfPole zRe_le_wRe zIm_le_wIm pInRectInterior fHolo] with c h
simp_rw [RectangleIntegral', h]
| theorem ResidueTheoremAtOrigin_aux1c (a b : ℝ) :
let f : ℝ → ℂ | ResidueTheoremAtOrigin_aux1c | f36a520 20240122 | 1909a40 20240209 | PrimeNumberTheoremAnd/PrimeNumberTheoremAnd/ResidueCalcOnRectangles.lean | {
"lineInFile": 346,
"tokenPositionInFile": 19068,
"theoremPositionInFile": 35
} | {
"inFilePremises": false,
"repositoryPremises": false
} | {
"hasProof": true,
"proof": ":= fun y => (y + I)⁻¹\n IntervalIntegrable f volume a b :=\n (ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable",
"proofType": "term",
"proofLengthLines": 2,
"proofLengthTokens": 143
} | prime |
import Mathlib.Analysis.Complex.CauchyIntegral
import Mathlib.Analysis.Complex.Convex
import Mathlib.Analysis.Complex.RemovableSingularity
import Mathlib.Analysis.Analytic.Meromorphic
import Mathlib.Analysis.SpecialFunctions.Integrals
import Mathlib.MeasureTheory.Measure.Lebesgue.Integral
import PrimeNumberTheoremAnd.Rectangle
open Complex BigOperators Nat Classical Real Topology Filter Set MeasureTheory intervalIntegral
open scoped Interval
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f g : ℂ → E}
{z w p c A : ℂ} {x x₁ x₂ y y₁ y₂ σ : ℝ}
noncomputable def HIntegral (f : ℂ → E) (x₁ x₂ y : ℝ) : E := ∫ x in x₁..x₂, f (x + y * I)
noncomputable def VIntegral (f : ℂ → E) (x y₁ y₂ : ℝ) : E := I • ∫ y in y₁..y₂, f (x + y * I)
noncomputable def HIntegral' (f : ℂ → E) (x₁ x₂ y : ℝ) : E := (1 / (2 * π * I)) • HIntegral f x₁ x₂ y
noncomputable def VIntegral' (f : ℂ → E) (x y₁ y₂ : ℝ) : E := (1 / (2 * π * I)) • VIntegral f x y₁ y₂
lemma HIntegral_symm : HIntegral f x₁ x₂ y = - HIntegral f x₂ x₁ y := integral_symm _ _
lemma VIntegral_symm : VIntegral f x y₁ y₂ = - VIntegral f x y₂ y₁ := by
simp_rw [VIntegral, integral_symm y₁ y₂, smul_neg, neg_neg]
/-%%
\begin{definition}[RectangleIntegral]\label{RectangleIntegral}\lean{RectangleIntegral}\leanok
A RectangleIntegral of a function $f$ is one over a rectangle determined by $z$ and $w$ in $\C$.
We will sometimes denote it by $\int_{z}^{w} f$. (There is also a primed version, which is $1/(2\pi i)$ times the original.)
\end{definition}
%%-/
/-- A `RectangleIntegral` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`. -/
noncomputable def RectangleIntegral (f : ℂ → E) (z w : ℂ) : E := HIntegral f z.re w.re z.im -
HIntegral f z.re w.re w.im + VIntegral f w.re z.im w.im - VIntegral f z.re z.im w.im
/-- A `RectangleIntegral'` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`, divided by `2 * π * I`. -/
noncomputable abbrev RectangleIntegral' (f : ℂ → E) (z w : ℂ) : E :=
(1 / (2 * π * I)) • RectangleIntegral f z w
/-% ** Wrong delimiter on purpose **
An UpperUIntegral is the integral of a function over a |\_| shape.
\begin{definition}\label{UpperUIntegral}\lean{UpperUIntegral}\leanok
An UpperUIntegral of a function $f$ comes from $\sigma+i\infty$ down to $\sigma+iT$, over to $\sigma'+iT$, and back up to $\sigma'+i\infty$.
\end{definition}
%-/
noncomputable def UpperUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' T +
I • (∫ y : ℝ in Ici T, f (σ' + y * I)) - I • (∫ y : ℝ in Ici T, f (σ + y * I))
/-% ** Wrong delimiter on purpose **
A LowerUIntegral is the integral of a function over a |-| shape.
\begin{definition}[LowerUIntegral]\label{LowerUIntegral}\lean{LowerUIntegral}\leanok
A LowerUIntegral of a function $f$ comes from $\sigma-i\infty$ up to $\sigma-iT$, over to $\sigma'-iT$, and back down to $\sigma'-i\infty$.
\end{definition}
%-/
noncomputable def LowerUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' (-T) -
I • (∫ y : ℝ in Iic (-T), f (σ' + y * I)) + I • (∫ y : ℝ in Iic (-T), f (σ + y * I))
/-%%
It is very convenient to define integrals along vertical lines in the complex plane, as follows.
\begin{definition}[VerticalIntegral]\label{VerticalIntegral}\lean{VerticalIntegral}\leanok
Let $f$ be a function from $\mathbb{C}$ to $\mathbb{C}$, and let $\sigma$ be a real number. Then we define
$$\int_{(\sigma)}f(s)ds = \int_{\sigma-i\infty}^{\sigma+i\infty}f(s)ds.$$
\end{definition}
%%-/
noncomputable def VerticalIntegral (f : ℂ → E) (σ : ℝ) : E := I • ∫ t : ℝ, f (σ + t * I)
--%% We also have a version with a factor of $1/(2\pi i)$.
noncomputable abbrev VerticalIntegral' (f : ℂ → E) (σ : ℝ) : E :=
(1 / (2 * π * I)) • VerticalIntegral f σ
lemma verticalIntegral_split_three (a b : ℝ) (hf : Integrable (fun t : ℝ ↦ f (σ + t * I))) :
VerticalIntegral f σ = I • (∫ t in Iic a, f (σ + t * I)) + VIntegral f σ a b
+ I • ∫ t in Ici b, f (σ + t * I) := by
simp_rw [VerticalIntegral, VIntegral, ← smul_add]
congr
rw [← intervalIntegral.integral_Iic_sub_Iic hf.restrict hf.restrict, add_sub_cancel,
integral_Iic_eq_integral_Iio, intervalIntegral.integral_Iio_add_Ici hf.restrict hf.restrict]
/-% ** Wrong delimiter on purpose **
\begin{lemma}[DiffVertRect_eq_UpperLowerUs]\label{DiffVertRect_eq_UpperLowerUs}\lean{DiffVertRect_eq_UpperLowerUs}\leanok
The difference of two vertical integrals and a rectangle is the difference of an upper and a lower U integrals.
\end{lemma}
%-/
lemma DiffVertRect_eq_UpperLowerUs {σ σ' T : ℝ}
(f_int_σ : Integrable (fun (t : ℝ) ↦ f (σ + t * I)))
(f_int_σ' : Integrable (fun (t : ℝ) ↦ f (σ' + t * I))) :
(VerticalIntegral f σ') - (VerticalIntegral f σ) - (RectangleIntegral f (σ - I * T) (σ' + I * T)) =
(UpperUIntegral f σ σ' T) - (LowerUIntegral f σ σ' T) := by
rw [verticalIntegral_split_three (-T) T f_int_σ, verticalIntegral_split_three (-T) T f_int_σ']
simp only [smul_eq_mul, RectangleIntegral, sub_re, ofReal_re, mul_re, I_re, zero_mul, I_im,
ofReal_im, mul_zero, sub_self, sub_zero, add_re, add_zero, sub_im, mul_im, one_mul, zero_add,
zero_sub, add_im, UpperUIntegral, LowerUIntegral]
abel
/-%
\begin{proof}\uses{UpperUIntegral, LowerUIntegral}\leanok
Follows directly from the definitions.
\end{proof}
%-/
/-- A function is `HolomorphicOn` a set if it is complex differentiable on that set. -/
abbrev HolomorphicOn (f : ℂ → E) (s : Set ℂ) : Prop := DifferentiableOn ℂ f s
/-%%
\begin{theorem}[existsDifferentiableOn_of_bddAbove]\label{existsDifferentiableOn_of_bddAbove}\lean{existsDifferentiableOn_of_bddAbove}\leanok
If $f$ is differentiable on a set $s$ except at $c\in s$, and $f$ is bounded above on $s\setminus\{c\}$, then there exists a differentiable function $g$ on $s$ such that $f$ and $g$ agree on $s\setminus\{c\}$.
\end{theorem}
%%-/
theorem existsDifferentiableOn_of_bddAbove [CompleteSpace E] {s : Set ℂ} {c : ℂ} (hc : s ∈ nhds c)
(hd : HolomorphicOn f (s \ {c})) (hb : BddAbove (norm ∘ f '' (s \ {c}))) :
∃ (g : ℂ → E), HolomorphicOn g s ∧ (Set.EqOn f g (s \ {c})) :=
⟨Function.update f c (limUnder (𝓝[{c}ᶜ] c) f),
differentiableOn_update_limUnder_of_bddAbove hc hd hb,
fun z hz ↦ if h : z = c then (hz.2 h).elim else by simp [h]⟩
/-%%
\begin{proof}\leanok
This is the Riemann Removable Singularity Theorem, slightly rephrased from what's in Mathlib. (We don't care what the function $g$ is, just that it's holomorphic.)
\end{proof}
%%-/
/-%%
\begin{theorem}[HolomorphicOn.vanishesOnRectangle]\label{HolomorphicOn.vanishesOnRectangle}\lean{HolomorphicOn.vanishesOnRectangle}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$, then the integral of $f$ over the rectangle with corners $z$ and $w$ is $0$.
\end{theorem}
%%-/
theorem HolomorphicOn.vanishesOnRectangle [CompleteSpace E] {U : Set ℂ}
(f_holo : HolomorphicOn f U) (hU : Rectangle z w ⊆ U) :
RectangleIntegral f z w = 0 :=
integral_boundary_rect_eq_zero_of_differentiableOn f z w (f_holo.mono hU)
/-%%
\begin{proof}\leanok
This is in a Mathlib PR.
\end{proof}
%%-/
theorem RectangleIntegral_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral f z w = RectangleIntegral g z w := by
unfold RectangleIntegral VIntegral
congr 2; swap; congr 1; swap; congr 1
all_goals refine intervalIntegral.integral_congr fun _ _ ↦ h ?_
· exact Or.inl <| Or.inl <| Or.inl ⟨by simpa, by simp⟩
· exact Or.inl <| Or.inr ⟨by simpa, by simp⟩
· exact Or.inr ⟨by simp, by simpa⟩
· exact Or.inl <| Or.inl <| Or.inr ⟨by simp, by simpa⟩
theorem RectangleIntegral'_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral' f z w = RectangleIntegral' g z w := by
rw [RectangleIntegral', RectangleIntegral_congr h]
theorem rectangleIntegral_symm (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f z w = RectangleIntegral f w z := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, intervalIntegral.integral_symm w.re,
intervalIntegral.integral_symm w.im, sub_neg_eq_add, smul_neg, sub_neg_eq_add, ← sub_eq_add_neg,
neg_add_eq_sub, sub_add_eq_add_sub]
theorem rectangleIntegral_symm_re (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f (w.re + z.im * I) (z.re + w.im * I) = - RectangleIntegral f z w := by
simp [RectangleIntegral, ← sub_eq_zero]
rw [HIntegral_symm (y := z.im), HIntegral_symm (y := w.im)]
abel
def RectangleBorderIntegrable (f : ℂ → E) (z w : ℂ) : Prop :=
IntervalIntegrable (fun x => f (x + z.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun x => f (x + w.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun y => f (w.re + y * I)) volume z.im w.im ∧
IntervalIntegrable (fun y => f (z.re + y * I)) volume z.im w.im
theorem RectangleBorderIntegrable.add {f g : ℂ → E} (hf : RectangleBorderIntegrable f z w)
(hg : RectangleBorderIntegrable g z w) :
RectangleIntegral (f + g) z w = RectangleIntegral f z w + RectangleIntegral g z w := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
rw [intervalIntegral.integral_add hf.1 hg.1, intervalIntegral.integral_add hf.2.1 hg.2.1,
intervalIntegral.integral_add hf.2.2.1 hg.2.2.1, intervalIntegral.integral_add hf.2.2.2 hg.2.2.2]
rw [← sub_eq_zero]
simp only [smul_add]; abel
theorem ContinuousOn.rectangleBorder_integrable (hf : ContinuousOn f (RectangleBorder z w)) :
RectangleBorderIntegrable f z w :=
⟨(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_re z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_re z w)).intervalIntegrable⟩
theorem ContinuousOn.rectangleBorderIntegrable (hf : ContinuousOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
(hf.mono (rectangleBorder_subset_rectangle z w)).rectangleBorder_integrable
theorem ContinuousOn.rectangleBorderNoPIntegrable (hf : ContinuousOn f (Rectangle z w \ {p}))
(pNotOnBorder : p ∉ RectangleBorder z w) : RectangleBorderIntegrable f z w := by
refine (hf.mono (Set.subset_diff.mpr ?_)).rectangleBorder_integrable
exact ⟨rectangleBorder_subset_rectangle z w, disjoint_singleton_right.mpr pNotOnBorder⟩
theorem HolomorphicOn.rectangleBorderIntegrable' (hf : HolomorphicOn f (Rectangle z w \ {p}))
(hp : Rectangle z w ∈ nhds p) : RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderNoPIntegrable (not_mem_rectangleBorder_of_rectangle_mem_nhds hp)
theorem HolomorphicOn.rectangleBorderIntegrable (hf : HolomorphicOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderIntegrable
/--
Given `x₀ a x₁ : ℝ`, and `y₀ y₁ : ℝ` and a function `f : ℂ → ℂ` so that
both `(t : ℝ) ↦ f(t + y₀ * I)` and `(t : ℝ) ↦ f(t + y₁ * I)` are integrable over both
`t ∈ Icc x₀ a` and `t ∈ Icc a x₁`, we have that
`RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I)` is the sum of
`RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I)` and
`RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I)`.
-/
lemma RectangleIntegralHSplit {a x₀ x₁ y₀ y₁ : ℝ}
(f_int_x₀_a_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume x₀ a)
(f_int_a_x₁_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume a x₁)
(f_int_x₀_a_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume x₀ a)
(f_int_a_x₁_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume a x₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_bot f_int_a_x₁_bot,
← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_top f_int_a_x₁_top]
abel
lemma RectangleIntegralHSplit' {a x₀ x₁ y₀ y₁ : ℝ} (ha : a ∈ [[x₀, x₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) :=
RectangleIntegralHSplit
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
lemma RectangleIntegralVSplit {b x₀ x₁ y₀ y₁ : ℝ}
(f_int_y₀_b_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume y₀ b)
(f_int_b_y₁_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume b y₁)
(f_int_y₀_b_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume y₀ b)
(f_int_b_y₁_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume b y₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_left f_int_b_y₁_left,
← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_right f_int_b_y₁_right, ← sub_eq_zero]
simp only [smul_add]; abel
lemma RectangleIntegralVSplit' {b x₀ x₁ y₀ y₁ : ℝ} (hb : b ∈ [[y₀, y₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) :=
RectangleIntegralVSplit
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
lemma RectanglePullToNhdOfPole' [CompleteSpace E] {z₀ z₁ z₂ z₃ p : ℂ}
(h_orientation : z₀.re ≤ z₃.re ∧ z₀.im ≤ z₃.im ∧ z₁.re ≤ z₂.re ∧ z₁.im ≤ z₂.im)
(hp : Rectangle z₁ z₂ ∈ 𝓝 p) (hz : Rectangle z₁ z₂ ⊆ Rectangle z₀ z₃)
(fHolo : HolomorphicOn f (Rectangle z₀ z₃ \ {p})) :
RectangleIntegral f z₀ z₃ = RectangleIntegral f z₁ z₂ := by
obtain ⟨hz₀_re, hz₀_im, hz₁_re, hz₁_im⟩ := h_orientation
have := rect_subset_iff.mp hz
rw [Rectangle, uIcc_of_le hz₀_re, uIcc_of_le hz₀_im] at this
obtain ⟨⟨⟨_, _⟩, ⟨_, _⟩⟩, ⟨_, _⟩, ⟨_, _⟩⟩ := this
obtain ⟨⟨_, _⟩, ⟨_, _⟩⟩ := (uIoo_of_le hz₁_re) ▸ (uIoo_of_le hz₁_im) ▸ rectangle_mem_nhds_iff.mp hp
obtain ⟨_, _, _, _⟩ := show p.re < z₂.re ∧ p.re < z₃.re ∧ p.im < z₂.im ∧ p.im < z₃.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
obtain ⟨_, _, _, _⟩ := show z₀.re < p.re ∧ z₁.re < p.re ∧ z₀.im < p.im ∧ z₁.im < p.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
have fCont := fHolo.continuousOn
have hbot : RectangleBorderIntegrable f (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have htop : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have hleft : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
have hright : RectangleBorderIntegrable f (↑z₁.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
all_goals try {
refine (fCont.mono (rectangleBorder_subset_punctured_rect ?_ ?_)).rectangleBorder_integrable
· simp_all
· simpa using ⟨by linarith, by linarith, by linarith, by linarith⟩
}
have hbot' : z₁.im ∈ [[z₀.im, z₃.im]] := ?_
have htop' : z₂.im ∈ [[z₁.im, z₃.im]] := ?_
have hleft' : z₁.re ∈ [[z₀.re, z₃.re]] := ?_
have hright' : z₂.re ∈ [[z₁.re, z₃.re]] := ?_
all_goals try { rw [Set.uIcc_of_le]; constructor; all_goals assumption }
have hbot'' : Rectangle (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₁.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have htop'' : Rectangle (↑z₀.re + ↑z₂.im * I) (↑z₃.re + ↑z₃.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hleft'' : Rectangle (↑z₀.re + ↑z₁.im * I) (↑z₁.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hright'' : Rectangle (↑z₂.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
all_goals try { apply rectangle_subset_punctured_rect <;> simp_all }
rw [← re_add_im z₀, ← re_add_im z₃,
RectangleIntegralVSplit' hbot' hbot, fHolo.vanishesOnRectangle hbot'', zero_add,
RectangleIntegralVSplit' htop' htop, fHolo.vanishesOnRectangle htop'', add_zero,
RectangleIntegralHSplit' hleft' hleft, fHolo.vanishesOnRectangle hleft'', zero_add,
RectangleIntegralHSplit' hright' hright, fHolo.vanishesOnRectangle hright'', add_zero,
re_add_im, re_add_im]
/-%%
The next lemma allows to zoom a big rectangle down to a small square, centered at a pole.
\begin{lemma}[RectanglePullToNhdOfPole]\label{RectanglePullToNhdOfPole}\lean{RectanglePullToNhdOfPole}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$ except at a point $p$, then the integral of $f$
over the rectangle with corners $z$ and $w$ is the same as the integral of $f$ over a small square
centered at $p$.
\end{lemma}
%%-/
/-- Given `f` holomorphic on a rectangle `z` and `w` except at a point `p`, the integral of `f` over
the rectangle with corners `z` and `w` is the same as the integral of `f` over a small square
centered at `p`. -/
lemma RectanglePullToNhdOfPole [CompleteSpace E] {z w p : ℂ} (zRe_lt_wRe : z.re ≤ w.re)
(zIm_lt_wIm : z.im ≤ w.im) (hp : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral f z w = RectangleIntegral f (-c - I * c + p) (c + I * c + p) := by
/-%%
\begin{proof}\uses{HolomorphicOn.vanishesOnRectangle}\leanok
Chop the big rectangle with two vertical cuts and two horizontal cuts into smaller rectangles,
the middle one being the desired square. The integral over each of the outer rectangles
vanishes, since $f$ is holomorphic there. (The constant $c$ being ``small enough'' here just means
that the inner square is strictly contained in the big rectangle.)
%%-/
filter_upwards [Ioo_mem_nhdsWithin_Ioi' zero_lt_one, SmallSquareInRectangle hp]
intro c ⟨cpos, _⟩ hc
simp_rw [mul_comm I]
exact RectanglePullToNhdOfPole' (by simp_all [cpos.le])
(square_mem_nhds p (ne_of_gt cpos)) hc fHolo
--%%\end{proof}
lemma RectanglePullToNhdOfPole'' [CompleteSpace E] {z w p : ℂ} (zRe_le_wRe : z.re ≤ w.re)
(zIm_le_wIm : z.im ≤ w.im) (pInRectInterior : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral' f z w = RectangleIntegral' f (-c - I * c + p) (c + I * c + p) := by
filter_upwards [RectanglePullToNhdOfPole zRe_le_wRe zIm_le_wIm pInRectInterior fHolo] with c h
simp_rw [RectangleIntegral', h]
theorem ResidueTheoremAtOrigin_aux1c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y + I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
| theorem ResidueTheoremAtOrigin_aux1c' (a b : ℝ) :
let f : ℝ → ℂ | ResidueTheoremAtOrigin_aux1c' | f36a520 20240122 | 1909a40 20240209 | PrimeNumberTheoremAnd/PrimeNumberTheoremAnd/ResidueCalcOnRectangles.lean | {
"lineInFile": 351,
"tokenPositionInFile": 19280,
"theoremPositionInFile": 36
} | {
"inFilePremises": false,
"repositoryPremises": false
} | {
"hasProof": true,
"proof": ":= fun y => (y - I)⁻¹\n IntervalIntegrable f volume a b :=\n (ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable",
"proofType": "term",
"proofLengthLines": 2,
"proofLengthTokens": 143
} | prime |
import Mathlib.Analysis.Complex.CauchyIntegral
import Mathlib.Analysis.Complex.Convex
import Mathlib.Analysis.Complex.RemovableSingularity
import Mathlib.Analysis.Analytic.Meromorphic
import Mathlib.Analysis.SpecialFunctions.Integrals
import Mathlib.MeasureTheory.Measure.Lebesgue.Integral
import PrimeNumberTheoremAnd.Rectangle
open Complex BigOperators Nat Classical Real Topology Filter Set MeasureTheory intervalIntegral
open scoped Interval
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f g : ℂ → E}
{z w p c A : ℂ} {x x₁ x₂ y y₁ y₂ σ : ℝ}
noncomputable def HIntegral (f : ℂ → E) (x₁ x₂ y : ℝ) : E := ∫ x in x₁..x₂, f (x + y * I)
noncomputable def VIntegral (f : ℂ → E) (x y₁ y₂ : ℝ) : E := I • ∫ y in y₁..y₂, f (x + y * I)
noncomputable def HIntegral' (f : ℂ → E) (x₁ x₂ y : ℝ) : E := (1 / (2 * π * I)) • HIntegral f x₁ x₂ y
noncomputable def VIntegral' (f : ℂ → E) (x y₁ y₂ : ℝ) : E := (1 / (2 * π * I)) • VIntegral f x y₁ y₂
lemma HIntegral_symm : HIntegral f x₁ x₂ y = - HIntegral f x₂ x₁ y := integral_symm _ _
lemma VIntegral_symm : VIntegral f x y₁ y₂ = - VIntegral f x y₂ y₁ := by
simp_rw [VIntegral, integral_symm y₁ y₂, smul_neg, neg_neg]
/-%%
\begin{definition}[RectangleIntegral]\label{RectangleIntegral}\lean{RectangleIntegral}\leanok
A RectangleIntegral of a function $f$ is one over a rectangle determined by $z$ and $w$ in $\C$.
We will sometimes denote it by $\int_{z}^{w} f$. (There is also a primed version, which is $1/(2\pi i)$ times the original.)
\end{definition}
%%-/
/-- A `RectangleIntegral` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`. -/
noncomputable def RectangleIntegral (f : ℂ → E) (z w : ℂ) : E := HIntegral f z.re w.re z.im -
HIntegral f z.re w.re w.im + VIntegral f w.re z.im w.im - VIntegral f z.re z.im w.im
/-- A `RectangleIntegral'` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`, divided by `2 * π * I`. -/
noncomputable abbrev RectangleIntegral' (f : ℂ → E) (z w : ℂ) : E :=
(1 / (2 * π * I)) • RectangleIntegral f z w
/-% ** Wrong delimiter on purpose **
An UpperUIntegral is the integral of a function over a |\_| shape.
\begin{definition}\label{UpperUIntegral}\lean{UpperUIntegral}\leanok
An UpperUIntegral of a function $f$ comes from $\sigma+i\infty$ down to $\sigma+iT$, over to $\sigma'+iT$, and back up to $\sigma'+i\infty$.
\end{definition}
%-/
noncomputable def UpperUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' T +
I • (∫ y : ℝ in Ici T, f (σ' + y * I)) - I • (∫ y : ℝ in Ici T, f (σ + y * I))
/-% ** Wrong delimiter on purpose **
A LowerUIntegral is the integral of a function over a |-| shape.
\begin{definition}[LowerUIntegral]\label{LowerUIntegral}\lean{LowerUIntegral}\leanok
A LowerUIntegral of a function $f$ comes from $\sigma-i\infty$ up to $\sigma-iT$, over to $\sigma'-iT$, and back down to $\sigma'-i\infty$.
\end{definition}
%-/
noncomputable def LowerUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' (-T) -
I • (∫ y : ℝ in Iic (-T), f (σ' + y * I)) + I • (∫ y : ℝ in Iic (-T), f (σ + y * I))
/-%%
It is very convenient to define integrals along vertical lines in the complex plane, as follows.
\begin{definition}[VerticalIntegral]\label{VerticalIntegral}\lean{VerticalIntegral}\leanok
Let $f$ be a function from $\mathbb{C}$ to $\mathbb{C}$, and let $\sigma$ be a real number. Then we define
$$\int_{(\sigma)}f(s)ds = \int_{\sigma-i\infty}^{\sigma+i\infty}f(s)ds.$$
\end{definition}
%%-/
noncomputable def VerticalIntegral (f : ℂ → E) (σ : ℝ) : E := I • ∫ t : ℝ, f (σ + t * I)
--%% We also have a version with a factor of $1/(2\pi i)$.
noncomputable abbrev VerticalIntegral' (f : ℂ → E) (σ : ℝ) : E :=
(1 / (2 * π * I)) • VerticalIntegral f σ
lemma verticalIntegral_split_three (a b : ℝ) (hf : Integrable (fun t : ℝ ↦ f (σ + t * I))) :
VerticalIntegral f σ = I • (∫ t in Iic a, f (σ + t * I)) + VIntegral f σ a b
+ I • ∫ t in Ici b, f (σ + t * I) := by
simp_rw [VerticalIntegral, VIntegral, ← smul_add]
congr
rw [← intervalIntegral.integral_Iic_sub_Iic hf.restrict hf.restrict, add_sub_cancel,
integral_Iic_eq_integral_Iio, intervalIntegral.integral_Iio_add_Ici hf.restrict hf.restrict]
/-% ** Wrong delimiter on purpose **
\begin{lemma}[DiffVertRect_eq_UpperLowerUs]\label{DiffVertRect_eq_UpperLowerUs}\lean{DiffVertRect_eq_UpperLowerUs}\leanok
The difference of two vertical integrals and a rectangle is the difference of an upper and a lower U integrals.
\end{lemma}
%-/
lemma DiffVertRect_eq_UpperLowerUs {σ σ' T : ℝ}
(f_int_σ : Integrable (fun (t : ℝ) ↦ f (σ + t * I)))
(f_int_σ' : Integrable (fun (t : ℝ) ↦ f (σ' + t * I))) :
(VerticalIntegral f σ') - (VerticalIntegral f σ) - (RectangleIntegral f (σ - I * T) (σ' + I * T)) =
(UpperUIntegral f σ σ' T) - (LowerUIntegral f σ σ' T) := by
rw [verticalIntegral_split_three (-T) T f_int_σ, verticalIntegral_split_three (-T) T f_int_σ']
simp only [smul_eq_mul, RectangleIntegral, sub_re, ofReal_re, mul_re, I_re, zero_mul, I_im,
ofReal_im, mul_zero, sub_self, sub_zero, add_re, add_zero, sub_im, mul_im, one_mul, zero_add,
zero_sub, add_im, UpperUIntegral, LowerUIntegral]
abel
/-%
\begin{proof}\uses{UpperUIntegral, LowerUIntegral}\leanok
Follows directly from the definitions.
\end{proof}
%-/
/-- A function is `HolomorphicOn` a set if it is complex differentiable on that set. -/
abbrev HolomorphicOn (f : ℂ → E) (s : Set ℂ) : Prop := DifferentiableOn ℂ f s
/-%%
\begin{theorem}[existsDifferentiableOn_of_bddAbove]\label{existsDifferentiableOn_of_bddAbove}\lean{existsDifferentiableOn_of_bddAbove}\leanok
If $f$ is differentiable on a set $s$ except at $c\in s$, and $f$ is bounded above on $s\setminus\{c\}$, then there exists a differentiable function $g$ on $s$ such that $f$ and $g$ agree on $s\setminus\{c\}$.
\end{theorem}
%%-/
theorem existsDifferentiableOn_of_bddAbove [CompleteSpace E] {s : Set ℂ} {c : ℂ} (hc : s ∈ nhds c)
(hd : HolomorphicOn f (s \ {c})) (hb : BddAbove (norm ∘ f '' (s \ {c}))) :
∃ (g : ℂ → E), HolomorphicOn g s ∧ (Set.EqOn f g (s \ {c})) :=
⟨Function.update f c (limUnder (𝓝[{c}ᶜ] c) f),
differentiableOn_update_limUnder_of_bddAbove hc hd hb,
fun z hz ↦ if h : z = c then (hz.2 h).elim else by simp [h]⟩
/-%%
\begin{proof}\leanok
This is the Riemann Removable Singularity Theorem, slightly rephrased from what's in Mathlib. (We don't care what the function $g$ is, just that it's holomorphic.)
\end{proof}
%%-/
/-%%
\begin{theorem}[HolomorphicOn.vanishesOnRectangle]\label{HolomorphicOn.vanishesOnRectangle}\lean{HolomorphicOn.vanishesOnRectangle}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$, then the integral of $f$ over the rectangle with corners $z$ and $w$ is $0$.
\end{theorem}
%%-/
theorem HolomorphicOn.vanishesOnRectangle [CompleteSpace E] {U : Set ℂ}
(f_holo : HolomorphicOn f U) (hU : Rectangle z w ⊆ U) :
RectangleIntegral f z w = 0 :=
integral_boundary_rect_eq_zero_of_differentiableOn f z w (f_holo.mono hU)
/-%%
\begin{proof}\leanok
This is in a Mathlib PR.
\end{proof}
%%-/
theorem RectangleIntegral_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral f z w = RectangleIntegral g z w := by
unfold RectangleIntegral VIntegral
congr 2; swap; congr 1; swap; congr 1
all_goals refine intervalIntegral.integral_congr fun _ _ ↦ h ?_
· exact Or.inl <| Or.inl <| Or.inl ⟨by simpa, by simp⟩
· exact Or.inl <| Or.inr ⟨by simpa, by simp⟩
· exact Or.inr ⟨by simp, by simpa⟩
· exact Or.inl <| Or.inl <| Or.inr ⟨by simp, by simpa⟩
theorem RectangleIntegral'_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral' f z w = RectangleIntegral' g z w := by
rw [RectangleIntegral', RectangleIntegral_congr h]
theorem rectangleIntegral_symm (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f z w = RectangleIntegral f w z := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, intervalIntegral.integral_symm w.re,
intervalIntegral.integral_symm w.im, sub_neg_eq_add, smul_neg, sub_neg_eq_add, ← sub_eq_add_neg,
neg_add_eq_sub, sub_add_eq_add_sub]
theorem rectangleIntegral_symm_re (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f (w.re + z.im * I) (z.re + w.im * I) = - RectangleIntegral f z w := by
simp [RectangleIntegral, ← sub_eq_zero]
rw [HIntegral_symm (y := z.im), HIntegral_symm (y := w.im)]
abel
def RectangleBorderIntegrable (f : ℂ → E) (z w : ℂ) : Prop :=
IntervalIntegrable (fun x => f (x + z.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun x => f (x + w.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun y => f (w.re + y * I)) volume z.im w.im ∧
IntervalIntegrable (fun y => f (z.re + y * I)) volume z.im w.im
theorem RectangleBorderIntegrable.add {f g : ℂ → E} (hf : RectangleBorderIntegrable f z w)
(hg : RectangleBorderIntegrable g z w) :
RectangleIntegral (f + g) z w = RectangleIntegral f z w + RectangleIntegral g z w := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
rw [intervalIntegral.integral_add hf.1 hg.1, intervalIntegral.integral_add hf.2.1 hg.2.1,
intervalIntegral.integral_add hf.2.2.1 hg.2.2.1, intervalIntegral.integral_add hf.2.2.2 hg.2.2.2]
rw [← sub_eq_zero]
simp only [smul_add]; abel
theorem ContinuousOn.rectangleBorder_integrable (hf : ContinuousOn f (RectangleBorder z w)) :
RectangleBorderIntegrable f z w :=
⟨(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_re z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_re z w)).intervalIntegrable⟩
theorem ContinuousOn.rectangleBorderIntegrable (hf : ContinuousOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
(hf.mono (rectangleBorder_subset_rectangle z w)).rectangleBorder_integrable
theorem ContinuousOn.rectangleBorderNoPIntegrable (hf : ContinuousOn f (Rectangle z w \ {p}))
(pNotOnBorder : p ∉ RectangleBorder z w) : RectangleBorderIntegrable f z w := by
refine (hf.mono (Set.subset_diff.mpr ?_)).rectangleBorder_integrable
exact ⟨rectangleBorder_subset_rectangle z w, disjoint_singleton_right.mpr pNotOnBorder⟩
theorem HolomorphicOn.rectangleBorderIntegrable' (hf : HolomorphicOn f (Rectangle z w \ {p}))
(hp : Rectangle z w ∈ nhds p) : RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderNoPIntegrable (not_mem_rectangleBorder_of_rectangle_mem_nhds hp)
theorem HolomorphicOn.rectangleBorderIntegrable (hf : HolomorphicOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderIntegrable
/--
Given `x₀ a x₁ : ℝ`, and `y₀ y₁ : ℝ` and a function `f : ℂ → ℂ` so that
both `(t : ℝ) ↦ f(t + y₀ * I)` and `(t : ℝ) ↦ f(t + y₁ * I)` are integrable over both
`t ∈ Icc x₀ a` and `t ∈ Icc a x₁`, we have that
`RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I)` is the sum of
`RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I)` and
`RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I)`.
-/
lemma RectangleIntegralHSplit {a x₀ x₁ y₀ y₁ : ℝ}
(f_int_x₀_a_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume x₀ a)
(f_int_a_x₁_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume a x₁)
(f_int_x₀_a_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume x₀ a)
(f_int_a_x₁_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume a x₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_bot f_int_a_x₁_bot,
← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_top f_int_a_x₁_top]
abel
lemma RectangleIntegralHSplit' {a x₀ x₁ y₀ y₁ : ℝ} (ha : a ∈ [[x₀, x₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) :=
RectangleIntegralHSplit
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
lemma RectangleIntegralVSplit {b x₀ x₁ y₀ y₁ : ℝ}
(f_int_y₀_b_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume y₀ b)
(f_int_b_y₁_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume b y₁)
(f_int_y₀_b_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume y₀ b)
(f_int_b_y₁_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume b y₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_left f_int_b_y₁_left,
← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_right f_int_b_y₁_right, ← sub_eq_zero]
simp only [smul_add]; abel
lemma RectangleIntegralVSplit' {b x₀ x₁ y₀ y₁ : ℝ} (hb : b ∈ [[y₀, y₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) :=
RectangleIntegralVSplit
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
lemma RectanglePullToNhdOfPole' [CompleteSpace E] {z₀ z₁ z₂ z₃ p : ℂ}
(h_orientation : z₀.re ≤ z₃.re ∧ z₀.im ≤ z₃.im ∧ z₁.re ≤ z₂.re ∧ z₁.im ≤ z₂.im)
(hp : Rectangle z₁ z₂ ∈ 𝓝 p) (hz : Rectangle z₁ z₂ ⊆ Rectangle z₀ z₃)
(fHolo : HolomorphicOn f (Rectangle z₀ z₃ \ {p})) :
RectangleIntegral f z₀ z₃ = RectangleIntegral f z₁ z₂ := by
obtain ⟨hz₀_re, hz₀_im, hz₁_re, hz₁_im⟩ := h_orientation
have := rect_subset_iff.mp hz
rw [Rectangle, uIcc_of_le hz₀_re, uIcc_of_le hz₀_im] at this
obtain ⟨⟨⟨_, _⟩, ⟨_, _⟩⟩, ⟨_, _⟩, ⟨_, _⟩⟩ := this
obtain ⟨⟨_, _⟩, ⟨_, _⟩⟩ := (uIoo_of_le hz₁_re) ▸ (uIoo_of_le hz₁_im) ▸ rectangle_mem_nhds_iff.mp hp
obtain ⟨_, _, _, _⟩ := show p.re < z₂.re ∧ p.re < z₃.re ∧ p.im < z₂.im ∧ p.im < z₃.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
obtain ⟨_, _, _, _⟩ := show z₀.re < p.re ∧ z₁.re < p.re ∧ z₀.im < p.im ∧ z₁.im < p.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
have fCont := fHolo.continuousOn
have hbot : RectangleBorderIntegrable f (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have htop : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have hleft : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
have hright : RectangleBorderIntegrable f (↑z₁.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
all_goals try {
refine (fCont.mono (rectangleBorder_subset_punctured_rect ?_ ?_)).rectangleBorder_integrable
· simp_all
· simpa using ⟨by linarith, by linarith, by linarith, by linarith⟩
}
have hbot' : z₁.im ∈ [[z₀.im, z₃.im]] := ?_
have htop' : z₂.im ∈ [[z₁.im, z₃.im]] := ?_
have hleft' : z₁.re ∈ [[z₀.re, z₃.re]] := ?_
have hright' : z₂.re ∈ [[z₁.re, z₃.re]] := ?_
all_goals try { rw [Set.uIcc_of_le]; constructor; all_goals assumption }
have hbot'' : Rectangle (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₁.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have htop'' : Rectangle (↑z₀.re + ↑z₂.im * I) (↑z₃.re + ↑z₃.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hleft'' : Rectangle (↑z₀.re + ↑z₁.im * I) (↑z₁.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hright'' : Rectangle (↑z₂.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
all_goals try { apply rectangle_subset_punctured_rect <;> simp_all }
rw [← re_add_im z₀, ← re_add_im z₃,
RectangleIntegralVSplit' hbot' hbot, fHolo.vanishesOnRectangle hbot'', zero_add,
RectangleIntegralVSplit' htop' htop, fHolo.vanishesOnRectangle htop'', add_zero,
RectangleIntegralHSplit' hleft' hleft, fHolo.vanishesOnRectangle hleft'', zero_add,
RectangleIntegralHSplit' hright' hright, fHolo.vanishesOnRectangle hright'', add_zero,
re_add_im, re_add_im]
/-%%
The next lemma allows to zoom a big rectangle down to a small square, centered at a pole.
\begin{lemma}[RectanglePullToNhdOfPole]\label{RectanglePullToNhdOfPole}\lean{RectanglePullToNhdOfPole}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$ except at a point $p$, then the integral of $f$
over the rectangle with corners $z$ and $w$ is the same as the integral of $f$ over a small square
centered at $p$.
\end{lemma}
%%-/
/-- Given `f` holomorphic on a rectangle `z` and `w` except at a point `p`, the integral of `f` over
the rectangle with corners `z` and `w` is the same as the integral of `f` over a small square
centered at `p`. -/
lemma RectanglePullToNhdOfPole [CompleteSpace E] {z w p : ℂ} (zRe_lt_wRe : z.re ≤ w.re)
(zIm_lt_wIm : z.im ≤ w.im) (hp : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral f z w = RectangleIntegral f (-c - I * c + p) (c + I * c + p) := by
/-%%
\begin{proof}\uses{HolomorphicOn.vanishesOnRectangle}\leanok
Chop the big rectangle with two vertical cuts and two horizontal cuts into smaller rectangles,
the middle one being the desired square. The integral over each of the outer rectangles
vanishes, since $f$ is holomorphic there. (The constant $c$ being ``small enough'' here just means
that the inner square is strictly contained in the big rectangle.)
%%-/
filter_upwards [Ioo_mem_nhdsWithin_Ioi' zero_lt_one, SmallSquareInRectangle hp]
intro c ⟨cpos, _⟩ hc
simp_rw [mul_comm I]
exact RectanglePullToNhdOfPole' (by simp_all [cpos.le])
(square_mem_nhds p (ne_of_gt cpos)) hc fHolo
--%%\end{proof}
lemma RectanglePullToNhdOfPole'' [CompleteSpace E] {z w p : ℂ} (zRe_le_wRe : z.re ≤ w.re)
(zIm_le_wIm : z.im ≤ w.im) (pInRectInterior : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral' f z w = RectangleIntegral' f (-c - I * c + p) (c + I * c + p) := by
filter_upwards [RectanglePullToNhdOfPole zRe_le_wRe zIm_le_wIm pInRectInterior fHolo] with c h
simp_rw [RectangleIntegral', h]
theorem ResidueTheoremAtOrigin_aux1c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y + I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux1c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y - I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
| theorem ResidueTheoremAtOrigin_aux2c (a b : ℝ) :
let f : ℝ → ℂ | ResidueTheoremAtOrigin_aux2c | f36a520 20240122 | 1909a40 20240209 | PrimeNumberTheoremAnd/PrimeNumberTheoremAnd/ResidueCalcOnRectangles.lean | {
"lineInFile": 356,
"tokenPositionInFile": 19493,
"theoremPositionInFile": 37
} | {
"inFilePremises": false,
"repositoryPremises": false
} | {
"hasProof": true,
"proof": ":= fun y => (1 + y * I)⁻¹\n IntervalIntegrable f volume a b :=\n (ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable",
"proofType": "term",
"proofLengthLines": 2,
"proofLengthTokens": 147
} | prime |
import Mathlib.Analysis.Complex.CauchyIntegral
import Mathlib.Analysis.Complex.Convex
import Mathlib.Analysis.Complex.RemovableSingularity
import Mathlib.Analysis.Analytic.Meromorphic
import Mathlib.Analysis.SpecialFunctions.Integrals
import Mathlib.MeasureTheory.Measure.Lebesgue.Integral
import PrimeNumberTheoremAnd.Rectangle
open Complex BigOperators Nat Classical Real Topology Filter Set MeasureTheory intervalIntegral
open scoped Interval
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f g : ℂ → E}
{z w p c A : ℂ} {x x₁ x₂ y y₁ y₂ σ : ℝ}
noncomputable def HIntegral (f : ℂ → E) (x₁ x₂ y : ℝ) : E := ∫ x in x₁..x₂, f (x + y * I)
noncomputable def VIntegral (f : ℂ → E) (x y₁ y₂ : ℝ) : E := I • ∫ y in y₁..y₂, f (x + y * I)
noncomputable def HIntegral' (f : ℂ → E) (x₁ x₂ y : ℝ) : E := (1 / (2 * π * I)) • HIntegral f x₁ x₂ y
noncomputable def VIntegral' (f : ℂ → E) (x y₁ y₂ : ℝ) : E := (1 / (2 * π * I)) • VIntegral f x y₁ y₂
lemma HIntegral_symm : HIntegral f x₁ x₂ y = - HIntegral f x₂ x₁ y := integral_symm _ _
lemma VIntegral_symm : VIntegral f x y₁ y₂ = - VIntegral f x y₂ y₁ := by
simp_rw [VIntegral, integral_symm y₁ y₂, smul_neg, neg_neg]
/-%%
\begin{definition}[RectangleIntegral]\label{RectangleIntegral}\lean{RectangleIntegral}\leanok
A RectangleIntegral of a function $f$ is one over a rectangle determined by $z$ and $w$ in $\C$.
We will sometimes denote it by $\int_{z}^{w} f$. (There is also a primed version, which is $1/(2\pi i)$ times the original.)
\end{definition}
%%-/
/-- A `RectangleIntegral` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`. -/
noncomputable def RectangleIntegral (f : ℂ → E) (z w : ℂ) : E := HIntegral f z.re w.re z.im -
HIntegral f z.re w.re w.im + VIntegral f w.re z.im w.im - VIntegral f z.re z.im w.im
/-- A `RectangleIntegral'` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`, divided by `2 * π * I`. -/
noncomputable abbrev RectangleIntegral' (f : ℂ → E) (z w : ℂ) : E :=
(1 / (2 * π * I)) • RectangleIntegral f z w
/-% ** Wrong delimiter on purpose **
An UpperUIntegral is the integral of a function over a |\_| shape.
\begin{definition}\label{UpperUIntegral}\lean{UpperUIntegral}\leanok
An UpperUIntegral of a function $f$ comes from $\sigma+i\infty$ down to $\sigma+iT$, over to $\sigma'+iT$, and back up to $\sigma'+i\infty$.
\end{definition}
%-/
noncomputable def UpperUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' T +
I • (∫ y : ℝ in Ici T, f (σ' + y * I)) - I • (∫ y : ℝ in Ici T, f (σ + y * I))
/-% ** Wrong delimiter on purpose **
A LowerUIntegral is the integral of a function over a |-| shape.
\begin{definition}[LowerUIntegral]\label{LowerUIntegral}\lean{LowerUIntegral}\leanok
A LowerUIntegral of a function $f$ comes from $\sigma-i\infty$ up to $\sigma-iT$, over to $\sigma'-iT$, and back down to $\sigma'-i\infty$.
\end{definition}
%-/
noncomputable def LowerUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' (-T) -
I • (∫ y : ℝ in Iic (-T), f (σ' + y * I)) + I • (∫ y : ℝ in Iic (-T), f (σ + y * I))
/-%%
It is very convenient to define integrals along vertical lines in the complex plane, as follows.
\begin{definition}[VerticalIntegral]\label{VerticalIntegral}\lean{VerticalIntegral}\leanok
Let $f$ be a function from $\mathbb{C}$ to $\mathbb{C}$, and let $\sigma$ be a real number. Then we define
$$\int_{(\sigma)}f(s)ds = \int_{\sigma-i\infty}^{\sigma+i\infty}f(s)ds.$$
\end{definition}
%%-/
noncomputable def VerticalIntegral (f : ℂ → E) (σ : ℝ) : E := I • ∫ t : ℝ, f (σ + t * I)
--%% We also have a version with a factor of $1/(2\pi i)$.
noncomputable abbrev VerticalIntegral' (f : ℂ → E) (σ : ℝ) : E :=
(1 / (2 * π * I)) • VerticalIntegral f σ
lemma verticalIntegral_split_three (a b : ℝ) (hf : Integrable (fun t : ℝ ↦ f (σ + t * I))) :
VerticalIntegral f σ = I • (∫ t in Iic a, f (σ + t * I)) + VIntegral f σ a b
+ I • ∫ t in Ici b, f (σ + t * I) := by
simp_rw [VerticalIntegral, VIntegral, ← smul_add]
congr
rw [← intervalIntegral.integral_Iic_sub_Iic hf.restrict hf.restrict, add_sub_cancel,
integral_Iic_eq_integral_Iio, intervalIntegral.integral_Iio_add_Ici hf.restrict hf.restrict]
/-% ** Wrong delimiter on purpose **
\begin{lemma}[DiffVertRect_eq_UpperLowerUs]\label{DiffVertRect_eq_UpperLowerUs}\lean{DiffVertRect_eq_UpperLowerUs}\leanok
The difference of two vertical integrals and a rectangle is the difference of an upper and a lower U integrals.
\end{lemma}
%-/
lemma DiffVertRect_eq_UpperLowerUs {σ σ' T : ℝ}
(f_int_σ : Integrable (fun (t : ℝ) ↦ f (σ + t * I)))
(f_int_σ' : Integrable (fun (t : ℝ) ↦ f (σ' + t * I))) :
(VerticalIntegral f σ') - (VerticalIntegral f σ) - (RectangleIntegral f (σ - I * T) (σ' + I * T)) =
(UpperUIntegral f σ σ' T) - (LowerUIntegral f σ σ' T) := by
rw [verticalIntegral_split_three (-T) T f_int_σ, verticalIntegral_split_three (-T) T f_int_σ']
simp only [smul_eq_mul, RectangleIntegral, sub_re, ofReal_re, mul_re, I_re, zero_mul, I_im,
ofReal_im, mul_zero, sub_self, sub_zero, add_re, add_zero, sub_im, mul_im, one_mul, zero_add,
zero_sub, add_im, UpperUIntegral, LowerUIntegral]
abel
/-%
\begin{proof}\uses{UpperUIntegral, LowerUIntegral}\leanok
Follows directly from the definitions.
\end{proof}
%-/
/-- A function is `HolomorphicOn` a set if it is complex differentiable on that set. -/
abbrev HolomorphicOn (f : ℂ → E) (s : Set ℂ) : Prop := DifferentiableOn ℂ f s
/-%%
\begin{theorem}[existsDifferentiableOn_of_bddAbove]\label{existsDifferentiableOn_of_bddAbove}\lean{existsDifferentiableOn_of_bddAbove}\leanok
If $f$ is differentiable on a set $s$ except at $c\in s$, and $f$ is bounded above on $s\setminus\{c\}$, then there exists a differentiable function $g$ on $s$ such that $f$ and $g$ agree on $s\setminus\{c\}$.
\end{theorem}
%%-/
theorem existsDifferentiableOn_of_bddAbove [CompleteSpace E] {s : Set ℂ} {c : ℂ} (hc : s ∈ nhds c)
(hd : HolomorphicOn f (s \ {c})) (hb : BddAbove (norm ∘ f '' (s \ {c}))) :
∃ (g : ℂ → E), HolomorphicOn g s ∧ (Set.EqOn f g (s \ {c})) :=
⟨Function.update f c (limUnder (𝓝[{c}ᶜ] c) f),
differentiableOn_update_limUnder_of_bddAbove hc hd hb,
fun z hz ↦ if h : z = c then (hz.2 h).elim else by simp [h]⟩
/-%%
\begin{proof}\leanok
This is the Riemann Removable Singularity Theorem, slightly rephrased from what's in Mathlib. (We don't care what the function $g$ is, just that it's holomorphic.)
\end{proof}
%%-/
/-%%
\begin{theorem}[HolomorphicOn.vanishesOnRectangle]\label{HolomorphicOn.vanishesOnRectangle}\lean{HolomorphicOn.vanishesOnRectangle}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$, then the integral of $f$ over the rectangle with corners $z$ and $w$ is $0$.
\end{theorem}
%%-/
theorem HolomorphicOn.vanishesOnRectangle [CompleteSpace E] {U : Set ℂ}
(f_holo : HolomorphicOn f U) (hU : Rectangle z w ⊆ U) :
RectangleIntegral f z w = 0 :=
integral_boundary_rect_eq_zero_of_differentiableOn f z w (f_holo.mono hU)
/-%%
\begin{proof}\leanok
This is in a Mathlib PR.
\end{proof}
%%-/
theorem RectangleIntegral_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral f z w = RectangleIntegral g z w := by
unfold RectangleIntegral VIntegral
congr 2; swap; congr 1; swap; congr 1
all_goals refine intervalIntegral.integral_congr fun _ _ ↦ h ?_
· exact Or.inl <| Or.inl <| Or.inl ⟨by simpa, by simp⟩
· exact Or.inl <| Or.inr ⟨by simpa, by simp⟩
· exact Or.inr ⟨by simp, by simpa⟩
· exact Or.inl <| Or.inl <| Or.inr ⟨by simp, by simpa⟩
theorem RectangleIntegral'_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral' f z w = RectangleIntegral' g z w := by
rw [RectangleIntegral', RectangleIntegral_congr h]
theorem rectangleIntegral_symm (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f z w = RectangleIntegral f w z := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, intervalIntegral.integral_symm w.re,
intervalIntegral.integral_symm w.im, sub_neg_eq_add, smul_neg, sub_neg_eq_add, ← sub_eq_add_neg,
neg_add_eq_sub, sub_add_eq_add_sub]
theorem rectangleIntegral_symm_re (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f (w.re + z.im * I) (z.re + w.im * I) = - RectangleIntegral f z w := by
simp [RectangleIntegral, ← sub_eq_zero]
rw [HIntegral_symm (y := z.im), HIntegral_symm (y := w.im)]
abel
def RectangleBorderIntegrable (f : ℂ → E) (z w : ℂ) : Prop :=
IntervalIntegrable (fun x => f (x + z.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun x => f (x + w.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun y => f (w.re + y * I)) volume z.im w.im ∧
IntervalIntegrable (fun y => f (z.re + y * I)) volume z.im w.im
theorem RectangleBorderIntegrable.add {f g : ℂ → E} (hf : RectangleBorderIntegrable f z w)
(hg : RectangleBorderIntegrable g z w) :
RectangleIntegral (f + g) z w = RectangleIntegral f z w + RectangleIntegral g z w := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
rw [intervalIntegral.integral_add hf.1 hg.1, intervalIntegral.integral_add hf.2.1 hg.2.1,
intervalIntegral.integral_add hf.2.2.1 hg.2.2.1, intervalIntegral.integral_add hf.2.2.2 hg.2.2.2]
rw [← sub_eq_zero]
simp only [smul_add]; abel
theorem ContinuousOn.rectangleBorder_integrable (hf : ContinuousOn f (RectangleBorder z w)) :
RectangleBorderIntegrable f z w :=
⟨(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_re z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_re z w)).intervalIntegrable⟩
theorem ContinuousOn.rectangleBorderIntegrable (hf : ContinuousOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
(hf.mono (rectangleBorder_subset_rectangle z w)).rectangleBorder_integrable
theorem ContinuousOn.rectangleBorderNoPIntegrable (hf : ContinuousOn f (Rectangle z w \ {p}))
(pNotOnBorder : p ∉ RectangleBorder z w) : RectangleBorderIntegrable f z w := by
refine (hf.mono (Set.subset_diff.mpr ?_)).rectangleBorder_integrable
exact ⟨rectangleBorder_subset_rectangle z w, disjoint_singleton_right.mpr pNotOnBorder⟩
theorem HolomorphicOn.rectangleBorderIntegrable' (hf : HolomorphicOn f (Rectangle z w \ {p}))
(hp : Rectangle z w ∈ nhds p) : RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderNoPIntegrable (not_mem_rectangleBorder_of_rectangle_mem_nhds hp)
theorem HolomorphicOn.rectangleBorderIntegrable (hf : HolomorphicOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderIntegrable
/--
Given `x₀ a x₁ : ℝ`, and `y₀ y₁ : ℝ` and a function `f : ℂ → ℂ` so that
both `(t : ℝ) ↦ f(t + y₀ * I)` and `(t : ℝ) ↦ f(t + y₁ * I)` are integrable over both
`t ∈ Icc x₀ a` and `t ∈ Icc a x₁`, we have that
`RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I)` is the sum of
`RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I)` and
`RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I)`.
-/
lemma RectangleIntegralHSplit {a x₀ x₁ y₀ y₁ : ℝ}
(f_int_x₀_a_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume x₀ a)
(f_int_a_x₁_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume a x₁)
(f_int_x₀_a_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume x₀ a)
(f_int_a_x₁_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume a x₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_bot f_int_a_x₁_bot,
← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_top f_int_a_x₁_top]
abel
lemma RectangleIntegralHSplit' {a x₀ x₁ y₀ y₁ : ℝ} (ha : a ∈ [[x₀, x₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) :=
RectangleIntegralHSplit
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
lemma RectangleIntegralVSplit {b x₀ x₁ y₀ y₁ : ℝ}
(f_int_y₀_b_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume y₀ b)
(f_int_b_y₁_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume b y₁)
(f_int_y₀_b_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume y₀ b)
(f_int_b_y₁_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume b y₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_left f_int_b_y₁_left,
← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_right f_int_b_y₁_right, ← sub_eq_zero]
simp only [smul_add]; abel
lemma RectangleIntegralVSplit' {b x₀ x₁ y₀ y₁ : ℝ} (hb : b ∈ [[y₀, y₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) :=
RectangleIntegralVSplit
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
lemma RectanglePullToNhdOfPole' [CompleteSpace E] {z₀ z₁ z₂ z₃ p : ℂ}
(h_orientation : z₀.re ≤ z₃.re ∧ z₀.im ≤ z₃.im ∧ z₁.re ≤ z₂.re ∧ z₁.im ≤ z₂.im)
(hp : Rectangle z₁ z₂ ∈ 𝓝 p) (hz : Rectangle z₁ z₂ ⊆ Rectangle z₀ z₃)
(fHolo : HolomorphicOn f (Rectangle z₀ z₃ \ {p})) :
RectangleIntegral f z₀ z₃ = RectangleIntegral f z₁ z₂ := by
obtain ⟨hz₀_re, hz₀_im, hz₁_re, hz₁_im⟩ := h_orientation
have := rect_subset_iff.mp hz
rw [Rectangle, uIcc_of_le hz₀_re, uIcc_of_le hz₀_im] at this
obtain ⟨⟨⟨_, _⟩, ⟨_, _⟩⟩, ⟨_, _⟩, ⟨_, _⟩⟩ := this
obtain ⟨⟨_, _⟩, ⟨_, _⟩⟩ := (uIoo_of_le hz₁_re) ▸ (uIoo_of_le hz₁_im) ▸ rectangle_mem_nhds_iff.mp hp
obtain ⟨_, _, _, _⟩ := show p.re < z₂.re ∧ p.re < z₃.re ∧ p.im < z₂.im ∧ p.im < z₃.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
obtain ⟨_, _, _, _⟩ := show z₀.re < p.re ∧ z₁.re < p.re ∧ z₀.im < p.im ∧ z₁.im < p.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
have fCont := fHolo.continuousOn
have hbot : RectangleBorderIntegrable f (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have htop : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have hleft : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
have hright : RectangleBorderIntegrable f (↑z₁.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
all_goals try {
refine (fCont.mono (rectangleBorder_subset_punctured_rect ?_ ?_)).rectangleBorder_integrable
· simp_all
· simpa using ⟨by linarith, by linarith, by linarith, by linarith⟩
}
have hbot' : z₁.im ∈ [[z₀.im, z₃.im]] := ?_
have htop' : z₂.im ∈ [[z₁.im, z₃.im]] := ?_
have hleft' : z₁.re ∈ [[z₀.re, z₃.re]] := ?_
have hright' : z₂.re ∈ [[z₁.re, z₃.re]] := ?_
all_goals try { rw [Set.uIcc_of_le]; constructor; all_goals assumption }
have hbot'' : Rectangle (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₁.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have htop'' : Rectangle (↑z₀.re + ↑z₂.im * I) (↑z₃.re + ↑z₃.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hleft'' : Rectangle (↑z₀.re + ↑z₁.im * I) (↑z₁.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hright'' : Rectangle (↑z₂.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
all_goals try { apply rectangle_subset_punctured_rect <;> simp_all }
rw [← re_add_im z₀, ← re_add_im z₃,
RectangleIntegralVSplit' hbot' hbot, fHolo.vanishesOnRectangle hbot'', zero_add,
RectangleIntegralVSplit' htop' htop, fHolo.vanishesOnRectangle htop'', add_zero,
RectangleIntegralHSplit' hleft' hleft, fHolo.vanishesOnRectangle hleft'', zero_add,
RectangleIntegralHSplit' hright' hright, fHolo.vanishesOnRectangle hright'', add_zero,
re_add_im, re_add_im]
/-%%
The next lemma allows to zoom a big rectangle down to a small square, centered at a pole.
\begin{lemma}[RectanglePullToNhdOfPole]\label{RectanglePullToNhdOfPole}\lean{RectanglePullToNhdOfPole}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$ except at a point $p$, then the integral of $f$
over the rectangle with corners $z$ and $w$ is the same as the integral of $f$ over a small square
centered at $p$.
\end{lemma}
%%-/
/-- Given `f` holomorphic on a rectangle `z` and `w` except at a point `p`, the integral of `f` over
the rectangle with corners `z` and `w` is the same as the integral of `f` over a small square
centered at `p`. -/
lemma RectanglePullToNhdOfPole [CompleteSpace E] {z w p : ℂ} (zRe_lt_wRe : z.re ≤ w.re)
(zIm_lt_wIm : z.im ≤ w.im) (hp : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral f z w = RectangleIntegral f (-c - I * c + p) (c + I * c + p) := by
/-%%
\begin{proof}\uses{HolomorphicOn.vanishesOnRectangle}\leanok
Chop the big rectangle with two vertical cuts and two horizontal cuts into smaller rectangles,
the middle one being the desired square. The integral over each of the outer rectangles
vanishes, since $f$ is holomorphic there. (The constant $c$ being ``small enough'' here just means
that the inner square is strictly contained in the big rectangle.)
%%-/
filter_upwards [Ioo_mem_nhdsWithin_Ioi' zero_lt_one, SmallSquareInRectangle hp]
intro c ⟨cpos, _⟩ hc
simp_rw [mul_comm I]
exact RectanglePullToNhdOfPole' (by simp_all [cpos.le])
(square_mem_nhds p (ne_of_gt cpos)) hc fHolo
--%%\end{proof}
lemma RectanglePullToNhdOfPole'' [CompleteSpace E] {z w p : ℂ} (zRe_le_wRe : z.re ≤ w.re)
(zIm_le_wIm : z.im ≤ w.im) (pInRectInterior : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral' f z w = RectangleIntegral' f (-c - I * c + p) (c + I * c + p) := by
filter_upwards [RectanglePullToNhdOfPole zRe_le_wRe zIm_le_wIm pInRectInterior fHolo] with c h
simp_rw [RectangleIntegral', h]
theorem ResidueTheoremAtOrigin_aux1c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y + I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux1c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y - I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
| theorem ResidueTheoremAtOrigin_aux2c' (a b : ℝ) :
let f : ℝ → ℂ | ResidueTheoremAtOrigin_aux2c' | f36a520 20240122 | 1909a40 20240209 | PrimeNumberTheoremAnd/PrimeNumberTheoremAnd/ResidueCalcOnRectangles.lean | {
"lineInFile": 361,
"tokenPositionInFile": 19709,
"theoremPositionInFile": 38
} | {
"inFilePremises": false,
"repositoryPremises": false
} | {
"hasProof": true,
"proof": ":= fun y => (-1 + y * I)⁻¹\n IntervalIntegrable f volume a b :=\n (ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable",
"proofType": "term",
"proofLengthLines": 2,
"proofLengthTokens": 148
} | prime |
import Mathlib.Analysis.Complex.CauchyIntegral
import Mathlib.Analysis.Complex.Convex
import Mathlib.Analysis.Complex.RemovableSingularity
import Mathlib.Analysis.Analytic.Meromorphic
import Mathlib.Analysis.SpecialFunctions.Integrals
import Mathlib.MeasureTheory.Measure.Lebesgue.Integral
import PrimeNumberTheoremAnd.Rectangle
open Complex BigOperators Nat Classical Real Topology Filter Set MeasureTheory intervalIntegral
open scoped Interval
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f g : ℂ → E}
{z w p c A : ℂ} {x x₁ x₂ y y₁ y₂ σ : ℝ}
noncomputable def HIntegral (f : ℂ → E) (x₁ x₂ y : ℝ) : E := ∫ x in x₁..x₂, f (x + y * I)
noncomputable def VIntegral (f : ℂ → E) (x y₁ y₂ : ℝ) : E := I • ∫ y in y₁..y₂, f (x + y * I)
noncomputable def HIntegral' (f : ℂ → E) (x₁ x₂ y : ℝ) : E := (1 / (2 * π * I)) • HIntegral f x₁ x₂ y
noncomputable def VIntegral' (f : ℂ → E) (x y₁ y₂ : ℝ) : E := (1 / (2 * π * I)) • VIntegral f x y₁ y₂
lemma HIntegral_symm : HIntegral f x₁ x₂ y = - HIntegral f x₂ x₁ y := integral_symm _ _
lemma VIntegral_symm : VIntegral f x y₁ y₂ = - VIntegral f x y₂ y₁ := by
simp_rw [VIntegral, integral_symm y₁ y₂, smul_neg, neg_neg]
/-%%
\begin{definition}[RectangleIntegral]\label{RectangleIntegral}\lean{RectangleIntegral}\leanok
A RectangleIntegral of a function $f$ is one over a rectangle determined by $z$ and $w$ in $\C$.
We will sometimes denote it by $\int_{z}^{w} f$. (There is also a primed version, which is $1/(2\pi i)$ times the original.)
\end{definition}
%%-/
/-- A `RectangleIntegral` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`. -/
noncomputable def RectangleIntegral (f : ℂ → E) (z w : ℂ) : E := HIntegral f z.re w.re z.im -
HIntegral f z.re w.re w.im + VIntegral f w.re z.im w.im - VIntegral f z.re z.im w.im
/-- A `RectangleIntegral'` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`, divided by `2 * π * I`. -/
noncomputable abbrev RectangleIntegral' (f : ℂ → E) (z w : ℂ) : E :=
(1 / (2 * π * I)) • RectangleIntegral f z w
/-% ** Wrong delimiter on purpose **
An UpperUIntegral is the integral of a function over a |\_| shape.
\begin{definition}\label{UpperUIntegral}\lean{UpperUIntegral}\leanok
An UpperUIntegral of a function $f$ comes from $\sigma+i\infty$ down to $\sigma+iT$, over to $\sigma'+iT$, and back up to $\sigma'+i\infty$.
\end{definition}
%-/
noncomputable def UpperUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' T +
I • (∫ y : ℝ in Ici T, f (σ' + y * I)) - I • (∫ y : ℝ in Ici T, f (σ + y * I))
/-% ** Wrong delimiter on purpose **
A LowerUIntegral is the integral of a function over a |-| shape.
\begin{definition}[LowerUIntegral]\label{LowerUIntegral}\lean{LowerUIntegral}\leanok
A LowerUIntegral of a function $f$ comes from $\sigma-i\infty$ up to $\sigma-iT$, over to $\sigma'-iT$, and back down to $\sigma'-i\infty$.
\end{definition}
%-/
noncomputable def LowerUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' (-T) -
I • (∫ y : ℝ in Iic (-T), f (σ' + y * I)) + I • (∫ y : ℝ in Iic (-T), f (σ + y * I))
/-%%
It is very convenient to define integrals along vertical lines in the complex plane, as follows.
\begin{definition}[VerticalIntegral]\label{VerticalIntegral}\lean{VerticalIntegral}\leanok
Let $f$ be a function from $\mathbb{C}$ to $\mathbb{C}$, and let $\sigma$ be a real number. Then we define
$$\int_{(\sigma)}f(s)ds = \int_{\sigma-i\infty}^{\sigma+i\infty}f(s)ds.$$
\end{definition}
%%-/
noncomputable def VerticalIntegral (f : ℂ → E) (σ : ℝ) : E := I • ∫ t : ℝ, f (σ + t * I)
--%% We also have a version with a factor of $1/(2\pi i)$.
noncomputable abbrev VerticalIntegral' (f : ℂ → E) (σ : ℝ) : E :=
(1 / (2 * π * I)) • VerticalIntegral f σ
lemma verticalIntegral_split_three (a b : ℝ) (hf : Integrable (fun t : ℝ ↦ f (σ + t * I))) :
VerticalIntegral f σ = I • (∫ t in Iic a, f (σ + t * I)) + VIntegral f σ a b
+ I • ∫ t in Ici b, f (σ + t * I) := by
simp_rw [VerticalIntegral, VIntegral, ← smul_add]
congr
rw [← intervalIntegral.integral_Iic_sub_Iic hf.restrict hf.restrict, add_sub_cancel,
integral_Iic_eq_integral_Iio, intervalIntegral.integral_Iio_add_Ici hf.restrict hf.restrict]
/-% ** Wrong delimiter on purpose **
\begin{lemma}[DiffVertRect_eq_UpperLowerUs]\label{DiffVertRect_eq_UpperLowerUs}\lean{DiffVertRect_eq_UpperLowerUs}\leanok
The difference of two vertical integrals and a rectangle is the difference of an upper and a lower U integrals.
\end{lemma}
%-/
lemma DiffVertRect_eq_UpperLowerUs {σ σ' T : ℝ}
(f_int_σ : Integrable (fun (t : ℝ) ↦ f (σ + t * I)))
(f_int_σ' : Integrable (fun (t : ℝ) ↦ f (σ' + t * I))) :
(VerticalIntegral f σ') - (VerticalIntegral f σ) - (RectangleIntegral f (σ - I * T) (σ' + I * T)) =
(UpperUIntegral f σ σ' T) - (LowerUIntegral f σ σ' T) := by
rw [verticalIntegral_split_three (-T) T f_int_σ, verticalIntegral_split_three (-T) T f_int_σ']
simp only [smul_eq_mul, RectangleIntegral, sub_re, ofReal_re, mul_re, I_re, zero_mul, I_im,
ofReal_im, mul_zero, sub_self, sub_zero, add_re, add_zero, sub_im, mul_im, one_mul, zero_add,
zero_sub, add_im, UpperUIntegral, LowerUIntegral]
abel
/-%
\begin{proof}\uses{UpperUIntegral, LowerUIntegral}\leanok
Follows directly from the definitions.
\end{proof}
%-/
/-- A function is `HolomorphicOn` a set if it is complex differentiable on that set. -/
abbrev HolomorphicOn (f : ℂ → E) (s : Set ℂ) : Prop := DifferentiableOn ℂ f s
/-%%
\begin{theorem}[existsDifferentiableOn_of_bddAbove]\label{existsDifferentiableOn_of_bddAbove}\lean{existsDifferentiableOn_of_bddAbove}\leanok
If $f$ is differentiable on a set $s$ except at $c\in s$, and $f$ is bounded above on $s\setminus\{c\}$, then there exists a differentiable function $g$ on $s$ such that $f$ and $g$ agree on $s\setminus\{c\}$.
\end{theorem}
%%-/
theorem existsDifferentiableOn_of_bddAbove [CompleteSpace E] {s : Set ℂ} {c : ℂ} (hc : s ∈ nhds c)
(hd : HolomorphicOn f (s \ {c})) (hb : BddAbove (norm ∘ f '' (s \ {c}))) :
∃ (g : ℂ → E), HolomorphicOn g s ∧ (Set.EqOn f g (s \ {c})) :=
⟨Function.update f c (limUnder (𝓝[{c}ᶜ] c) f),
differentiableOn_update_limUnder_of_bddAbove hc hd hb,
fun z hz ↦ if h : z = c then (hz.2 h).elim else by simp [h]⟩
/-%%
\begin{proof}\leanok
This is the Riemann Removable Singularity Theorem, slightly rephrased from what's in Mathlib. (We don't care what the function $g$ is, just that it's holomorphic.)
\end{proof}
%%-/
/-%%
\begin{theorem}[HolomorphicOn.vanishesOnRectangle]\label{HolomorphicOn.vanishesOnRectangle}\lean{HolomorphicOn.vanishesOnRectangle}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$, then the integral of $f$ over the rectangle with corners $z$ and $w$ is $0$.
\end{theorem}
%%-/
theorem HolomorphicOn.vanishesOnRectangle [CompleteSpace E] {U : Set ℂ}
(f_holo : HolomorphicOn f U) (hU : Rectangle z w ⊆ U) :
RectangleIntegral f z w = 0 :=
integral_boundary_rect_eq_zero_of_differentiableOn f z w (f_holo.mono hU)
/-%%
\begin{proof}\leanok
This is in a Mathlib PR.
\end{proof}
%%-/
theorem RectangleIntegral_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral f z w = RectangleIntegral g z w := by
unfold RectangleIntegral VIntegral
congr 2; swap; congr 1; swap; congr 1
all_goals refine intervalIntegral.integral_congr fun _ _ ↦ h ?_
· exact Or.inl <| Or.inl <| Or.inl ⟨by simpa, by simp⟩
· exact Or.inl <| Or.inr ⟨by simpa, by simp⟩
· exact Or.inr ⟨by simp, by simpa⟩
· exact Or.inl <| Or.inl <| Or.inr ⟨by simp, by simpa⟩
theorem RectangleIntegral'_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral' f z w = RectangleIntegral' g z w := by
rw [RectangleIntegral', RectangleIntegral_congr h]
theorem rectangleIntegral_symm (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f z w = RectangleIntegral f w z := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, intervalIntegral.integral_symm w.re,
intervalIntegral.integral_symm w.im, sub_neg_eq_add, smul_neg, sub_neg_eq_add, ← sub_eq_add_neg,
neg_add_eq_sub, sub_add_eq_add_sub]
theorem rectangleIntegral_symm_re (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f (w.re + z.im * I) (z.re + w.im * I) = - RectangleIntegral f z w := by
simp [RectangleIntegral, ← sub_eq_zero]
rw [HIntegral_symm (y := z.im), HIntegral_symm (y := w.im)]
abel
def RectangleBorderIntegrable (f : ℂ → E) (z w : ℂ) : Prop :=
IntervalIntegrable (fun x => f (x + z.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun x => f (x + w.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun y => f (w.re + y * I)) volume z.im w.im ∧
IntervalIntegrable (fun y => f (z.re + y * I)) volume z.im w.im
theorem RectangleBorderIntegrable.add {f g : ℂ → E} (hf : RectangleBorderIntegrable f z w)
(hg : RectangleBorderIntegrable g z w) :
RectangleIntegral (f + g) z w = RectangleIntegral f z w + RectangleIntegral g z w := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
rw [intervalIntegral.integral_add hf.1 hg.1, intervalIntegral.integral_add hf.2.1 hg.2.1,
intervalIntegral.integral_add hf.2.2.1 hg.2.2.1, intervalIntegral.integral_add hf.2.2.2 hg.2.2.2]
rw [← sub_eq_zero]
simp only [smul_add]; abel
theorem ContinuousOn.rectangleBorder_integrable (hf : ContinuousOn f (RectangleBorder z w)) :
RectangleBorderIntegrable f z w :=
⟨(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_re z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_re z w)).intervalIntegrable⟩
theorem ContinuousOn.rectangleBorderIntegrable (hf : ContinuousOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
(hf.mono (rectangleBorder_subset_rectangle z w)).rectangleBorder_integrable
theorem ContinuousOn.rectangleBorderNoPIntegrable (hf : ContinuousOn f (Rectangle z w \ {p}))
(pNotOnBorder : p ∉ RectangleBorder z w) : RectangleBorderIntegrable f z w := by
refine (hf.mono (Set.subset_diff.mpr ?_)).rectangleBorder_integrable
exact ⟨rectangleBorder_subset_rectangle z w, disjoint_singleton_right.mpr pNotOnBorder⟩
theorem HolomorphicOn.rectangleBorderIntegrable' (hf : HolomorphicOn f (Rectangle z w \ {p}))
(hp : Rectangle z w ∈ nhds p) : RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderNoPIntegrable (not_mem_rectangleBorder_of_rectangle_mem_nhds hp)
theorem HolomorphicOn.rectangleBorderIntegrable (hf : HolomorphicOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderIntegrable
/--
Given `x₀ a x₁ : ℝ`, and `y₀ y₁ : ℝ` and a function `f : ℂ → ℂ` so that
both `(t : ℝ) ↦ f(t + y₀ * I)` and `(t : ℝ) ↦ f(t + y₁ * I)` are integrable over both
`t ∈ Icc x₀ a` and `t ∈ Icc a x₁`, we have that
`RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I)` is the sum of
`RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I)` and
`RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I)`.
-/
lemma RectangleIntegralHSplit {a x₀ x₁ y₀ y₁ : ℝ}
(f_int_x₀_a_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume x₀ a)
(f_int_a_x₁_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume a x₁)
(f_int_x₀_a_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume x₀ a)
(f_int_a_x₁_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume a x₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_bot f_int_a_x₁_bot,
← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_top f_int_a_x₁_top]
abel
lemma RectangleIntegralHSplit' {a x₀ x₁ y₀ y₁ : ℝ} (ha : a ∈ [[x₀, x₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) :=
RectangleIntegralHSplit
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
lemma RectangleIntegralVSplit {b x₀ x₁ y₀ y₁ : ℝ}
(f_int_y₀_b_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume y₀ b)
(f_int_b_y₁_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume b y₁)
(f_int_y₀_b_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume y₀ b)
(f_int_b_y₁_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume b y₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_left f_int_b_y₁_left,
← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_right f_int_b_y₁_right, ← sub_eq_zero]
simp only [smul_add]; abel
lemma RectangleIntegralVSplit' {b x₀ x₁ y₀ y₁ : ℝ} (hb : b ∈ [[y₀, y₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) :=
RectangleIntegralVSplit
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
lemma RectanglePullToNhdOfPole' [CompleteSpace E] {z₀ z₁ z₂ z₃ p : ℂ}
(h_orientation : z₀.re ≤ z₃.re ∧ z₀.im ≤ z₃.im ∧ z₁.re ≤ z₂.re ∧ z₁.im ≤ z₂.im)
(hp : Rectangle z₁ z₂ ∈ 𝓝 p) (hz : Rectangle z₁ z₂ ⊆ Rectangle z₀ z₃)
(fHolo : HolomorphicOn f (Rectangle z₀ z₃ \ {p})) :
RectangleIntegral f z₀ z₃ = RectangleIntegral f z₁ z₂ := by
obtain ⟨hz₀_re, hz₀_im, hz₁_re, hz₁_im⟩ := h_orientation
have := rect_subset_iff.mp hz
rw [Rectangle, uIcc_of_le hz₀_re, uIcc_of_le hz₀_im] at this
obtain ⟨⟨⟨_, _⟩, ⟨_, _⟩⟩, ⟨_, _⟩, ⟨_, _⟩⟩ := this
obtain ⟨⟨_, _⟩, ⟨_, _⟩⟩ := (uIoo_of_le hz₁_re) ▸ (uIoo_of_le hz₁_im) ▸ rectangle_mem_nhds_iff.mp hp
obtain ⟨_, _, _, _⟩ := show p.re < z₂.re ∧ p.re < z₃.re ∧ p.im < z₂.im ∧ p.im < z₃.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
obtain ⟨_, _, _, _⟩ := show z₀.re < p.re ∧ z₁.re < p.re ∧ z₀.im < p.im ∧ z₁.im < p.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
have fCont := fHolo.continuousOn
have hbot : RectangleBorderIntegrable f (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have htop : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have hleft : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
have hright : RectangleBorderIntegrable f (↑z₁.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
all_goals try {
refine (fCont.mono (rectangleBorder_subset_punctured_rect ?_ ?_)).rectangleBorder_integrable
· simp_all
· simpa using ⟨by linarith, by linarith, by linarith, by linarith⟩
}
have hbot' : z₁.im ∈ [[z₀.im, z₃.im]] := ?_
have htop' : z₂.im ∈ [[z₁.im, z₃.im]] := ?_
have hleft' : z₁.re ∈ [[z₀.re, z₃.re]] := ?_
have hright' : z₂.re ∈ [[z₁.re, z₃.re]] := ?_
all_goals try { rw [Set.uIcc_of_le]; constructor; all_goals assumption }
have hbot'' : Rectangle (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₁.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have htop'' : Rectangle (↑z₀.re + ↑z₂.im * I) (↑z₃.re + ↑z₃.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hleft'' : Rectangle (↑z₀.re + ↑z₁.im * I) (↑z₁.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hright'' : Rectangle (↑z₂.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
all_goals try { apply rectangle_subset_punctured_rect <;> simp_all }
rw [← re_add_im z₀, ← re_add_im z₃,
RectangleIntegralVSplit' hbot' hbot, fHolo.vanishesOnRectangle hbot'', zero_add,
RectangleIntegralVSplit' htop' htop, fHolo.vanishesOnRectangle htop'', add_zero,
RectangleIntegralHSplit' hleft' hleft, fHolo.vanishesOnRectangle hleft'', zero_add,
RectangleIntegralHSplit' hright' hright, fHolo.vanishesOnRectangle hright'', add_zero,
re_add_im, re_add_im]
/-%%
The next lemma allows to zoom a big rectangle down to a small square, centered at a pole.
\begin{lemma}[RectanglePullToNhdOfPole]\label{RectanglePullToNhdOfPole}\lean{RectanglePullToNhdOfPole}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$ except at a point $p$, then the integral of $f$
over the rectangle with corners $z$ and $w$ is the same as the integral of $f$ over a small square
centered at $p$.
\end{lemma}
%%-/
/-- Given `f` holomorphic on a rectangle `z` and `w` except at a point `p`, the integral of `f` over
the rectangle with corners `z` and `w` is the same as the integral of `f` over a small square
centered at `p`. -/
lemma RectanglePullToNhdOfPole [CompleteSpace E] {z w p : ℂ} (zRe_lt_wRe : z.re ≤ w.re)
(zIm_lt_wIm : z.im ≤ w.im) (hp : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral f z w = RectangleIntegral f (-c - I * c + p) (c + I * c + p) := by
/-%%
\begin{proof}\uses{HolomorphicOn.vanishesOnRectangle}\leanok
Chop the big rectangle with two vertical cuts and two horizontal cuts into smaller rectangles,
the middle one being the desired square. The integral over each of the outer rectangles
vanishes, since $f$ is holomorphic there. (The constant $c$ being ``small enough'' here just means
that the inner square is strictly contained in the big rectangle.)
%%-/
filter_upwards [Ioo_mem_nhdsWithin_Ioi' zero_lt_one, SmallSquareInRectangle hp]
intro c ⟨cpos, _⟩ hc
simp_rw [mul_comm I]
exact RectanglePullToNhdOfPole' (by simp_all [cpos.le])
(square_mem_nhds p (ne_of_gt cpos)) hc fHolo
--%%\end{proof}
lemma RectanglePullToNhdOfPole'' [CompleteSpace E] {z w p : ℂ} (zRe_le_wRe : z.re ≤ w.re)
(zIm_le_wIm : z.im ≤ w.im) (pInRectInterior : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral' f z w = RectangleIntegral' f (-c - I * c + p) (c + I * c + p) := by
filter_upwards [RectanglePullToNhdOfPole zRe_le_wRe zIm_le_wIm pInRectInterior fHolo] with c h
simp_rw [RectangleIntegral', h]
theorem ResidueTheoremAtOrigin_aux1c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y + I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux1c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y - I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (-1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
| theorem RectangleIntegral.const_smul (f : ℂ → E) (z w c : ℂ) :
RectangleIntegral (fun s => c • f s) z w = c • RectangleIntegral f z w | RectangleIntegral.const_smul | f36a520 20240122 | 1909a40 20240209 | PrimeNumberTheoremAnd/PrimeNumberTheoremAnd/ResidueCalcOnRectangles.lean | {
"lineInFile": 366,
"tokenPositionInFile": 19927,
"theoremPositionInFile": 39
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": ":= by\n simp [RectangleIntegral, HIntegral, VIntegral, smul_add, smul_sub, smul_smul, mul_comm]",
"proofType": "tactic",
"proofLengthLines": 1,
"proofLengthTokens": 95
} | prime |
import Mathlib.Analysis.Complex.CauchyIntegral
import Mathlib.Analysis.Complex.Convex
import Mathlib.Analysis.Complex.RemovableSingularity
import Mathlib.Analysis.Analytic.Meromorphic
import Mathlib.Analysis.SpecialFunctions.Integrals
import Mathlib.MeasureTheory.Measure.Lebesgue.Integral
import PrimeNumberTheoremAnd.Rectangle
open Complex BigOperators Nat Classical Real Topology Filter Set MeasureTheory intervalIntegral
open scoped Interval
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f g : ℂ → E}
{z w p c A : ℂ} {x x₁ x₂ y y₁ y₂ σ : ℝ}
noncomputable def HIntegral (f : ℂ → E) (x₁ x₂ y : ℝ) : E := ∫ x in x₁..x₂, f (x + y * I)
noncomputable def VIntegral (f : ℂ → E) (x y₁ y₂ : ℝ) : E := I • ∫ y in y₁..y₂, f (x + y * I)
noncomputable def HIntegral' (f : ℂ → E) (x₁ x₂ y : ℝ) : E := (1 / (2 * π * I)) • HIntegral f x₁ x₂ y
noncomputable def VIntegral' (f : ℂ → E) (x y₁ y₂ : ℝ) : E := (1 / (2 * π * I)) • VIntegral f x y₁ y₂
lemma HIntegral_symm : HIntegral f x₁ x₂ y = - HIntegral f x₂ x₁ y := integral_symm _ _
lemma VIntegral_symm : VIntegral f x y₁ y₂ = - VIntegral f x y₂ y₁ := by
simp_rw [VIntegral, integral_symm y₁ y₂, smul_neg, neg_neg]
/-%%
\begin{definition}[RectangleIntegral]\label{RectangleIntegral}\lean{RectangleIntegral}\leanok
A RectangleIntegral of a function $f$ is one over a rectangle determined by $z$ and $w$ in $\C$.
We will sometimes denote it by $\int_{z}^{w} f$. (There is also a primed version, which is $1/(2\pi i)$ times the original.)
\end{definition}
%%-/
/-- A `RectangleIntegral` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`. -/
noncomputable def RectangleIntegral (f : ℂ → E) (z w : ℂ) : E := HIntegral f z.re w.re z.im -
HIntegral f z.re w.re w.im + VIntegral f w.re z.im w.im - VIntegral f z.re z.im w.im
/-- A `RectangleIntegral'` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`, divided by `2 * π * I`. -/
noncomputable abbrev RectangleIntegral' (f : ℂ → E) (z w : ℂ) : E :=
(1 / (2 * π * I)) • RectangleIntegral f z w
/-% ** Wrong delimiter on purpose **
An UpperUIntegral is the integral of a function over a |\_| shape.
\begin{definition}\label{UpperUIntegral}\lean{UpperUIntegral}\leanok
An UpperUIntegral of a function $f$ comes from $\sigma+i\infty$ down to $\sigma+iT$, over to $\sigma'+iT$, and back up to $\sigma'+i\infty$.
\end{definition}
%-/
noncomputable def UpperUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' T +
I • (∫ y : ℝ in Ici T, f (σ' + y * I)) - I • (∫ y : ℝ in Ici T, f (σ + y * I))
/-% ** Wrong delimiter on purpose **
A LowerUIntegral is the integral of a function over a |-| shape.
\begin{definition}[LowerUIntegral]\label{LowerUIntegral}\lean{LowerUIntegral}\leanok
A LowerUIntegral of a function $f$ comes from $\sigma-i\infty$ up to $\sigma-iT$, over to $\sigma'-iT$, and back down to $\sigma'-i\infty$.
\end{definition}
%-/
noncomputable def LowerUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' (-T) -
I • (∫ y : ℝ in Iic (-T), f (σ' + y * I)) + I • (∫ y : ℝ in Iic (-T), f (σ + y * I))
/-%%
It is very convenient to define integrals along vertical lines in the complex plane, as follows.
\begin{definition}[VerticalIntegral]\label{VerticalIntegral}\lean{VerticalIntegral}\leanok
Let $f$ be a function from $\mathbb{C}$ to $\mathbb{C}$, and let $\sigma$ be a real number. Then we define
$$\int_{(\sigma)}f(s)ds = \int_{\sigma-i\infty}^{\sigma+i\infty}f(s)ds.$$
\end{definition}
%%-/
noncomputable def VerticalIntegral (f : ℂ → E) (σ : ℝ) : E := I • ∫ t : ℝ, f (σ + t * I)
--%% We also have a version with a factor of $1/(2\pi i)$.
noncomputable abbrev VerticalIntegral' (f : ℂ → E) (σ : ℝ) : E :=
(1 / (2 * π * I)) • VerticalIntegral f σ
lemma verticalIntegral_split_three (a b : ℝ) (hf : Integrable (fun t : ℝ ↦ f (σ + t * I))) :
VerticalIntegral f σ = I • (∫ t in Iic a, f (σ + t * I)) + VIntegral f σ a b
+ I • ∫ t in Ici b, f (σ + t * I) := by
simp_rw [VerticalIntegral, VIntegral, ← smul_add]
congr
rw [← intervalIntegral.integral_Iic_sub_Iic hf.restrict hf.restrict, add_sub_cancel,
integral_Iic_eq_integral_Iio, intervalIntegral.integral_Iio_add_Ici hf.restrict hf.restrict]
/-% ** Wrong delimiter on purpose **
\begin{lemma}[DiffVertRect_eq_UpperLowerUs]\label{DiffVertRect_eq_UpperLowerUs}\lean{DiffVertRect_eq_UpperLowerUs}\leanok
The difference of two vertical integrals and a rectangle is the difference of an upper and a lower U integrals.
\end{lemma}
%-/
lemma DiffVertRect_eq_UpperLowerUs {σ σ' T : ℝ}
(f_int_σ : Integrable (fun (t : ℝ) ↦ f (σ + t * I)))
(f_int_σ' : Integrable (fun (t : ℝ) ↦ f (σ' + t * I))) :
(VerticalIntegral f σ') - (VerticalIntegral f σ) - (RectangleIntegral f (σ - I * T) (σ' + I * T)) =
(UpperUIntegral f σ σ' T) - (LowerUIntegral f σ σ' T) := by
rw [verticalIntegral_split_three (-T) T f_int_σ, verticalIntegral_split_three (-T) T f_int_σ']
simp only [smul_eq_mul, RectangleIntegral, sub_re, ofReal_re, mul_re, I_re, zero_mul, I_im,
ofReal_im, mul_zero, sub_self, sub_zero, add_re, add_zero, sub_im, mul_im, one_mul, zero_add,
zero_sub, add_im, UpperUIntegral, LowerUIntegral]
abel
/-%
\begin{proof}\uses{UpperUIntegral, LowerUIntegral}\leanok
Follows directly from the definitions.
\end{proof}
%-/
/-- A function is `HolomorphicOn` a set if it is complex differentiable on that set. -/
abbrev HolomorphicOn (f : ℂ → E) (s : Set ℂ) : Prop := DifferentiableOn ℂ f s
/-%%
\begin{theorem}[existsDifferentiableOn_of_bddAbove]\label{existsDifferentiableOn_of_bddAbove}\lean{existsDifferentiableOn_of_bddAbove}\leanok
If $f$ is differentiable on a set $s$ except at $c\in s$, and $f$ is bounded above on $s\setminus\{c\}$, then there exists a differentiable function $g$ on $s$ such that $f$ and $g$ agree on $s\setminus\{c\}$.
\end{theorem}
%%-/
theorem existsDifferentiableOn_of_bddAbove [CompleteSpace E] {s : Set ℂ} {c : ℂ} (hc : s ∈ nhds c)
(hd : HolomorphicOn f (s \ {c})) (hb : BddAbove (norm ∘ f '' (s \ {c}))) :
∃ (g : ℂ → E), HolomorphicOn g s ∧ (Set.EqOn f g (s \ {c})) :=
⟨Function.update f c (limUnder (𝓝[{c}ᶜ] c) f),
differentiableOn_update_limUnder_of_bddAbove hc hd hb,
fun z hz ↦ if h : z = c then (hz.2 h).elim else by simp [h]⟩
/-%%
\begin{proof}\leanok
This is the Riemann Removable Singularity Theorem, slightly rephrased from what's in Mathlib. (We don't care what the function $g$ is, just that it's holomorphic.)
\end{proof}
%%-/
/-%%
\begin{theorem}[HolomorphicOn.vanishesOnRectangle]\label{HolomorphicOn.vanishesOnRectangle}\lean{HolomorphicOn.vanishesOnRectangle}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$, then the integral of $f$ over the rectangle with corners $z$ and $w$ is $0$.
\end{theorem}
%%-/
theorem HolomorphicOn.vanishesOnRectangle [CompleteSpace E] {U : Set ℂ}
(f_holo : HolomorphicOn f U) (hU : Rectangle z w ⊆ U) :
RectangleIntegral f z w = 0 :=
integral_boundary_rect_eq_zero_of_differentiableOn f z w (f_holo.mono hU)
/-%%
\begin{proof}\leanok
This is in a Mathlib PR.
\end{proof}
%%-/
theorem RectangleIntegral_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral f z w = RectangleIntegral g z w := by
unfold RectangleIntegral VIntegral
congr 2; swap; congr 1; swap; congr 1
all_goals refine intervalIntegral.integral_congr fun _ _ ↦ h ?_
· exact Or.inl <| Or.inl <| Or.inl ⟨by simpa, by simp⟩
· exact Or.inl <| Or.inr ⟨by simpa, by simp⟩
· exact Or.inr ⟨by simp, by simpa⟩
· exact Or.inl <| Or.inl <| Or.inr ⟨by simp, by simpa⟩
theorem RectangleIntegral'_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral' f z w = RectangleIntegral' g z w := by
rw [RectangleIntegral', RectangleIntegral_congr h]
theorem rectangleIntegral_symm (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f z w = RectangleIntegral f w z := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, intervalIntegral.integral_symm w.re,
intervalIntegral.integral_symm w.im, sub_neg_eq_add, smul_neg, sub_neg_eq_add, ← sub_eq_add_neg,
neg_add_eq_sub, sub_add_eq_add_sub]
theorem rectangleIntegral_symm_re (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f (w.re + z.im * I) (z.re + w.im * I) = - RectangleIntegral f z w := by
simp [RectangleIntegral, ← sub_eq_zero]
rw [HIntegral_symm (y := z.im), HIntegral_symm (y := w.im)]
abel
def RectangleBorderIntegrable (f : ℂ → E) (z w : ℂ) : Prop :=
IntervalIntegrable (fun x => f (x + z.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun x => f (x + w.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun y => f (w.re + y * I)) volume z.im w.im ∧
IntervalIntegrable (fun y => f (z.re + y * I)) volume z.im w.im
theorem RectangleBorderIntegrable.add {f g : ℂ → E} (hf : RectangleBorderIntegrable f z w)
(hg : RectangleBorderIntegrable g z w) :
RectangleIntegral (f + g) z w = RectangleIntegral f z w + RectangleIntegral g z w := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
rw [intervalIntegral.integral_add hf.1 hg.1, intervalIntegral.integral_add hf.2.1 hg.2.1,
intervalIntegral.integral_add hf.2.2.1 hg.2.2.1, intervalIntegral.integral_add hf.2.2.2 hg.2.2.2]
rw [← sub_eq_zero]
simp only [smul_add]; abel
theorem ContinuousOn.rectangleBorder_integrable (hf : ContinuousOn f (RectangleBorder z w)) :
RectangleBorderIntegrable f z w :=
⟨(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_re z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_re z w)).intervalIntegrable⟩
theorem ContinuousOn.rectangleBorderIntegrable (hf : ContinuousOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
(hf.mono (rectangleBorder_subset_rectangle z w)).rectangleBorder_integrable
theorem ContinuousOn.rectangleBorderNoPIntegrable (hf : ContinuousOn f (Rectangle z w \ {p}))
(pNotOnBorder : p ∉ RectangleBorder z w) : RectangleBorderIntegrable f z w := by
refine (hf.mono (Set.subset_diff.mpr ?_)).rectangleBorder_integrable
exact ⟨rectangleBorder_subset_rectangle z w, disjoint_singleton_right.mpr pNotOnBorder⟩
theorem HolomorphicOn.rectangleBorderIntegrable' (hf : HolomorphicOn f (Rectangle z w \ {p}))
(hp : Rectangle z w ∈ nhds p) : RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderNoPIntegrable (not_mem_rectangleBorder_of_rectangle_mem_nhds hp)
theorem HolomorphicOn.rectangleBorderIntegrable (hf : HolomorphicOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderIntegrable
/--
Given `x₀ a x₁ : ℝ`, and `y₀ y₁ : ℝ` and a function `f : ℂ → ℂ` so that
both `(t : ℝ) ↦ f(t + y₀ * I)` and `(t : ℝ) ↦ f(t + y₁ * I)` are integrable over both
`t ∈ Icc x₀ a` and `t ∈ Icc a x₁`, we have that
`RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I)` is the sum of
`RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I)` and
`RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I)`.
-/
lemma RectangleIntegralHSplit {a x₀ x₁ y₀ y₁ : ℝ}
(f_int_x₀_a_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume x₀ a)
(f_int_a_x₁_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume a x₁)
(f_int_x₀_a_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume x₀ a)
(f_int_a_x₁_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume a x₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_bot f_int_a_x₁_bot,
← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_top f_int_a_x₁_top]
abel
lemma RectangleIntegralHSplit' {a x₀ x₁ y₀ y₁ : ℝ} (ha : a ∈ [[x₀, x₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) :=
RectangleIntegralHSplit
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
lemma RectangleIntegralVSplit {b x₀ x₁ y₀ y₁ : ℝ}
(f_int_y₀_b_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume y₀ b)
(f_int_b_y₁_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume b y₁)
(f_int_y₀_b_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume y₀ b)
(f_int_b_y₁_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume b y₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_left f_int_b_y₁_left,
← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_right f_int_b_y₁_right, ← sub_eq_zero]
simp only [smul_add]; abel
lemma RectangleIntegralVSplit' {b x₀ x₁ y₀ y₁ : ℝ} (hb : b ∈ [[y₀, y₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) :=
RectangleIntegralVSplit
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
lemma RectanglePullToNhdOfPole' [CompleteSpace E] {z₀ z₁ z₂ z₃ p : ℂ}
(h_orientation : z₀.re ≤ z₃.re ∧ z₀.im ≤ z₃.im ∧ z₁.re ≤ z₂.re ∧ z₁.im ≤ z₂.im)
(hp : Rectangle z₁ z₂ ∈ 𝓝 p) (hz : Rectangle z₁ z₂ ⊆ Rectangle z₀ z₃)
(fHolo : HolomorphicOn f (Rectangle z₀ z₃ \ {p})) :
RectangleIntegral f z₀ z₃ = RectangleIntegral f z₁ z₂ := by
obtain ⟨hz₀_re, hz₀_im, hz₁_re, hz₁_im⟩ := h_orientation
have := rect_subset_iff.mp hz
rw [Rectangle, uIcc_of_le hz₀_re, uIcc_of_le hz₀_im] at this
obtain ⟨⟨⟨_, _⟩, ⟨_, _⟩⟩, ⟨_, _⟩, ⟨_, _⟩⟩ := this
obtain ⟨⟨_, _⟩, ⟨_, _⟩⟩ := (uIoo_of_le hz₁_re) ▸ (uIoo_of_le hz₁_im) ▸ rectangle_mem_nhds_iff.mp hp
obtain ⟨_, _, _, _⟩ := show p.re < z₂.re ∧ p.re < z₃.re ∧ p.im < z₂.im ∧ p.im < z₃.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
obtain ⟨_, _, _, _⟩ := show z₀.re < p.re ∧ z₁.re < p.re ∧ z₀.im < p.im ∧ z₁.im < p.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
have fCont := fHolo.continuousOn
have hbot : RectangleBorderIntegrable f (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have htop : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have hleft : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
have hright : RectangleBorderIntegrable f (↑z₁.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
all_goals try {
refine (fCont.mono (rectangleBorder_subset_punctured_rect ?_ ?_)).rectangleBorder_integrable
· simp_all
· simpa using ⟨by linarith, by linarith, by linarith, by linarith⟩
}
have hbot' : z₁.im ∈ [[z₀.im, z₃.im]] := ?_
have htop' : z₂.im ∈ [[z₁.im, z₃.im]] := ?_
have hleft' : z₁.re ∈ [[z₀.re, z₃.re]] := ?_
have hright' : z₂.re ∈ [[z₁.re, z₃.re]] := ?_
all_goals try { rw [Set.uIcc_of_le]; constructor; all_goals assumption }
have hbot'' : Rectangle (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₁.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have htop'' : Rectangle (↑z₀.re + ↑z₂.im * I) (↑z₃.re + ↑z₃.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hleft'' : Rectangle (↑z₀.re + ↑z₁.im * I) (↑z₁.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hright'' : Rectangle (↑z₂.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
all_goals try { apply rectangle_subset_punctured_rect <;> simp_all }
rw [← re_add_im z₀, ← re_add_im z₃,
RectangleIntegralVSplit' hbot' hbot, fHolo.vanishesOnRectangle hbot'', zero_add,
RectangleIntegralVSplit' htop' htop, fHolo.vanishesOnRectangle htop'', add_zero,
RectangleIntegralHSplit' hleft' hleft, fHolo.vanishesOnRectangle hleft'', zero_add,
RectangleIntegralHSplit' hright' hright, fHolo.vanishesOnRectangle hright'', add_zero,
re_add_im, re_add_im]
/-%%
The next lemma allows to zoom a big rectangle down to a small square, centered at a pole.
\begin{lemma}[RectanglePullToNhdOfPole]\label{RectanglePullToNhdOfPole}\lean{RectanglePullToNhdOfPole}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$ except at a point $p$, then the integral of $f$
over the rectangle with corners $z$ and $w$ is the same as the integral of $f$ over a small square
centered at $p$.
\end{lemma}
%%-/
/-- Given `f` holomorphic on a rectangle `z` and `w` except at a point `p`, the integral of `f` over
the rectangle with corners `z` and `w` is the same as the integral of `f` over a small square
centered at `p`. -/
lemma RectanglePullToNhdOfPole [CompleteSpace E] {z w p : ℂ} (zRe_lt_wRe : z.re ≤ w.re)
(zIm_lt_wIm : z.im ≤ w.im) (hp : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral f z w = RectangleIntegral f (-c - I * c + p) (c + I * c + p) := by
/-%%
\begin{proof}\uses{HolomorphicOn.vanishesOnRectangle}\leanok
Chop the big rectangle with two vertical cuts and two horizontal cuts into smaller rectangles,
the middle one being the desired square. The integral over each of the outer rectangles
vanishes, since $f$ is holomorphic there. (The constant $c$ being ``small enough'' here just means
that the inner square is strictly contained in the big rectangle.)
%%-/
filter_upwards [Ioo_mem_nhdsWithin_Ioi' zero_lt_one, SmallSquareInRectangle hp]
intro c ⟨cpos, _⟩ hc
simp_rw [mul_comm I]
exact RectanglePullToNhdOfPole' (by simp_all [cpos.le])
(square_mem_nhds p (ne_of_gt cpos)) hc fHolo
--%%\end{proof}
lemma RectanglePullToNhdOfPole'' [CompleteSpace E] {z w p : ℂ} (zRe_le_wRe : z.re ≤ w.re)
(zIm_le_wIm : z.im ≤ w.im) (pInRectInterior : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral' f z w = RectangleIntegral' f (-c - I * c + p) (c + I * c + p) := by
filter_upwards [RectanglePullToNhdOfPole zRe_le_wRe zIm_le_wIm pInRectInterior fHolo] with c h
simp_rw [RectangleIntegral', h]
theorem ResidueTheoremAtOrigin_aux1c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y + I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux1c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y - I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (-1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem RectangleIntegral.const_smul (f : ℂ → E) (z w c : ℂ) :
RectangleIntegral (fun s => c • f s) z w = c • RectangleIntegral f z w := by
simp [RectangleIntegral, HIntegral, VIntegral, smul_add, smul_sub, smul_smul, mul_comm]
| theorem RectangleIntegral.const_mul' (f : ℂ → E) (z w c : ℂ) :
RectangleIntegral' (fun s => c • f s) z w = c • RectangleIntegral' f z w | RectangleIntegral.const_mul' | f36a520 20240122 | 1909a40 20240209 | PrimeNumberTheoremAnd/PrimeNumberTheoremAnd/ResidueCalcOnRectangles.lean | {
"lineInFile": 370,
"tokenPositionInFile": 20162,
"theoremPositionInFile": 40
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": ":= by\n simp [RectangleIntegral', RectangleIntegral.const_smul, smul_smul] ; ring_nf",
"proofType": "tactic",
"proofLengthLines": 1,
"proofLengthTokens": 84
} | prime |
import Mathlib.Analysis.Complex.CauchyIntegral
import Mathlib.Analysis.Complex.Convex
import Mathlib.Analysis.Complex.RemovableSingularity
import Mathlib.Analysis.Analytic.Meromorphic
import Mathlib.Analysis.SpecialFunctions.Integrals
import Mathlib.MeasureTheory.Measure.Lebesgue.Integral
import PrimeNumberTheoremAnd.Rectangle
open Complex BigOperators Nat Classical Real Topology Filter Set MeasureTheory intervalIntegral
open scoped Interval
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f g : ℂ → E}
{z w p c A : ℂ} {x x₁ x₂ y y₁ y₂ σ : ℝ}
noncomputable def HIntegral (f : ℂ → E) (x₁ x₂ y : ℝ) : E := ∫ x in x₁..x₂, f (x + y * I)
noncomputable def VIntegral (f : ℂ → E) (x y₁ y₂ : ℝ) : E := I • ∫ y in y₁..y₂, f (x + y * I)
noncomputable def HIntegral' (f : ℂ → E) (x₁ x₂ y : ℝ) : E := (1 / (2 * π * I)) • HIntegral f x₁ x₂ y
noncomputable def VIntegral' (f : ℂ → E) (x y₁ y₂ : ℝ) : E := (1 / (2 * π * I)) • VIntegral f x y₁ y₂
lemma HIntegral_symm : HIntegral f x₁ x₂ y = - HIntegral f x₂ x₁ y := integral_symm _ _
lemma VIntegral_symm : VIntegral f x y₁ y₂ = - VIntegral f x y₂ y₁ := by
simp_rw [VIntegral, integral_symm y₁ y₂, smul_neg, neg_neg]
/-%%
\begin{definition}[RectangleIntegral]\label{RectangleIntegral}\lean{RectangleIntegral}\leanok
A RectangleIntegral of a function $f$ is one over a rectangle determined by $z$ and $w$ in $\C$.
We will sometimes denote it by $\int_{z}^{w} f$. (There is also a primed version, which is $1/(2\pi i)$ times the original.)
\end{definition}
%%-/
/-- A `RectangleIntegral` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`. -/
noncomputable def RectangleIntegral (f : ℂ → E) (z w : ℂ) : E := HIntegral f z.re w.re z.im -
HIntegral f z.re w.re w.im + VIntegral f w.re z.im w.im - VIntegral f z.re z.im w.im
/-- A `RectangleIntegral'` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`, divided by `2 * π * I`. -/
noncomputable abbrev RectangleIntegral' (f : ℂ → E) (z w : ℂ) : E :=
(1 / (2 * π * I)) • RectangleIntegral f z w
/-% ** Wrong delimiter on purpose **
An UpperUIntegral is the integral of a function over a |\_| shape.
\begin{definition}\label{UpperUIntegral}\lean{UpperUIntegral}\leanok
An UpperUIntegral of a function $f$ comes from $\sigma+i\infty$ down to $\sigma+iT$, over to $\sigma'+iT$, and back up to $\sigma'+i\infty$.
\end{definition}
%-/
noncomputable def UpperUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' T +
I • (∫ y : ℝ in Ici T, f (σ' + y * I)) - I • (∫ y : ℝ in Ici T, f (σ + y * I))
/-% ** Wrong delimiter on purpose **
A LowerUIntegral is the integral of a function over a |-| shape.
\begin{definition}[LowerUIntegral]\label{LowerUIntegral}\lean{LowerUIntegral}\leanok
A LowerUIntegral of a function $f$ comes from $\sigma-i\infty$ up to $\sigma-iT$, over to $\sigma'-iT$, and back down to $\sigma'-i\infty$.
\end{definition}
%-/
noncomputable def LowerUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' (-T) -
I • (∫ y : ℝ in Iic (-T), f (σ' + y * I)) + I • (∫ y : ℝ in Iic (-T), f (σ + y * I))
/-%%
It is very convenient to define integrals along vertical lines in the complex plane, as follows.
\begin{definition}[VerticalIntegral]\label{VerticalIntegral}\lean{VerticalIntegral}\leanok
Let $f$ be a function from $\mathbb{C}$ to $\mathbb{C}$, and let $\sigma$ be a real number. Then we define
$$\int_{(\sigma)}f(s)ds = \int_{\sigma-i\infty}^{\sigma+i\infty}f(s)ds.$$
\end{definition}
%%-/
noncomputable def VerticalIntegral (f : ℂ → E) (σ : ℝ) : E := I • ∫ t : ℝ, f (σ + t * I)
--%% We also have a version with a factor of $1/(2\pi i)$.
noncomputable abbrev VerticalIntegral' (f : ℂ → E) (σ : ℝ) : E :=
(1 / (2 * π * I)) • VerticalIntegral f σ
lemma verticalIntegral_split_three (a b : ℝ) (hf : Integrable (fun t : ℝ ↦ f (σ + t * I))) :
VerticalIntegral f σ = I • (∫ t in Iic a, f (σ + t * I)) + VIntegral f σ a b
+ I • ∫ t in Ici b, f (σ + t * I) := by
simp_rw [VerticalIntegral, VIntegral, ← smul_add]
congr
rw [← intervalIntegral.integral_Iic_sub_Iic hf.restrict hf.restrict, add_sub_cancel,
integral_Iic_eq_integral_Iio, intervalIntegral.integral_Iio_add_Ici hf.restrict hf.restrict]
/-% ** Wrong delimiter on purpose **
\begin{lemma}[DiffVertRect_eq_UpperLowerUs]\label{DiffVertRect_eq_UpperLowerUs}\lean{DiffVertRect_eq_UpperLowerUs}\leanok
The difference of two vertical integrals and a rectangle is the difference of an upper and a lower U integrals.
\end{lemma}
%-/
lemma DiffVertRect_eq_UpperLowerUs {σ σ' T : ℝ}
(f_int_σ : Integrable (fun (t : ℝ) ↦ f (σ + t * I)))
(f_int_σ' : Integrable (fun (t : ℝ) ↦ f (σ' + t * I))) :
(VerticalIntegral f σ') - (VerticalIntegral f σ) - (RectangleIntegral f (σ - I * T) (σ' + I * T)) =
(UpperUIntegral f σ σ' T) - (LowerUIntegral f σ σ' T) := by
rw [verticalIntegral_split_three (-T) T f_int_σ, verticalIntegral_split_three (-T) T f_int_σ']
simp only [smul_eq_mul, RectangleIntegral, sub_re, ofReal_re, mul_re, I_re, zero_mul, I_im,
ofReal_im, mul_zero, sub_self, sub_zero, add_re, add_zero, sub_im, mul_im, one_mul, zero_add,
zero_sub, add_im, UpperUIntegral, LowerUIntegral]
abel
/-%
\begin{proof}\uses{UpperUIntegral, LowerUIntegral}\leanok
Follows directly from the definitions.
\end{proof}
%-/
/-- A function is `HolomorphicOn` a set if it is complex differentiable on that set. -/
abbrev HolomorphicOn (f : ℂ → E) (s : Set ℂ) : Prop := DifferentiableOn ℂ f s
/-%%
\begin{theorem}[existsDifferentiableOn_of_bddAbove]\label{existsDifferentiableOn_of_bddAbove}\lean{existsDifferentiableOn_of_bddAbove}\leanok
If $f$ is differentiable on a set $s$ except at $c\in s$, and $f$ is bounded above on $s\setminus\{c\}$, then there exists a differentiable function $g$ on $s$ such that $f$ and $g$ agree on $s\setminus\{c\}$.
\end{theorem}
%%-/
theorem existsDifferentiableOn_of_bddAbove [CompleteSpace E] {s : Set ℂ} {c : ℂ} (hc : s ∈ nhds c)
(hd : HolomorphicOn f (s \ {c})) (hb : BddAbove (norm ∘ f '' (s \ {c}))) :
∃ (g : ℂ → E), HolomorphicOn g s ∧ (Set.EqOn f g (s \ {c})) :=
⟨Function.update f c (limUnder (𝓝[{c}ᶜ] c) f),
differentiableOn_update_limUnder_of_bddAbove hc hd hb,
fun z hz ↦ if h : z = c then (hz.2 h).elim else by simp [h]⟩
/-%%
\begin{proof}\leanok
This is the Riemann Removable Singularity Theorem, slightly rephrased from what's in Mathlib. (We don't care what the function $g$ is, just that it's holomorphic.)
\end{proof}
%%-/
/-%%
\begin{theorem}[HolomorphicOn.vanishesOnRectangle]\label{HolomorphicOn.vanishesOnRectangle}\lean{HolomorphicOn.vanishesOnRectangle}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$, then the integral of $f$ over the rectangle with corners $z$ and $w$ is $0$.
\end{theorem}
%%-/
theorem HolomorphicOn.vanishesOnRectangle [CompleteSpace E] {U : Set ℂ}
(f_holo : HolomorphicOn f U) (hU : Rectangle z w ⊆ U) :
RectangleIntegral f z w = 0 :=
integral_boundary_rect_eq_zero_of_differentiableOn f z w (f_holo.mono hU)
/-%%
\begin{proof}\leanok
This is in a Mathlib PR.
\end{proof}
%%-/
theorem RectangleIntegral_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral f z w = RectangleIntegral g z w := by
unfold RectangleIntegral VIntegral
congr 2; swap; congr 1; swap; congr 1
all_goals refine intervalIntegral.integral_congr fun _ _ ↦ h ?_
· exact Or.inl <| Or.inl <| Or.inl ⟨by simpa, by simp⟩
· exact Or.inl <| Or.inr ⟨by simpa, by simp⟩
· exact Or.inr ⟨by simp, by simpa⟩
· exact Or.inl <| Or.inl <| Or.inr ⟨by simp, by simpa⟩
theorem RectangleIntegral'_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral' f z w = RectangleIntegral' g z w := by
rw [RectangleIntegral', RectangleIntegral_congr h]
theorem rectangleIntegral_symm (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f z w = RectangleIntegral f w z := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, intervalIntegral.integral_symm w.re,
intervalIntegral.integral_symm w.im, sub_neg_eq_add, smul_neg, sub_neg_eq_add, ← sub_eq_add_neg,
neg_add_eq_sub, sub_add_eq_add_sub]
theorem rectangleIntegral_symm_re (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f (w.re + z.im * I) (z.re + w.im * I) = - RectangleIntegral f z w := by
simp [RectangleIntegral, ← sub_eq_zero]
rw [HIntegral_symm (y := z.im), HIntegral_symm (y := w.im)]
abel
def RectangleBorderIntegrable (f : ℂ → E) (z w : ℂ) : Prop :=
IntervalIntegrable (fun x => f (x + z.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun x => f (x + w.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun y => f (w.re + y * I)) volume z.im w.im ∧
IntervalIntegrable (fun y => f (z.re + y * I)) volume z.im w.im
theorem RectangleBorderIntegrable.add {f g : ℂ → E} (hf : RectangleBorderIntegrable f z w)
(hg : RectangleBorderIntegrable g z w) :
RectangleIntegral (f + g) z w = RectangleIntegral f z w + RectangleIntegral g z w := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
rw [intervalIntegral.integral_add hf.1 hg.1, intervalIntegral.integral_add hf.2.1 hg.2.1,
intervalIntegral.integral_add hf.2.2.1 hg.2.2.1, intervalIntegral.integral_add hf.2.2.2 hg.2.2.2]
rw [← sub_eq_zero]
simp only [smul_add]; abel
theorem ContinuousOn.rectangleBorder_integrable (hf : ContinuousOn f (RectangleBorder z w)) :
RectangleBorderIntegrable f z w :=
⟨(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_re z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_re z w)).intervalIntegrable⟩
theorem ContinuousOn.rectangleBorderIntegrable (hf : ContinuousOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
(hf.mono (rectangleBorder_subset_rectangle z w)).rectangleBorder_integrable
theorem ContinuousOn.rectangleBorderNoPIntegrable (hf : ContinuousOn f (Rectangle z w \ {p}))
(pNotOnBorder : p ∉ RectangleBorder z w) : RectangleBorderIntegrable f z w := by
refine (hf.mono (Set.subset_diff.mpr ?_)).rectangleBorder_integrable
exact ⟨rectangleBorder_subset_rectangle z w, disjoint_singleton_right.mpr pNotOnBorder⟩
theorem HolomorphicOn.rectangleBorderIntegrable' (hf : HolomorphicOn f (Rectangle z w \ {p}))
(hp : Rectangle z w ∈ nhds p) : RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderNoPIntegrable (not_mem_rectangleBorder_of_rectangle_mem_nhds hp)
theorem HolomorphicOn.rectangleBorderIntegrable (hf : HolomorphicOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderIntegrable
/--
Given `x₀ a x₁ : ℝ`, and `y₀ y₁ : ℝ` and a function `f : ℂ → ℂ` so that
both `(t : ℝ) ↦ f(t + y₀ * I)` and `(t : ℝ) ↦ f(t + y₁ * I)` are integrable over both
`t ∈ Icc x₀ a` and `t ∈ Icc a x₁`, we have that
`RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I)` is the sum of
`RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I)` and
`RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I)`.
-/
lemma RectangleIntegralHSplit {a x₀ x₁ y₀ y₁ : ℝ}
(f_int_x₀_a_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume x₀ a)
(f_int_a_x₁_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume a x₁)
(f_int_x₀_a_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume x₀ a)
(f_int_a_x₁_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume a x₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_bot f_int_a_x₁_bot,
← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_top f_int_a_x₁_top]
abel
lemma RectangleIntegralHSplit' {a x₀ x₁ y₀ y₁ : ℝ} (ha : a ∈ [[x₀, x₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) :=
RectangleIntegralHSplit
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
lemma RectangleIntegralVSplit {b x₀ x₁ y₀ y₁ : ℝ}
(f_int_y₀_b_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume y₀ b)
(f_int_b_y₁_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume b y₁)
(f_int_y₀_b_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume y₀ b)
(f_int_b_y₁_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume b y₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_left f_int_b_y₁_left,
← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_right f_int_b_y₁_right, ← sub_eq_zero]
simp only [smul_add]; abel
lemma RectangleIntegralVSplit' {b x₀ x₁ y₀ y₁ : ℝ} (hb : b ∈ [[y₀, y₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) :=
RectangleIntegralVSplit
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
lemma RectanglePullToNhdOfPole' [CompleteSpace E] {z₀ z₁ z₂ z₃ p : ℂ}
(h_orientation : z₀.re ≤ z₃.re ∧ z₀.im ≤ z₃.im ∧ z₁.re ≤ z₂.re ∧ z₁.im ≤ z₂.im)
(hp : Rectangle z₁ z₂ ∈ 𝓝 p) (hz : Rectangle z₁ z₂ ⊆ Rectangle z₀ z₃)
(fHolo : HolomorphicOn f (Rectangle z₀ z₃ \ {p})) :
RectangleIntegral f z₀ z₃ = RectangleIntegral f z₁ z₂ := by
obtain ⟨hz₀_re, hz₀_im, hz₁_re, hz₁_im⟩ := h_orientation
have := rect_subset_iff.mp hz
rw [Rectangle, uIcc_of_le hz₀_re, uIcc_of_le hz₀_im] at this
obtain ⟨⟨⟨_, _⟩, ⟨_, _⟩⟩, ⟨_, _⟩, ⟨_, _⟩⟩ := this
obtain ⟨⟨_, _⟩, ⟨_, _⟩⟩ := (uIoo_of_le hz₁_re) ▸ (uIoo_of_le hz₁_im) ▸ rectangle_mem_nhds_iff.mp hp
obtain ⟨_, _, _, _⟩ := show p.re < z₂.re ∧ p.re < z₃.re ∧ p.im < z₂.im ∧ p.im < z₃.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
obtain ⟨_, _, _, _⟩ := show z₀.re < p.re ∧ z₁.re < p.re ∧ z₀.im < p.im ∧ z₁.im < p.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
have fCont := fHolo.continuousOn
have hbot : RectangleBorderIntegrable f (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have htop : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have hleft : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
have hright : RectangleBorderIntegrable f (↑z₁.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
all_goals try {
refine (fCont.mono (rectangleBorder_subset_punctured_rect ?_ ?_)).rectangleBorder_integrable
· simp_all
· simpa using ⟨by linarith, by linarith, by linarith, by linarith⟩
}
have hbot' : z₁.im ∈ [[z₀.im, z₃.im]] := ?_
have htop' : z₂.im ∈ [[z₁.im, z₃.im]] := ?_
have hleft' : z₁.re ∈ [[z₀.re, z₃.re]] := ?_
have hright' : z₂.re ∈ [[z₁.re, z₃.re]] := ?_
all_goals try { rw [Set.uIcc_of_le]; constructor; all_goals assumption }
have hbot'' : Rectangle (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₁.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have htop'' : Rectangle (↑z₀.re + ↑z₂.im * I) (↑z₃.re + ↑z₃.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hleft'' : Rectangle (↑z₀.re + ↑z₁.im * I) (↑z₁.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hright'' : Rectangle (↑z₂.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
all_goals try { apply rectangle_subset_punctured_rect <;> simp_all }
rw [← re_add_im z₀, ← re_add_im z₃,
RectangleIntegralVSplit' hbot' hbot, fHolo.vanishesOnRectangle hbot'', zero_add,
RectangleIntegralVSplit' htop' htop, fHolo.vanishesOnRectangle htop'', add_zero,
RectangleIntegralHSplit' hleft' hleft, fHolo.vanishesOnRectangle hleft'', zero_add,
RectangleIntegralHSplit' hright' hright, fHolo.vanishesOnRectangle hright'', add_zero,
re_add_im, re_add_im]
/-%%
The next lemma allows to zoom a big rectangle down to a small square, centered at a pole.
\begin{lemma}[RectanglePullToNhdOfPole]\label{RectanglePullToNhdOfPole}\lean{RectanglePullToNhdOfPole}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$ except at a point $p$, then the integral of $f$
over the rectangle with corners $z$ and $w$ is the same as the integral of $f$ over a small square
centered at $p$.
\end{lemma}
%%-/
/-- Given `f` holomorphic on a rectangle `z` and `w` except at a point `p`, the integral of `f` over
the rectangle with corners `z` and `w` is the same as the integral of `f` over a small square
centered at `p`. -/
lemma RectanglePullToNhdOfPole [CompleteSpace E] {z w p : ℂ} (zRe_lt_wRe : z.re ≤ w.re)
(zIm_lt_wIm : z.im ≤ w.im) (hp : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral f z w = RectangleIntegral f (-c - I * c + p) (c + I * c + p) := by
/-%%
\begin{proof}\uses{HolomorphicOn.vanishesOnRectangle}\leanok
Chop the big rectangle with two vertical cuts and two horizontal cuts into smaller rectangles,
the middle one being the desired square. The integral over each of the outer rectangles
vanishes, since $f$ is holomorphic there. (The constant $c$ being ``small enough'' here just means
that the inner square is strictly contained in the big rectangle.)
%%-/
filter_upwards [Ioo_mem_nhdsWithin_Ioi' zero_lt_one, SmallSquareInRectangle hp]
intro c ⟨cpos, _⟩ hc
simp_rw [mul_comm I]
exact RectanglePullToNhdOfPole' (by simp_all [cpos.le])
(square_mem_nhds p (ne_of_gt cpos)) hc fHolo
--%%\end{proof}
lemma RectanglePullToNhdOfPole'' [CompleteSpace E] {z w p : ℂ} (zRe_le_wRe : z.re ≤ w.re)
(zIm_le_wIm : z.im ≤ w.im) (pInRectInterior : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral' f z w = RectangleIntegral' f (-c - I * c + p) (c + I * c + p) := by
filter_upwards [RectanglePullToNhdOfPole zRe_le_wRe zIm_le_wIm pInRectInterior fHolo] with c h
simp_rw [RectangleIntegral', h]
theorem ResidueTheoremAtOrigin_aux1c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y + I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux1c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y - I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (-1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem RectangleIntegral.const_smul (f : ℂ → E) (z w c : ℂ) :
RectangleIntegral (fun s => c • f s) z w = c • RectangleIntegral f z w := by
simp [RectangleIntegral, HIntegral, VIntegral, smul_add, smul_sub, smul_smul, mul_comm]
theorem RectangleIntegral.const_mul' (f : ℂ → E) (z w c : ℂ) :
RectangleIntegral' (fun s => c • f s) z w = c • RectangleIntegral' f z w := by
simp [RectangleIntegral', RectangleIntegral.const_smul, smul_smul] ; ring_nf
| theorem RectangleIntegral.translate (f : ℂ → E) (z w p : ℂ) :
RectangleIntegral (fun s => f (s - p)) z w = RectangleIntegral f (z - p) (w - p) | RectangleIntegral.translate | f36a520 20240122 | 1909a40 20240209 | PrimeNumberTheoremAnd/PrimeNumberTheoremAnd/ResidueCalcOnRectangles.lean | {
"lineInFile": 374,
"tokenPositionInFile": 20388,
"theoremPositionInFile": 41
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": ":= by\n simp_rw [RectangleIntegral, HIntegral, VIntegral, sub_re, sub_im, ← intervalIntegral.integral_comp_sub_right]\n congr <;> ext <;> congr 1 <;> simp [Complex.ext_iff]",
"proofType": "tactic",
"proofLengthLines": 2,
"proofLengthTokens": 172
} | prime |
import Mathlib.Analysis.Complex.CauchyIntegral
import Mathlib.Analysis.Complex.Convex
import Mathlib.Analysis.Complex.RemovableSingularity
import Mathlib.Analysis.Analytic.Meromorphic
import Mathlib.Analysis.SpecialFunctions.Integrals
import Mathlib.MeasureTheory.Measure.Lebesgue.Integral
import PrimeNumberTheoremAnd.Rectangle
open Complex BigOperators Nat Classical Real Topology Filter Set MeasureTheory intervalIntegral
open scoped Interval
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f g : ℂ → E}
{z w p c A : ℂ} {x x₁ x₂ y y₁ y₂ σ : ℝ}
noncomputable def HIntegral (f : ℂ → E) (x₁ x₂ y : ℝ) : E := ∫ x in x₁..x₂, f (x + y * I)
noncomputable def VIntegral (f : ℂ → E) (x y₁ y₂ : ℝ) : E := I • ∫ y in y₁..y₂, f (x + y * I)
noncomputable def HIntegral' (f : ℂ → E) (x₁ x₂ y : ℝ) : E := (1 / (2 * π * I)) • HIntegral f x₁ x₂ y
noncomputable def VIntegral' (f : ℂ → E) (x y₁ y₂ : ℝ) : E := (1 / (2 * π * I)) • VIntegral f x y₁ y₂
lemma HIntegral_symm : HIntegral f x₁ x₂ y = - HIntegral f x₂ x₁ y := integral_symm _ _
lemma VIntegral_symm : VIntegral f x y₁ y₂ = - VIntegral f x y₂ y₁ := by
simp_rw [VIntegral, integral_symm y₁ y₂, smul_neg, neg_neg]
/-%%
\begin{definition}[RectangleIntegral]\label{RectangleIntegral}\lean{RectangleIntegral}\leanok
A RectangleIntegral of a function $f$ is one over a rectangle determined by $z$ and $w$ in $\C$.
We will sometimes denote it by $\int_{z}^{w} f$. (There is also a primed version, which is $1/(2\pi i)$ times the original.)
\end{definition}
%%-/
/-- A `RectangleIntegral` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`. -/
noncomputable def RectangleIntegral (f : ℂ → E) (z w : ℂ) : E := HIntegral f z.re w.re z.im -
HIntegral f z.re w.re w.im + VIntegral f w.re z.im w.im - VIntegral f z.re z.im w.im
/-- A `RectangleIntegral'` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`, divided by `2 * π * I`. -/
noncomputable abbrev RectangleIntegral' (f : ℂ → E) (z w : ℂ) : E :=
(1 / (2 * π * I)) • RectangleIntegral f z w
/-% ** Wrong delimiter on purpose **
An UpperUIntegral is the integral of a function over a |\_| shape.
\begin{definition}\label{UpperUIntegral}\lean{UpperUIntegral}\leanok
An UpperUIntegral of a function $f$ comes from $\sigma+i\infty$ down to $\sigma+iT$, over to $\sigma'+iT$, and back up to $\sigma'+i\infty$.
\end{definition}
%-/
noncomputable def UpperUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' T +
I • (∫ y : ℝ in Ici T, f (σ' + y * I)) - I • (∫ y : ℝ in Ici T, f (σ + y * I))
/-% ** Wrong delimiter on purpose **
A LowerUIntegral is the integral of a function over a |-| shape.
\begin{definition}[LowerUIntegral]\label{LowerUIntegral}\lean{LowerUIntegral}\leanok
A LowerUIntegral of a function $f$ comes from $\sigma-i\infty$ up to $\sigma-iT$, over to $\sigma'-iT$, and back down to $\sigma'-i\infty$.
\end{definition}
%-/
noncomputable def LowerUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' (-T) -
I • (∫ y : ℝ in Iic (-T), f (σ' + y * I)) + I • (∫ y : ℝ in Iic (-T), f (σ + y * I))
/-%%
It is very convenient to define integrals along vertical lines in the complex plane, as follows.
\begin{definition}[VerticalIntegral]\label{VerticalIntegral}\lean{VerticalIntegral}\leanok
Let $f$ be a function from $\mathbb{C}$ to $\mathbb{C}$, and let $\sigma$ be a real number. Then we define
$$\int_{(\sigma)}f(s)ds = \int_{\sigma-i\infty}^{\sigma+i\infty}f(s)ds.$$
\end{definition}
%%-/
noncomputable def VerticalIntegral (f : ℂ → E) (σ : ℝ) : E := I • ∫ t : ℝ, f (σ + t * I)
--%% We also have a version with a factor of $1/(2\pi i)$.
noncomputable abbrev VerticalIntegral' (f : ℂ → E) (σ : ℝ) : E :=
(1 / (2 * π * I)) • VerticalIntegral f σ
lemma verticalIntegral_split_three (a b : ℝ) (hf : Integrable (fun t : ℝ ↦ f (σ + t * I))) :
VerticalIntegral f σ = I • (∫ t in Iic a, f (σ + t * I)) + VIntegral f σ a b
+ I • ∫ t in Ici b, f (σ + t * I) := by
simp_rw [VerticalIntegral, VIntegral, ← smul_add]
congr
rw [← intervalIntegral.integral_Iic_sub_Iic hf.restrict hf.restrict, add_sub_cancel,
integral_Iic_eq_integral_Iio, intervalIntegral.integral_Iio_add_Ici hf.restrict hf.restrict]
/-% ** Wrong delimiter on purpose **
\begin{lemma}[DiffVertRect_eq_UpperLowerUs]\label{DiffVertRect_eq_UpperLowerUs}\lean{DiffVertRect_eq_UpperLowerUs}\leanok
The difference of two vertical integrals and a rectangle is the difference of an upper and a lower U integrals.
\end{lemma}
%-/
lemma DiffVertRect_eq_UpperLowerUs {σ σ' T : ℝ}
(f_int_σ : Integrable (fun (t : ℝ) ↦ f (σ + t * I)))
(f_int_σ' : Integrable (fun (t : ℝ) ↦ f (σ' + t * I))) :
(VerticalIntegral f σ') - (VerticalIntegral f σ) - (RectangleIntegral f (σ - I * T) (σ' + I * T)) =
(UpperUIntegral f σ σ' T) - (LowerUIntegral f σ σ' T) := by
rw [verticalIntegral_split_three (-T) T f_int_σ, verticalIntegral_split_three (-T) T f_int_σ']
simp only [smul_eq_mul, RectangleIntegral, sub_re, ofReal_re, mul_re, I_re, zero_mul, I_im,
ofReal_im, mul_zero, sub_self, sub_zero, add_re, add_zero, sub_im, mul_im, one_mul, zero_add,
zero_sub, add_im, UpperUIntegral, LowerUIntegral]
abel
/-%
\begin{proof}\uses{UpperUIntegral, LowerUIntegral}\leanok
Follows directly from the definitions.
\end{proof}
%-/
/-- A function is `HolomorphicOn` a set if it is complex differentiable on that set. -/
abbrev HolomorphicOn (f : ℂ → E) (s : Set ℂ) : Prop := DifferentiableOn ℂ f s
/-%%
\begin{theorem}[existsDifferentiableOn_of_bddAbove]\label{existsDifferentiableOn_of_bddAbove}\lean{existsDifferentiableOn_of_bddAbove}\leanok
If $f$ is differentiable on a set $s$ except at $c\in s$, and $f$ is bounded above on $s\setminus\{c\}$, then there exists a differentiable function $g$ on $s$ such that $f$ and $g$ agree on $s\setminus\{c\}$.
\end{theorem}
%%-/
theorem existsDifferentiableOn_of_bddAbove [CompleteSpace E] {s : Set ℂ} {c : ℂ} (hc : s ∈ nhds c)
(hd : HolomorphicOn f (s \ {c})) (hb : BddAbove (norm ∘ f '' (s \ {c}))) :
∃ (g : ℂ → E), HolomorphicOn g s ∧ (Set.EqOn f g (s \ {c})) :=
⟨Function.update f c (limUnder (𝓝[{c}ᶜ] c) f),
differentiableOn_update_limUnder_of_bddAbove hc hd hb,
fun z hz ↦ if h : z = c then (hz.2 h).elim else by simp [h]⟩
/-%%
\begin{proof}\leanok
This is the Riemann Removable Singularity Theorem, slightly rephrased from what's in Mathlib. (We don't care what the function $g$ is, just that it's holomorphic.)
\end{proof}
%%-/
/-%%
\begin{theorem}[HolomorphicOn.vanishesOnRectangle]\label{HolomorphicOn.vanishesOnRectangle}\lean{HolomorphicOn.vanishesOnRectangle}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$, then the integral of $f$ over the rectangle with corners $z$ and $w$ is $0$.
\end{theorem}
%%-/
theorem HolomorphicOn.vanishesOnRectangle [CompleteSpace E] {U : Set ℂ}
(f_holo : HolomorphicOn f U) (hU : Rectangle z w ⊆ U) :
RectangleIntegral f z w = 0 :=
integral_boundary_rect_eq_zero_of_differentiableOn f z w (f_holo.mono hU)
/-%%
\begin{proof}\leanok
This is in a Mathlib PR.
\end{proof}
%%-/
theorem RectangleIntegral_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral f z w = RectangleIntegral g z w := by
unfold RectangleIntegral VIntegral
congr 2; swap; congr 1; swap; congr 1
all_goals refine intervalIntegral.integral_congr fun _ _ ↦ h ?_
· exact Or.inl <| Or.inl <| Or.inl ⟨by simpa, by simp⟩
· exact Or.inl <| Or.inr ⟨by simpa, by simp⟩
· exact Or.inr ⟨by simp, by simpa⟩
· exact Or.inl <| Or.inl <| Or.inr ⟨by simp, by simpa⟩
theorem RectangleIntegral'_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral' f z w = RectangleIntegral' g z w := by
rw [RectangleIntegral', RectangleIntegral_congr h]
theorem rectangleIntegral_symm (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f z w = RectangleIntegral f w z := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, intervalIntegral.integral_symm w.re,
intervalIntegral.integral_symm w.im, sub_neg_eq_add, smul_neg, sub_neg_eq_add, ← sub_eq_add_neg,
neg_add_eq_sub, sub_add_eq_add_sub]
theorem rectangleIntegral_symm_re (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f (w.re + z.im * I) (z.re + w.im * I) = - RectangleIntegral f z w := by
simp [RectangleIntegral, ← sub_eq_zero]
rw [HIntegral_symm (y := z.im), HIntegral_symm (y := w.im)]
abel
def RectangleBorderIntegrable (f : ℂ → E) (z w : ℂ) : Prop :=
IntervalIntegrable (fun x => f (x + z.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun x => f (x + w.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun y => f (w.re + y * I)) volume z.im w.im ∧
IntervalIntegrable (fun y => f (z.re + y * I)) volume z.im w.im
theorem RectangleBorderIntegrable.add {f g : ℂ → E} (hf : RectangleBorderIntegrable f z w)
(hg : RectangleBorderIntegrable g z w) :
RectangleIntegral (f + g) z w = RectangleIntegral f z w + RectangleIntegral g z w := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
rw [intervalIntegral.integral_add hf.1 hg.1, intervalIntegral.integral_add hf.2.1 hg.2.1,
intervalIntegral.integral_add hf.2.2.1 hg.2.2.1, intervalIntegral.integral_add hf.2.2.2 hg.2.2.2]
rw [← sub_eq_zero]
simp only [smul_add]; abel
theorem ContinuousOn.rectangleBorder_integrable (hf : ContinuousOn f (RectangleBorder z w)) :
RectangleBorderIntegrable f z w :=
⟨(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_re z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_re z w)).intervalIntegrable⟩
theorem ContinuousOn.rectangleBorderIntegrable (hf : ContinuousOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
(hf.mono (rectangleBorder_subset_rectangle z w)).rectangleBorder_integrable
theorem ContinuousOn.rectangleBorderNoPIntegrable (hf : ContinuousOn f (Rectangle z w \ {p}))
(pNotOnBorder : p ∉ RectangleBorder z w) : RectangleBorderIntegrable f z w := by
refine (hf.mono (Set.subset_diff.mpr ?_)).rectangleBorder_integrable
exact ⟨rectangleBorder_subset_rectangle z w, disjoint_singleton_right.mpr pNotOnBorder⟩
theorem HolomorphicOn.rectangleBorderIntegrable' (hf : HolomorphicOn f (Rectangle z w \ {p}))
(hp : Rectangle z w ∈ nhds p) : RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderNoPIntegrable (not_mem_rectangleBorder_of_rectangle_mem_nhds hp)
theorem HolomorphicOn.rectangleBorderIntegrable (hf : HolomorphicOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderIntegrable
/--
Given `x₀ a x₁ : ℝ`, and `y₀ y₁ : ℝ` and a function `f : ℂ → ℂ` so that
both `(t : ℝ) ↦ f(t + y₀ * I)` and `(t : ℝ) ↦ f(t + y₁ * I)` are integrable over both
`t ∈ Icc x₀ a` and `t ∈ Icc a x₁`, we have that
`RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I)` is the sum of
`RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I)` and
`RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I)`.
-/
lemma RectangleIntegralHSplit {a x₀ x₁ y₀ y₁ : ℝ}
(f_int_x₀_a_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume x₀ a)
(f_int_a_x₁_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume a x₁)
(f_int_x₀_a_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume x₀ a)
(f_int_a_x₁_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume a x₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_bot f_int_a_x₁_bot,
← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_top f_int_a_x₁_top]
abel
lemma RectangleIntegralHSplit' {a x₀ x₁ y₀ y₁ : ℝ} (ha : a ∈ [[x₀, x₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) :=
RectangleIntegralHSplit
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
lemma RectangleIntegralVSplit {b x₀ x₁ y₀ y₁ : ℝ}
(f_int_y₀_b_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume y₀ b)
(f_int_b_y₁_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume b y₁)
(f_int_y₀_b_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume y₀ b)
(f_int_b_y₁_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume b y₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_left f_int_b_y₁_left,
← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_right f_int_b_y₁_right, ← sub_eq_zero]
simp only [smul_add]; abel
lemma RectangleIntegralVSplit' {b x₀ x₁ y₀ y₁ : ℝ} (hb : b ∈ [[y₀, y₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) :=
RectangleIntegralVSplit
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
lemma RectanglePullToNhdOfPole' [CompleteSpace E] {z₀ z₁ z₂ z₃ p : ℂ}
(h_orientation : z₀.re ≤ z₃.re ∧ z₀.im ≤ z₃.im ∧ z₁.re ≤ z₂.re ∧ z₁.im ≤ z₂.im)
(hp : Rectangle z₁ z₂ ∈ 𝓝 p) (hz : Rectangle z₁ z₂ ⊆ Rectangle z₀ z₃)
(fHolo : HolomorphicOn f (Rectangle z₀ z₃ \ {p})) :
RectangleIntegral f z₀ z₃ = RectangleIntegral f z₁ z₂ := by
obtain ⟨hz₀_re, hz₀_im, hz₁_re, hz₁_im⟩ := h_orientation
have := rect_subset_iff.mp hz
rw [Rectangle, uIcc_of_le hz₀_re, uIcc_of_le hz₀_im] at this
obtain ⟨⟨⟨_, _⟩, ⟨_, _⟩⟩, ⟨_, _⟩, ⟨_, _⟩⟩ := this
obtain ⟨⟨_, _⟩, ⟨_, _⟩⟩ := (uIoo_of_le hz₁_re) ▸ (uIoo_of_le hz₁_im) ▸ rectangle_mem_nhds_iff.mp hp
obtain ⟨_, _, _, _⟩ := show p.re < z₂.re ∧ p.re < z₃.re ∧ p.im < z₂.im ∧ p.im < z₃.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
obtain ⟨_, _, _, _⟩ := show z₀.re < p.re ∧ z₁.re < p.re ∧ z₀.im < p.im ∧ z₁.im < p.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
have fCont := fHolo.continuousOn
have hbot : RectangleBorderIntegrable f (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have htop : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have hleft : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
have hright : RectangleBorderIntegrable f (↑z₁.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
all_goals try {
refine (fCont.mono (rectangleBorder_subset_punctured_rect ?_ ?_)).rectangleBorder_integrable
· simp_all
· simpa using ⟨by linarith, by linarith, by linarith, by linarith⟩
}
have hbot' : z₁.im ∈ [[z₀.im, z₃.im]] := ?_
have htop' : z₂.im ∈ [[z₁.im, z₃.im]] := ?_
have hleft' : z₁.re ∈ [[z₀.re, z₃.re]] := ?_
have hright' : z₂.re ∈ [[z₁.re, z₃.re]] := ?_
all_goals try { rw [Set.uIcc_of_le]; constructor; all_goals assumption }
have hbot'' : Rectangle (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₁.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have htop'' : Rectangle (↑z₀.re + ↑z₂.im * I) (↑z₃.re + ↑z₃.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hleft'' : Rectangle (↑z₀.re + ↑z₁.im * I) (↑z₁.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hright'' : Rectangle (↑z₂.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
all_goals try { apply rectangle_subset_punctured_rect <;> simp_all }
rw [← re_add_im z₀, ← re_add_im z₃,
RectangleIntegralVSplit' hbot' hbot, fHolo.vanishesOnRectangle hbot'', zero_add,
RectangleIntegralVSplit' htop' htop, fHolo.vanishesOnRectangle htop'', add_zero,
RectangleIntegralHSplit' hleft' hleft, fHolo.vanishesOnRectangle hleft'', zero_add,
RectangleIntegralHSplit' hright' hright, fHolo.vanishesOnRectangle hright'', add_zero,
re_add_im, re_add_im]
/-%%
The next lemma allows to zoom a big rectangle down to a small square, centered at a pole.
\begin{lemma}[RectanglePullToNhdOfPole]\label{RectanglePullToNhdOfPole}\lean{RectanglePullToNhdOfPole}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$ except at a point $p$, then the integral of $f$
over the rectangle with corners $z$ and $w$ is the same as the integral of $f$ over a small square
centered at $p$.
\end{lemma}
%%-/
/-- Given `f` holomorphic on a rectangle `z` and `w` except at a point `p`, the integral of `f` over
the rectangle with corners `z` and `w` is the same as the integral of `f` over a small square
centered at `p`. -/
lemma RectanglePullToNhdOfPole [CompleteSpace E] {z w p : ℂ} (zRe_lt_wRe : z.re ≤ w.re)
(zIm_lt_wIm : z.im ≤ w.im) (hp : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral f z w = RectangleIntegral f (-c - I * c + p) (c + I * c + p) := by
/-%%
\begin{proof}\uses{HolomorphicOn.vanishesOnRectangle}\leanok
Chop the big rectangle with two vertical cuts and two horizontal cuts into smaller rectangles,
the middle one being the desired square. The integral over each of the outer rectangles
vanishes, since $f$ is holomorphic there. (The constant $c$ being ``small enough'' here just means
that the inner square is strictly contained in the big rectangle.)
%%-/
filter_upwards [Ioo_mem_nhdsWithin_Ioi' zero_lt_one, SmallSquareInRectangle hp]
intro c ⟨cpos, _⟩ hc
simp_rw [mul_comm I]
exact RectanglePullToNhdOfPole' (by simp_all [cpos.le])
(square_mem_nhds p (ne_of_gt cpos)) hc fHolo
--%%\end{proof}
lemma RectanglePullToNhdOfPole'' [CompleteSpace E] {z w p : ℂ} (zRe_le_wRe : z.re ≤ w.re)
(zIm_le_wIm : z.im ≤ w.im) (pInRectInterior : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral' f z w = RectangleIntegral' f (-c - I * c + p) (c + I * c + p) := by
filter_upwards [RectanglePullToNhdOfPole zRe_le_wRe zIm_le_wIm pInRectInterior fHolo] with c h
simp_rw [RectangleIntegral', h]
theorem ResidueTheoremAtOrigin_aux1c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y + I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux1c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y - I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (-1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem RectangleIntegral.const_smul (f : ℂ → E) (z w c : ℂ) :
RectangleIntegral (fun s => c • f s) z w = c • RectangleIntegral f z w := by
simp [RectangleIntegral, HIntegral, VIntegral, smul_add, smul_sub, smul_smul, mul_comm]
theorem RectangleIntegral.const_mul' (f : ℂ → E) (z w c : ℂ) :
RectangleIntegral' (fun s => c • f s) z w = c • RectangleIntegral' f z w := by
simp [RectangleIntegral', RectangleIntegral.const_smul, smul_smul] ; ring_nf
theorem RectangleIntegral.translate (f : ℂ → E) (z w p : ℂ) :
RectangleIntegral (fun s => f (s - p)) z w = RectangleIntegral f (z - p) (w - p) := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, sub_re, sub_im, ← intervalIntegral.integral_comp_sub_right]
congr <;> ext <;> congr 1 <;> simp [Complex.ext_iff]
| theorem RectangleIntegral.translate' (f : ℂ → E) (z w p : ℂ) :
RectangleIntegral' (fun s => f (s - p)) z w = RectangleIntegral' f (z - p) (w - p) | RectangleIntegral.translate' | f36a520 20240122 | 1909a40 20240209 | PrimeNumberTheoremAnd/PrimeNumberTheoremAnd/ResidueCalcOnRectangles.lean | {
"lineInFile": 379,
"tokenPositionInFile": 20709,
"theoremPositionInFile": 42
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": ":= by\n simp_rw [RectangleIntegral', RectangleIntegral.translate]",
"proofType": "tactic",
"proofLengthLines": 1,
"proofLengthTokens": 65
} | prime |
import Mathlib.Analysis.Complex.CauchyIntegral
import Mathlib.Analysis.Complex.Convex
import Mathlib.Analysis.Complex.RemovableSingularity
import Mathlib.Analysis.Analytic.Meromorphic
import Mathlib.Analysis.SpecialFunctions.Integrals
import Mathlib.MeasureTheory.Measure.Lebesgue.Integral
import PrimeNumberTheoremAnd.Rectangle
open Complex BigOperators Nat Classical Real Topology Filter Set MeasureTheory intervalIntegral
open scoped Interval
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f g : ℂ → E}
{z w p c A : ℂ} {x x₁ x₂ y y₁ y₂ σ : ℝ}
noncomputable def HIntegral (f : ℂ → E) (x₁ x₂ y : ℝ) : E := ∫ x in x₁..x₂, f (x + y * I)
noncomputable def VIntegral (f : ℂ → E) (x y₁ y₂ : ℝ) : E := I • ∫ y in y₁..y₂, f (x + y * I)
noncomputable def HIntegral' (f : ℂ → E) (x₁ x₂ y : ℝ) : E := (1 / (2 * π * I)) • HIntegral f x₁ x₂ y
noncomputable def VIntegral' (f : ℂ → E) (x y₁ y₂ : ℝ) : E := (1 / (2 * π * I)) • VIntegral f x y₁ y₂
lemma HIntegral_symm : HIntegral f x₁ x₂ y = - HIntegral f x₂ x₁ y := integral_symm _ _
lemma VIntegral_symm : VIntegral f x y₁ y₂ = - VIntegral f x y₂ y₁ := by
simp_rw [VIntegral, integral_symm y₁ y₂, smul_neg, neg_neg]
/-%%
\begin{definition}[RectangleIntegral]\label{RectangleIntegral}\lean{RectangleIntegral}\leanok
A RectangleIntegral of a function $f$ is one over a rectangle determined by $z$ and $w$ in $\C$.
We will sometimes denote it by $\int_{z}^{w} f$. (There is also a primed version, which is $1/(2\pi i)$ times the original.)
\end{definition}
%%-/
/-- A `RectangleIntegral` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`. -/
noncomputable def RectangleIntegral (f : ℂ → E) (z w : ℂ) : E := HIntegral f z.re w.re z.im -
HIntegral f z.re w.re w.im + VIntegral f w.re z.im w.im - VIntegral f z.re z.im w.im
/-- A `RectangleIntegral'` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`, divided by `2 * π * I`. -/
noncomputable abbrev RectangleIntegral' (f : ℂ → E) (z w : ℂ) : E :=
(1 / (2 * π * I)) • RectangleIntegral f z w
/-% ** Wrong delimiter on purpose **
An UpperUIntegral is the integral of a function over a |\_| shape.
\begin{definition}\label{UpperUIntegral}\lean{UpperUIntegral}\leanok
An UpperUIntegral of a function $f$ comes from $\sigma+i\infty$ down to $\sigma+iT$, over to $\sigma'+iT$, and back up to $\sigma'+i\infty$.
\end{definition}
%-/
noncomputable def UpperUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' T +
I • (∫ y : ℝ in Ici T, f (σ' + y * I)) - I • (∫ y : ℝ in Ici T, f (σ + y * I))
/-% ** Wrong delimiter on purpose **
A LowerUIntegral is the integral of a function over a |-| shape.
\begin{definition}[LowerUIntegral]\label{LowerUIntegral}\lean{LowerUIntegral}\leanok
A LowerUIntegral of a function $f$ comes from $\sigma-i\infty$ up to $\sigma-iT$, over to $\sigma'-iT$, and back down to $\sigma'-i\infty$.
\end{definition}
%-/
noncomputable def LowerUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' (-T) -
I • (∫ y : ℝ in Iic (-T), f (σ' + y * I)) + I • (∫ y : ℝ in Iic (-T), f (σ + y * I))
/-%%
It is very convenient to define integrals along vertical lines in the complex plane, as follows.
\begin{definition}[VerticalIntegral]\label{VerticalIntegral}\lean{VerticalIntegral}\leanok
Let $f$ be a function from $\mathbb{C}$ to $\mathbb{C}$, and let $\sigma$ be a real number. Then we define
$$\int_{(\sigma)}f(s)ds = \int_{\sigma-i\infty}^{\sigma+i\infty}f(s)ds.$$
\end{definition}
%%-/
noncomputable def VerticalIntegral (f : ℂ → E) (σ : ℝ) : E := I • ∫ t : ℝ, f (σ + t * I)
--%% We also have a version with a factor of $1/(2\pi i)$.
noncomputable abbrev VerticalIntegral' (f : ℂ → E) (σ : ℝ) : E :=
(1 / (2 * π * I)) • VerticalIntegral f σ
lemma verticalIntegral_split_three (a b : ℝ) (hf : Integrable (fun t : ℝ ↦ f (σ + t * I))) :
VerticalIntegral f σ = I • (∫ t in Iic a, f (σ + t * I)) + VIntegral f σ a b
+ I • ∫ t in Ici b, f (σ + t * I) := by
simp_rw [VerticalIntegral, VIntegral, ← smul_add]
congr
rw [← intervalIntegral.integral_Iic_sub_Iic hf.restrict hf.restrict, add_sub_cancel,
integral_Iic_eq_integral_Iio, intervalIntegral.integral_Iio_add_Ici hf.restrict hf.restrict]
/-% ** Wrong delimiter on purpose **
\begin{lemma}[DiffVertRect_eq_UpperLowerUs]\label{DiffVertRect_eq_UpperLowerUs}\lean{DiffVertRect_eq_UpperLowerUs}\leanok
The difference of two vertical integrals and a rectangle is the difference of an upper and a lower U integrals.
\end{lemma}
%-/
lemma DiffVertRect_eq_UpperLowerUs {σ σ' T : ℝ}
(f_int_σ : Integrable (fun (t : ℝ) ↦ f (σ + t * I)))
(f_int_σ' : Integrable (fun (t : ℝ) ↦ f (σ' + t * I))) :
(VerticalIntegral f σ') - (VerticalIntegral f σ) - (RectangleIntegral f (σ - I * T) (σ' + I * T)) =
(UpperUIntegral f σ σ' T) - (LowerUIntegral f σ σ' T) := by
rw [verticalIntegral_split_three (-T) T f_int_σ, verticalIntegral_split_three (-T) T f_int_σ']
simp only [smul_eq_mul, RectangleIntegral, sub_re, ofReal_re, mul_re, I_re, zero_mul, I_im,
ofReal_im, mul_zero, sub_self, sub_zero, add_re, add_zero, sub_im, mul_im, one_mul, zero_add,
zero_sub, add_im, UpperUIntegral, LowerUIntegral]
abel
/-%
\begin{proof}\uses{UpperUIntegral, LowerUIntegral}\leanok
Follows directly from the definitions.
\end{proof}
%-/
/-- A function is `HolomorphicOn` a set if it is complex differentiable on that set. -/
abbrev HolomorphicOn (f : ℂ → E) (s : Set ℂ) : Prop := DifferentiableOn ℂ f s
/-%%
\begin{theorem}[existsDifferentiableOn_of_bddAbove]\label{existsDifferentiableOn_of_bddAbove}\lean{existsDifferentiableOn_of_bddAbove}\leanok
If $f$ is differentiable on a set $s$ except at $c\in s$, and $f$ is bounded above on $s\setminus\{c\}$, then there exists a differentiable function $g$ on $s$ such that $f$ and $g$ agree on $s\setminus\{c\}$.
\end{theorem}
%%-/
theorem existsDifferentiableOn_of_bddAbove [CompleteSpace E] {s : Set ℂ} {c : ℂ} (hc : s ∈ nhds c)
(hd : HolomorphicOn f (s \ {c})) (hb : BddAbove (norm ∘ f '' (s \ {c}))) :
∃ (g : ℂ → E), HolomorphicOn g s ∧ (Set.EqOn f g (s \ {c})) :=
⟨Function.update f c (limUnder (𝓝[{c}ᶜ] c) f),
differentiableOn_update_limUnder_of_bddAbove hc hd hb,
fun z hz ↦ if h : z = c then (hz.2 h).elim else by simp [h]⟩
/-%%
\begin{proof}\leanok
This is the Riemann Removable Singularity Theorem, slightly rephrased from what's in Mathlib. (We don't care what the function $g$ is, just that it's holomorphic.)
\end{proof}
%%-/
/-%%
\begin{theorem}[HolomorphicOn.vanishesOnRectangle]\label{HolomorphicOn.vanishesOnRectangle}\lean{HolomorphicOn.vanishesOnRectangle}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$, then the integral of $f$ over the rectangle with corners $z$ and $w$ is $0$.
\end{theorem}
%%-/
theorem HolomorphicOn.vanishesOnRectangle [CompleteSpace E] {U : Set ℂ}
(f_holo : HolomorphicOn f U) (hU : Rectangle z w ⊆ U) :
RectangleIntegral f z w = 0 :=
integral_boundary_rect_eq_zero_of_differentiableOn f z w (f_holo.mono hU)
/-%%
\begin{proof}\leanok
This is in a Mathlib PR.
\end{proof}
%%-/
theorem RectangleIntegral_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral f z w = RectangleIntegral g z w := by
unfold RectangleIntegral VIntegral
congr 2; swap; congr 1; swap; congr 1
all_goals refine intervalIntegral.integral_congr fun _ _ ↦ h ?_
· exact Or.inl <| Or.inl <| Or.inl ⟨by simpa, by simp⟩
· exact Or.inl <| Or.inr ⟨by simpa, by simp⟩
· exact Or.inr ⟨by simp, by simpa⟩
· exact Or.inl <| Or.inl <| Or.inr ⟨by simp, by simpa⟩
theorem RectangleIntegral'_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral' f z w = RectangleIntegral' g z w := by
rw [RectangleIntegral', RectangleIntegral_congr h]
theorem rectangleIntegral_symm (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f z w = RectangleIntegral f w z := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, intervalIntegral.integral_symm w.re,
intervalIntegral.integral_symm w.im, sub_neg_eq_add, smul_neg, sub_neg_eq_add, ← sub_eq_add_neg,
neg_add_eq_sub, sub_add_eq_add_sub]
theorem rectangleIntegral_symm_re (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f (w.re + z.im * I) (z.re + w.im * I) = - RectangleIntegral f z w := by
simp [RectangleIntegral, ← sub_eq_zero]
rw [HIntegral_symm (y := z.im), HIntegral_symm (y := w.im)]
abel
def RectangleBorderIntegrable (f : ℂ → E) (z w : ℂ) : Prop :=
IntervalIntegrable (fun x => f (x + z.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun x => f (x + w.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun y => f (w.re + y * I)) volume z.im w.im ∧
IntervalIntegrable (fun y => f (z.re + y * I)) volume z.im w.im
theorem RectangleBorderIntegrable.add {f g : ℂ → E} (hf : RectangleBorderIntegrable f z w)
(hg : RectangleBorderIntegrable g z w) :
RectangleIntegral (f + g) z w = RectangleIntegral f z w + RectangleIntegral g z w := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
rw [intervalIntegral.integral_add hf.1 hg.1, intervalIntegral.integral_add hf.2.1 hg.2.1,
intervalIntegral.integral_add hf.2.2.1 hg.2.2.1, intervalIntegral.integral_add hf.2.2.2 hg.2.2.2]
rw [← sub_eq_zero]
simp only [smul_add]; abel
theorem ContinuousOn.rectangleBorder_integrable (hf : ContinuousOn f (RectangleBorder z w)) :
RectangleBorderIntegrable f z w :=
⟨(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_re z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_re z w)).intervalIntegrable⟩
theorem ContinuousOn.rectangleBorderIntegrable (hf : ContinuousOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
(hf.mono (rectangleBorder_subset_rectangle z w)).rectangleBorder_integrable
theorem ContinuousOn.rectangleBorderNoPIntegrable (hf : ContinuousOn f (Rectangle z w \ {p}))
(pNotOnBorder : p ∉ RectangleBorder z w) : RectangleBorderIntegrable f z w := by
refine (hf.mono (Set.subset_diff.mpr ?_)).rectangleBorder_integrable
exact ⟨rectangleBorder_subset_rectangle z w, disjoint_singleton_right.mpr pNotOnBorder⟩
theorem HolomorphicOn.rectangleBorderIntegrable' (hf : HolomorphicOn f (Rectangle z w \ {p}))
(hp : Rectangle z w ∈ nhds p) : RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderNoPIntegrable (not_mem_rectangleBorder_of_rectangle_mem_nhds hp)
theorem HolomorphicOn.rectangleBorderIntegrable (hf : HolomorphicOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderIntegrable
/--
Given `x₀ a x₁ : ℝ`, and `y₀ y₁ : ℝ` and a function `f : ℂ → ℂ` so that
both `(t : ℝ) ↦ f(t + y₀ * I)` and `(t : ℝ) ↦ f(t + y₁ * I)` are integrable over both
`t ∈ Icc x₀ a` and `t ∈ Icc a x₁`, we have that
`RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I)` is the sum of
`RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I)` and
`RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I)`.
-/
lemma RectangleIntegralHSplit {a x₀ x₁ y₀ y₁ : ℝ}
(f_int_x₀_a_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume x₀ a)
(f_int_a_x₁_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume a x₁)
(f_int_x₀_a_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume x₀ a)
(f_int_a_x₁_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume a x₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_bot f_int_a_x₁_bot,
← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_top f_int_a_x₁_top]
abel
lemma RectangleIntegralHSplit' {a x₀ x₁ y₀ y₁ : ℝ} (ha : a ∈ [[x₀, x₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) :=
RectangleIntegralHSplit
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
lemma RectangleIntegralVSplit {b x₀ x₁ y₀ y₁ : ℝ}
(f_int_y₀_b_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume y₀ b)
(f_int_b_y₁_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume b y₁)
(f_int_y₀_b_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume y₀ b)
(f_int_b_y₁_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume b y₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_left f_int_b_y₁_left,
← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_right f_int_b_y₁_right, ← sub_eq_zero]
simp only [smul_add]; abel
lemma RectangleIntegralVSplit' {b x₀ x₁ y₀ y₁ : ℝ} (hb : b ∈ [[y₀, y₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) :=
RectangleIntegralVSplit
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
lemma RectanglePullToNhdOfPole' [CompleteSpace E] {z₀ z₁ z₂ z₃ p : ℂ}
(h_orientation : z₀.re ≤ z₃.re ∧ z₀.im ≤ z₃.im ∧ z₁.re ≤ z₂.re ∧ z₁.im ≤ z₂.im)
(hp : Rectangle z₁ z₂ ∈ 𝓝 p) (hz : Rectangle z₁ z₂ ⊆ Rectangle z₀ z₃)
(fHolo : HolomorphicOn f (Rectangle z₀ z₃ \ {p})) :
RectangleIntegral f z₀ z₃ = RectangleIntegral f z₁ z₂ := by
obtain ⟨hz₀_re, hz₀_im, hz₁_re, hz₁_im⟩ := h_orientation
have := rect_subset_iff.mp hz
rw [Rectangle, uIcc_of_le hz₀_re, uIcc_of_le hz₀_im] at this
obtain ⟨⟨⟨_, _⟩, ⟨_, _⟩⟩, ⟨_, _⟩, ⟨_, _⟩⟩ := this
obtain ⟨⟨_, _⟩, ⟨_, _⟩⟩ := (uIoo_of_le hz₁_re) ▸ (uIoo_of_le hz₁_im) ▸ rectangle_mem_nhds_iff.mp hp
obtain ⟨_, _, _, _⟩ := show p.re < z₂.re ∧ p.re < z₃.re ∧ p.im < z₂.im ∧ p.im < z₃.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
obtain ⟨_, _, _, _⟩ := show z₀.re < p.re ∧ z₁.re < p.re ∧ z₀.im < p.im ∧ z₁.im < p.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
have fCont := fHolo.continuousOn
have hbot : RectangleBorderIntegrable f (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have htop : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have hleft : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
have hright : RectangleBorderIntegrable f (↑z₁.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
all_goals try {
refine (fCont.mono (rectangleBorder_subset_punctured_rect ?_ ?_)).rectangleBorder_integrable
· simp_all
· simpa using ⟨by linarith, by linarith, by linarith, by linarith⟩
}
have hbot' : z₁.im ∈ [[z₀.im, z₃.im]] := ?_
have htop' : z₂.im ∈ [[z₁.im, z₃.im]] := ?_
have hleft' : z₁.re ∈ [[z₀.re, z₃.re]] := ?_
have hright' : z₂.re ∈ [[z₁.re, z₃.re]] := ?_
all_goals try { rw [Set.uIcc_of_le]; constructor; all_goals assumption }
have hbot'' : Rectangle (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₁.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have htop'' : Rectangle (↑z₀.re + ↑z₂.im * I) (↑z₃.re + ↑z₃.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hleft'' : Rectangle (↑z₀.re + ↑z₁.im * I) (↑z₁.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hright'' : Rectangle (↑z₂.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
all_goals try { apply rectangle_subset_punctured_rect <;> simp_all }
rw [← re_add_im z₀, ← re_add_im z₃,
RectangleIntegralVSplit' hbot' hbot, fHolo.vanishesOnRectangle hbot'', zero_add,
RectangleIntegralVSplit' htop' htop, fHolo.vanishesOnRectangle htop'', add_zero,
RectangleIntegralHSplit' hleft' hleft, fHolo.vanishesOnRectangle hleft'', zero_add,
RectangleIntegralHSplit' hright' hright, fHolo.vanishesOnRectangle hright'', add_zero,
re_add_im, re_add_im]
/-%%
The next lemma allows to zoom a big rectangle down to a small square, centered at a pole.
\begin{lemma}[RectanglePullToNhdOfPole]\label{RectanglePullToNhdOfPole}\lean{RectanglePullToNhdOfPole}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$ except at a point $p$, then the integral of $f$
over the rectangle with corners $z$ and $w$ is the same as the integral of $f$ over a small square
centered at $p$.
\end{lemma}
%%-/
/-- Given `f` holomorphic on a rectangle `z` and `w` except at a point `p`, the integral of `f` over
the rectangle with corners `z` and `w` is the same as the integral of `f` over a small square
centered at `p`. -/
lemma RectanglePullToNhdOfPole [CompleteSpace E] {z w p : ℂ} (zRe_lt_wRe : z.re ≤ w.re)
(zIm_lt_wIm : z.im ≤ w.im) (hp : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral f z w = RectangleIntegral f (-c - I * c + p) (c + I * c + p) := by
/-%%
\begin{proof}\uses{HolomorphicOn.vanishesOnRectangle}\leanok
Chop the big rectangle with two vertical cuts and two horizontal cuts into smaller rectangles,
the middle one being the desired square. The integral over each of the outer rectangles
vanishes, since $f$ is holomorphic there. (The constant $c$ being ``small enough'' here just means
that the inner square is strictly contained in the big rectangle.)
%%-/
filter_upwards [Ioo_mem_nhdsWithin_Ioi' zero_lt_one, SmallSquareInRectangle hp]
intro c ⟨cpos, _⟩ hc
simp_rw [mul_comm I]
exact RectanglePullToNhdOfPole' (by simp_all [cpos.le])
(square_mem_nhds p (ne_of_gt cpos)) hc fHolo
--%%\end{proof}
lemma RectanglePullToNhdOfPole'' [CompleteSpace E] {z w p : ℂ} (zRe_le_wRe : z.re ≤ w.re)
(zIm_le_wIm : z.im ≤ w.im) (pInRectInterior : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral' f z w = RectangleIntegral' f (-c - I * c + p) (c + I * c + p) := by
filter_upwards [RectanglePullToNhdOfPole zRe_le_wRe zIm_le_wIm pInRectInterior fHolo] with c h
simp_rw [RectangleIntegral', h]
theorem ResidueTheoremAtOrigin_aux1c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y + I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux1c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y - I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (-1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem RectangleIntegral.const_smul (f : ℂ → E) (z w c : ℂ) :
RectangleIntegral (fun s => c • f s) z w = c • RectangleIntegral f z w := by
simp [RectangleIntegral, HIntegral, VIntegral, smul_add, smul_sub, smul_smul, mul_comm]
theorem RectangleIntegral.const_mul' (f : ℂ → E) (z w c : ℂ) :
RectangleIntegral' (fun s => c • f s) z w = c • RectangleIntegral' f z w := by
simp [RectangleIntegral', RectangleIntegral.const_smul, smul_smul] ; ring_nf
theorem RectangleIntegral.translate (f : ℂ → E) (z w p : ℂ) :
RectangleIntegral (fun s => f (s - p)) z w = RectangleIntegral f (z - p) (w - p) := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, sub_re, sub_im, ← intervalIntegral.integral_comp_sub_right]
congr <;> ext <;> congr 1 <;> simp [Complex.ext_iff]
theorem RectangleIntegral.translate' (f : ℂ → E) (z w p : ℂ) :
RectangleIntegral' (fun s => f (s - p)) z w = RectangleIntegral' f (z - p) (w - p) := by
simp_rw [RectangleIntegral', RectangleIntegral.translate]
| lemma Complex.inv_re_add_im : (x + y * I)⁻¹ = (x - I * y) / (x ^ 2 + y ^ 2) | Complex.inv_re_add_im | f36a520 20240122 | 1909a40 20240209 | PrimeNumberTheoremAnd/PrimeNumberTheoremAnd/ResidueCalcOnRectangles.lean | {
"lineInFile": 383,
"tokenPositionInFile": 20926,
"theoremPositionInFile": 43
} | {
"inFilePremises": false,
"repositoryPremises": false
} | {
"hasProof": true,
"proof": ":= by\n rw [Complex.inv_def, div_eq_mul_inv] ; congr <;> simp [conj_ofReal, normSq] <;> ring",
"proofType": "tactic",
"proofLengthLines": 1,
"proofLengthTokens": 92
} | prime |
import Mathlib.Analysis.Complex.CauchyIntegral
import Mathlib.Analysis.Complex.Convex
import Mathlib.Analysis.Complex.RemovableSingularity
import Mathlib.Analysis.Analytic.Meromorphic
import Mathlib.Analysis.SpecialFunctions.Integrals
import Mathlib.MeasureTheory.Measure.Lebesgue.Integral
import PrimeNumberTheoremAnd.Rectangle
open Complex BigOperators Nat Classical Real Topology Filter Set MeasureTheory intervalIntegral
open scoped Interval
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f g : ℂ → E}
{z w p c A : ℂ} {x x₁ x₂ y y₁ y₂ σ : ℝ}
noncomputable def HIntegral (f : ℂ → E) (x₁ x₂ y : ℝ) : E := ∫ x in x₁..x₂, f (x + y * I)
noncomputable def VIntegral (f : ℂ → E) (x y₁ y₂ : ℝ) : E := I • ∫ y in y₁..y₂, f (x + y * I)
noncomputable def HIntegral' (f : ℂ → E) (x₁ x₂ y : ℝ) : E := (1 / (2 * π * I)) • HIntegral f x₁ x₂ y
noncomputable def VIntegral' (f : ℂ → E) (x y₁ y₂ : ℝ) : E := (1 / (2 * π * I)) • VIntegral f x y₁ y₂
lemma HIntegral_symm : HIntegral f x₁ x₂ y = - HIntegral f x₂ x₁ y := integral_symm _ _
lemma VIntegral_symm : VIntegral f x y₁ y₂ = - VIntegral f x y₂ y₁ := by
simp_rw [VIntegral, integral_symm y₁ y₂, smul_neg, neg_neg]
/-%%
\begin{definition}[RectangleIntegral]\label{RectangleIntegral}\lean{RectangleIntegral}\leanok
A RectangleIntegral of a function $f$ is one over a rectangle determined by $z$ and $w$ in $\C$.
We will sometimes denote it by $\int_{z}^{w} f$. (There is also a primed version, which is $1/(2\pi i)$ times the original.)
\end{definition}
%%-/
/-- A `RectangleIntegral` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`. -/
noncomputable def RectangleIntegral (f : ℂ → E) (z w : ℂ) : E := HIntegral f z.re w.re z.im -
HIntegral f z.re w.re w.im + VIntegral f w.re z.im w.im - VIntegral f z.re z.im w.im
/-- A `RectangleIntegral'` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`, divided by `2 * π * I`. -/
noncomputable abbrev RectangleIntegral' (f : ℂ → E) (z w : ℂ) : E :=
(1 / (2 * π * I)) • RectangleIntegral f z w
/-% ** Wrong delimiter on purpose **
An UpperUIntegral is the integral of a function over a |\_| shape.
\begin{definition}\label{UpperUIntegral}\lean{UpperUIntegral}\leanok
An UpperUIntegral of a function $f$ comes from $\sigma+i\infty$ down to $\sigma+iT$, over to $\sigma'+iT$, and back up to $\sigma'+i\infty$.
\end{definition}
%-/
noncomputable def UpperUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' T +
I • (∫ y : ℝ in Ici T, f (σ' + y * I)) - I • (∫ y : ℝ in Ici T, f (σ + y * I))
/-% ** Wrong delimiter on purpose **
A LowerUIntegral is the integral of a function over a |-| shape.
\begin{definition}[LowerUIntegral]\label{LowerUIntegral}\lean{LowerUIntegral}\leanok
A LowerUIntegral of a function $f$ comes from $\sigma-i\infty$ up to $\sigma-iT$, over to $\sigma'-iT$, and back down to $\sigma'-i\infty$.
\end{definition}
%-/
noncomputable def LowerUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' (-T) -
I • (∫ y : ℝ in Iic (-T), f (σ' + y * I)) + I • (∫ y : ℝ in Iic (-T), f (σ + y * I))
/-%%
It is very convenient to define integrals along vertical lines in the complex plane, as follows.
\begin{definition}[VerticalIntegral]\label{VerticalIntegral}\lean{VerticalIntegral}\leanok
Let $f$ be a function from $\mathbb{C}$ to $\mathbb{C}$, and let $\sigma$ be a real number. Then we define
$$\int_{(\sigma)}f(s)ds = \int_{\sigma-i\infty}^{\sigma+i\infty}f(s)ds.$$
\end{definition}
%%-/
noncomputable def VerticalIntegral (f : ℂ → E) (σ : ℝ) : E := I • ∫ t : ℝ, f (σ + t * I)
--%% We also have a version with a factor of $1/(2\pi i)$.
noncomputable abbrev VerticalIntegral' (f : ℂ → E) (σ : ℝ) : E :=
(1 / (2 * π * I)) • VerticalIntegral f σ
lemma verticalIntegral_split_three (a b : ℝ) (hf : Integrable (fun t : ℝ ↦ f (σ + t * I))) :
VerticalIntegral f σ = I • (∫ t in Iic a, f (σ + t * I)) + VIntegral f σ a b
+ I • ∫ t in Ici b, f (σ + t * I) := by
simp_rw [VerticalIntegral, VIntegral, ← smul_add]
congr
rw [← intervalIntegral.integral_Iic_sub_Iic hf.restrict hf.restrict, add_sub_cancel,
integral_Iic_eq_integral_Iio, intervalIntegral.integral_Iio_add_Ici hf.restrict hf.restrict]
/-% ** Wrong delimiter on purpose **
\begin{lemma}[DiffVertRect_eq_UpperLowerUs]\label{DiffVertRect_eq_UpperLowerUs}\lean{DiffVertRect_eq_UpperLowerUs}\leanok
The difference of two vertical integrals and a rectangle is the difference of an upper and a lower U integrals.
\end{lemma}
%-/
lemma DiffVertRect_eq_UpperLowerUs {σ σ' T : ℝ}
(f_int_σ : Integrable (fun (t : ℝ) ↦ f (σ + t * I)))
(f_int_σ' : Integrable (fun (t : ℝ) ↦ f (σ' + t * I))) :
(VerticalIntegral f σ') - (VerticalIntegral f σ) - (RectangleIntegral f (σ - I * T) (σ' + I * T)) =
(UpperUIntegral f σ σ' T) - (LowerUIntegral f σ σ' T) := by
rw [verticalIntegral_split_three (-T) T f_int_σ, verticalIntegral_split_three (-T) T f_int_σ']
simp only [smul_eq_mul, RectangleIntegral, sub_re, ofReal_re, mul_re, I_re, zero_mul, I_im,
ofReal_im, mul_zero, sub_self, sub_zero, add_re, add_zero, sub_im, mul_im, one_mul, zero_add,
zero_sub, add_im, UpperUIntegral, LowerUIntegral]
abel
/-%
\begin{proof}\uses{UpperUIntegral, LowerUIntegral}\leanok
Follows directly from the definitions.
\end{proof}
%-/
/-- A function is `HolomorphicOn` a set if it is complex differentiable on that set. -/
abbrev HolomorphicOn (f : ℂ → E) (s : Set ℂ) : Prop := DifferentiableOn ℂ f s
/-%%
\begin{theorem}[existsDifferentiableOn_of_bddAbove]\label{existsDifferentiableOn_of_bddAbove}\lean{existsDifferentiableOn_of_bddAbove}\leanok
If $f$ is differentiable on a set $s$ except at $c\in s$, and $f$ is bounded above on $s\setminus\{c\}$, then there exists a differentiable function $g$ on $s$ such that $f$ and $g$ agree on $s\setminus\{c\}$.
\end{theorem}
%%-/
theorem existsDifferentiableOn_of_bddAbove [CompleteSpace E] {s : Set ℂ} {c : ℂ} (hc : s ∈ nhds c)
(hd : HolomorphicOn f (s \ {c})) (hb : BddAbove (norm ∘ f '' (s \ {c}))) :
∃ (g : ℂ → E), HolomorphicOn g s ∧ (Set.EqOn f g (s \ {c})) :=
⟨Function.update f c (limUnder (𝓝[{c}ᶜ] c) f),
differentiableOn_update_limUnder_of_bddAbove hc hd hb,
fun z hz ↦ if h : z = c then (hz.2 h).elim else by simp [h]⟩
/-%%
\begin{proof}\leanok
This is the Riemann Removable Singularity Theorem, slightly rephrased from what's in Mathlib. (We don't care what the function $g$ is, just that it's holomorphic.)
\end{proof}
%%-/
/-%%
\begin{theorem}[HolomorphicOn.vanishesOnRectangle]\label{HolomorphicOn.vanishesOnRectangle}\lean{HolomorphicOn.vanishesOnRectangle}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$, then the integral of $f$ over the rectangle with corners $z$ and $w$ is $0$.
\end{theorem}
%%-/
theorem HolomorphicOn.vanishesOnRectangle [CompleteSpace E] {U : Set ℂ}
(f_holo : HolomorphicOn f U) (hU : Rectangle z w ⊆ U) :
RectangleIntegral f z w = 0 :=
integral_boundary_rect_eq_zero_of_differentiableOn f z w (f_holo.mono hU)
/-%%
\begin{proof}\leanok
This is in a Mathlib PR.
\end{proof}
%%-/
theorem RectangleIntegral_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral f z w = RectangleIntegral g z w := by
unfold RectangleIntegral VIntegral
congr 2; swap; congr 1; swap; congr 1
all_goals refine intervalIntegral.integral_congr fun _ _ ↦ h ?_
· exact Or.inl <| Or.inl <| Or.inl ⟨by simpa, by simp⟩
· exact Or.inl <| Or.inr ⟨by simpa, by simp⟩
· exact Or.inr ⟨by simp, by simpa⟩
· exact Or.inl <| Or.inl <| Or.inr ⟨by simp, by simpa⟩
theorem RectangleIntegral'_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral' f z w = RectangleIntegral' g z w := by
rw [RectangleIntegral', RectangleIntegral_congr h]
theorem rectangleIntegral_symm (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f z w = RectangleIntegral f w z := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, intervalIntegral.integral_symm w.re,
intervalIntegral.integral_symm w.im, sub_neg_eq_add, smul_neg, sub_neg_eq_add, ← sub_eq_add_neg,
neg_add_eq_sub, sub_add_eq_add_sub]
theorem rectangleIntegral_symm_re (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f (w.re + z.im * I) (z.re + w.im * I) = - RectangleIntegral f z w := by
simp [RectangleIntegral, ← sub_eq_zero]
rw [HIntegral_symm (y := z.im), HIntegral_symm (y := w.im)]
abel
def RectangleBorderIntegrable (f : ℂ → E) (z w : ℂ) : Prop :=
IntervalIntegrable (fun x => f (x + z.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun x => f (x + w.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun y => f (w.re + y * I)) volume z.im w.im ∧
IntervalIntegrable (fun y => f (z.re + y * I)) volume z.im w.im
theorem RectangleBorderIntegrable.add {f g : ℂ → E} (hf : RectangleBorderIntegrable f z w)
(hg : RectangleBorderIntegrable g z w) :
RectangleIntegral (f + g) z w = RectangleIntegral f z w + RectangleIntegral g z w := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
rw [intervalIntegral.integral_add hf.1 hg.1, intervalIntegral.integral_add hf.2.1 hg.2.1,
intervalIntegral.integral_add hf.2.2.1 hg.2.2.1, intervalIntegral.integral_add hf.2.2.2 hg.2.2.2]
rw [← sub_eq_zero]
simp only [smul_add]; abel
theorem ContinuousOn.rectangleBorder_integrable (hf : ContinuousOn f (RectangleBorder z w)) :
RectangleBorderIntegrable f z w :=
⟨(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_re z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_re z w)).intervalIntegrable⟩
theorem ContinuousOn.rectangleBorderIntegrable (hf : ContinuousOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
(hf.mono (rectangleBorder_subset_rectangle z w)).rectangleBorder_integrable
theorem ContinuousOn.rectangleBorderNoPIntegrable (hf : ContinuousOn f (Rectangle z w \ {p}))
(pNotOnBorder : p ∉ RectangleBorder z w) : RectangleBorderIntegrable f z w := by
refine (hf.mono (Set.subset_diff.mpr ?_)).rectangleBorder_integrable
exact ⟨rectangleBorder_subset_rectangle z w, disjoint_singleton_right.mpr pNotOnBorder⟩
theorem HolomorphicOn.rectangleBorderIntegrable' (hf : HolomorphicOn f (Rectangle z w \ {p}))
(hp : Rectangle z w ∈ nhds p) : RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderNoPIntegrable (not_mem_rectangleBorder_of_rectangle_mem_nhds hp)
theorem HolomorphicOn.rectangleBorderIntegrable (hf : HolomorphicOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderIntegrable
/--
Given `x₀ a x₁ : ℝ`, and `y₀ y₁ : ℝ` and a function `f : ℂ → ℂ` so that
both `(t : ℝ) ↦ f(t + y₀ * I)` and `(t : ℝ) ↦ f(t + y₁ * I)` are integrable over both
`t ∈ Icc x₀ a` and `t ∈ Icc a x₁`, we have that
`RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I)` is the sum of
`RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I)` and
`RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I)`.
-/
lemma RectangleIntegralHSplit {a x₀ x₁ y₀ y₁ : ℝ}
(f_int_x₀_a_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume x₀ a)
(f_int_a_x₁_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume a x₁)
(f_int_x₀_a_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume x₀ a)
(f_int_a_x₁_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume a x₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_bot f_int_a_x₁_bot,
← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_top f_int_a_x₁_top]
abel
lemma RectangleIntegralHSplit' {a x₀ x₁ y₀ y₁ : ℝ} (ha : a ∈ [[x₀, x₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) :=
RectangleIntegralHSplit
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
lemma RectangleIntegralVSplit {b x₀ x₁ y₀ y₁ : ℝ}
(f_int_y₀_b_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume y₀ b)
(f_int_b_y₁_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume b y₁)
(f_int_y₀_b_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume y₀ b)
(f_int_b_y₁_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume b y₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_left f_int_b_y₁_left,
← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_right f_int_b_y₁_right, ← sub_eq_zero]
simp only [smul_add]; abel
lemma RectangleIntegralVSplit' {b x₀ x₁ y₀ y₁ : ℝ} (hb : b ∈ [[y₀, y₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) :=
RectangleIntegralVSplit
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
lemma RectanglePullToNhdOfPole' [CompleteSpace E] {z₀ z₁ z₂ z₃ p : ℂ}
(h_orientation : z₀.re ≤ z₃.re ∧ z₀.im ≤ z₃.im ∧ z₁.re ≤ z₂.re ∧ z₁.im ≤ z₂.im)
(hp : Rectangle z₁ z₂ ∈ 𝓝 p) (hz : Rectangle z₁ z₂ ⊆ Rectangle z₀ z₃)
(fHolo : HolomorphicOn f (Rectangle z₀ z₃ \ {p})) :
RectangleIntegral f z₀ z₃ = RectangleIntegral f z₁ z₂ := by
obtain ⟨hz₀_re, hz₀_im, hz₁_re, hz₁_im⟩ := h_orientation
have := rect_subset_iff.mp hz
rw [Rectangle, uIcc_of_le hz₀_re, uIcc_of_le hz₀_im] at this
obtain ⟨⟨⟨_, _⟩, ⟨_, _⟩⟩, ⟨_, _⟩, ⟨_, _⟩⟩ := this
obtain ⟨⟨_, _⟩, ⟨_, _⟩⟩ := (uIoo_of_le hz₁_re) ▸ (uIoo_of_le hz₁_im) ▸ rectangle_mem_nhds_iff.mp hp
obtain ⟨_, _, _, _⟩ := show p.re < z₂.re ∧ p.re < z₃.re ∧ p.im < z₂.im ∧ p.im < z₃.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
obtain ⟨_, _, _, _⟩ := show z₀.re < p.re ∧ z₁.re < p.re ∧ z₀.im < p.im ∧ z₁.im < p.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
have fCont := fHolo.continuousOn
have hbot : RectangleBorderIntegrable f (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have htop : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have hleft : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
have hright : RectangleBorderIntegrable f (↑z₁.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
all_goals try {
refine (fCont.mono (rectangleBorder_subset_punctured_rect ?_ ?_)).rectangleBorder_integrable
· simp_all
· simpa using ⟨by linarith, by linarith, by linarith, by linarith⟩
}
have hbot' : z₁.im ∈ [[z₀.im, z₃.im]] := ?_
have htop' : z₂.im ∈ [[z₁.im, z₃.im]] := ?_
have hleft' : z₁.re ∈ [[z₀.re, z₃.re]] := ?_
have hright' : z₂.re ∈ [[z₁.re, z₃.re]] := ?_
all_goals try { rw [Set.uIcc_of_le]; constructor; all_goals assumption }
have hbot'' : Rectangle (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₁.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have htop'' : Rectangle (↑z₀.re + ↑z₂.im * I) (↑z₃.re + ↑z₃.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hleft'' : Rectangle (↑z₀.re + ↑z₁.im * I) (↑z₁.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hright'' : Rectangle (↑z₂.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
all_goals try { apply rectangle_subset_punctured_rect <;> simp_all }
rw [← re_add_im z₀, ← re_add_im z₃,
RectangleIntegralVSplit' hbot' hbot, fHolo.vanishesOnRectangle hbot'', zero_add,
RectangleIntegralVSplit' htop' htop, fHolo.vanishesOnRectangle htop'', add_zero,
RectangleIntegralHSplit' hleft' hleft, fHolo.vanishesOnRectangle hleft'', zero_add,
RectangleIntegralHSplit' hright' hright, fHolo.vanishesOnRectangle hright'', add_zero,
re_add_im, re_add_im]
/-%%
The next lemma allows to zoom a big rectangle down to a small square, centered at a pole.
\begin{lemma}[RectanglePullToNhdOfPole]\label{RectanglePullToNhdOfPole}\lean{RectanglePullToNhdOfPole}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$ except at a point $p$, then the integral of $f$
over the rectangle with corners $z$ and $w$ is the same as the integral of $f$ over a small square
centered at $p$.
\end{lemma}
%%-/
/-- Given `f` holomorphic on a rectangle `z` and `w` except at a point `p`, the integral of `f` over
the rectangle with corners `z` and `w` is the same as the integral of `f` over a small square
centered at `p`. -/
lemma RectanglePullToNhdOfPole [CompleteSpace E] {z w p : ℂ} (zRe_lt_wRe : z.re ≤ w.re)
(zIm_lt_wIm : z.im ≤ w.im) (hp : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral f z w = RectangleIntegral f (-c - I * c + p) (c + I * c + p) := by
/-%%
\begin{proof}\uses{HolomorphicOn.vanishesOnRectangle}\leanok
Chop the big rectangle with two vertical cuts and two horizontal cuts into smaller rectangles,
the middle one being the desired square. The integral over each of the outer rectangles
vanishes, since $f$ is holomorphic there. (The constant $c$ being ``small enough'' here just means
that the inner square is strictly contained in the big rectangle.)
%%-/
filter_upwards [Ioo_mem_nhdsWithin_Ioi' zero_lt_one, SmallSquareInRectangle hp]
intro c ⟨cpos, _⟩ hc
simp_rw [mul_comm I]
exact RectanglePullToNhdOfPole' (by simp_all [cpos.le])
(square_mem_nhds p (ne_of_gt cpos)) hc fHolo
--%%\end{proof}
lemma RectanglePullToNhdOfPole'' [CompleteSpace E] {z w p : ℂ} (zRe_le_wRe : z.re ≤ w.re)
(zIm_le_wIm : z.im ≤ w.im) (pInRectInterior : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral' f z w = RectangleIntegral' f (-c - I * c + p) (c + I * c + p) := by
filter_upwards [RectanglePullToNhdOfPole zRe_le_wRe zIm_le_wIm pInRectInterior fHolo] with c h
simp_rw [RectangleIntegral', h]
theorem ResidueTheoremAtOrigin_aux1c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y + I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux1c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y - I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (-1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem RectangleIntegral.const_smul (f : ℂ → E) (z w c : ℂ) :
RectangleIntegral (fun s => c • f s) z w = c • RectangleIntegral f z w := by
simp [RectangleIntegral, HIntegral, VIntegral, smul_add, smul_sub, smul_smul, mul_comm]
theorem RectangleIntegral.const_mul' (f : ℂ → E) (z w c : ℂ) :
RectangleIntegral' (fun s => c • f s) z w = c • RectangleIntegral' f z w := by
simp [RectangleIntegral', RectangleIntegral.const_smul, smul_smul] ; ring_nf
theorem RectangleIntegral.translate (f : ℂ → E) (z w p : ℂ) :
RectangleIntegral (fun s => f (s - p)) z w = RectangleIntegral f (z - p) (w - p) := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, sub_re, sub_im, ← intervalIntegral.integral_comp_sub_right]
congr <;> ext <;> congr 1 <;> simp [Complex.ext_iff]
theorem RectangleIntegral.translate' (f : ℂ → E) (z w p : ℂ) :
RectangleIntegral' (fun s => f (s - p)) z w = RectangleIntegral' f (z - p) (w - p) := by
simp_rw [RectangleIntegral', RectangleIntegral.translate]
lemma Complex.inv_re_add_im : (x + y * I)⁻¹ = (x - I * y) / (x ^ 2 + y ^ 2) := by
rw [Complex.inv_def, div_eq_mul_inv] ; congr <;> simp [conj_ofReal, normSq] <;> ring
| lemma sq_add_sq_ne_zero (hy : y ≠ 0) : x ^ 2 + y ^ 2 ≠ 0 | sq_add_sq_ne_zero | f36a520 20240122 | 1909a40 20240209 | PrimeNumberTheoremAnd/PrimeNumberTheoremAnd/ResidueCalcOnRectangles.lean | {
"lineInFile": 386,
"tokenPositionInFile": 21096,
"theoremPositionInFile": 44
} | {
"inFilePremises": false,
"repositoryPremises": false
} | {
"hasProof": true,
"proof": ":= by linarith [sq_nonneg x, (sq_pos_iff y).mpr hy]",
"proofType": "tactic",
"proofLengthLines": 0,
"proofLengthTokens": 51
} | prime |
import Mathlib.Analysis.Complex.CauchyIntegral
import Mathlib.Analysis.Complex.Convex
import Mathlib.Analysis.Complex.RemovableSingularity
import Mathlib.Analysis.Analytic.Meromorphic
import Mathlib.Analysis.SpecialFunctions.Integrals
import Mathlib.MeasureTheory.Measure.Lebesgue.Integral
import PrimeNumberTheoremAnd.Rectangle
open Complex BigOperators Nat Classical Real Topology Filter Set MeasureTheory intervalIntegral
open scoped Interval
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f g : ℂ → E}
{z w p c A : ℂ} {x x₁ x₂ y y₁ y₂ σ : ℝ}
noncomputable def HIntegral (f : ℂ → E) (x₁ x₂ y : ℝ) : E := ∫ x in x₁..x₂, f (x + y * I)
noncomputable def VIntegral (f : ℂ → E) (x y₁ y₂ : ℝ) : E := I • ∫ y in y₁..y₂, f (x + y * I)
noncomputable def HIntegral' (f : ℂ → E) (x₁ x₂ y : ℝ) : E := (1 / (2 * π * I)) • HIntegral f x₁ x₂ y
noncomputable def VIntegral' (f : ℂ → E) (x y₁ y₂ : ℝ) : E := (1 / (2 * π * I)) • VIntegral f x y₁ y₂
lemma HIntegral_symm : HIntegral f x₁ x₂ y = - HIntegral f x₂ x₁ y := integral_symm _ _
lemma VIntegral_symm : VIntegral f x y₁ y₂ = - VIntegral f x y₂ y₁ := by
simp_rw [VIntegral, integral_symm y₁ y₂, smul_neg, neg_neg]
/-%%
\begin{definition}[RectangleIntegral]\label{RectangleIntegral}\lean{RectangleIntegral}\leanok
A RectangleIntegral of a function $f$ is one over a rectangle determined by $z$ and $w$ in $\C$.
We will sometimes denote it by $\int_{z}^{w} f$. (There is also a primed version, which is $1/(2\pi i)$ times the original.)
\end{definition}
%%-/
/-- A `RectangleIntegral` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`. -/
noncomputable def RectangleIntegral (f : ℂ → E) (z w : ℂ) : E := HIntegral f z.re w.re z.im -
HIntegral f z.re w.re w.im + VIntegral f w.re z.im w.im - VIntegral f z.re z.im w.im
/-- A `RectangleIntegral'` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`, divided by `2 * π * I`. -/
noncomputable abbrev RectangleIntegral' (f : ℂ → E) (z w : ℂ) : E :=
(1 / (2 * π * I)) • RectangleIntegral f z w
/-% ** Wrong delimiter on purpose **
An UpperUIntegral is the integral of a function over a |\_| shape.
\begin{definition}\label{UpperUIntegral}\lean{UpperUIntegral}\leanok
An UpperUIntegral of a function $f$ comes from $\sigma+i\infty$ down to $\sigma+iT$, over to $\sigma'+iT$, and back up to $\sigma'+i\infty$.
\end{definition}
%-/
noncomputable def UpperUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' T +
I • (∫ y : ℝ in Ici T, f (σ' + y * I)) - I • (∫ y : ℝ in Ici T, f (σ + y * I))
/-% ** Wrong delimiter on purpose **
A LowerUIntegral is the integral of a function over a |-| shape.
\begin{definition}[LowerUIntegral]\label{LowerUIntegral}\lean{LowerUIntegral}\leanok
A LowerUIntegral of a function $f$ comes from $\sigma-i\infty$ up to $\sigma-iT$, over to $\sigma'-iT$, and back down to $\sigma'-i\infty$.
\end{definition}
%-/
noncomputable def LowerUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' (-T) -
I • (∫ y : ℝ in Iic (-T), f (σ' + y * I)) + I • (∫ y : ℝ in Iic (-T), f (σ + y * I))
/-%%
It is very convenient to define integrals along vertical lines in the complex plane, as follows.
\begin{definition}[VerticalIntegral]\label{VerticalIntegral}\lean{VerticalIntegral}\leanok
Let $f$ be a function from $\mathbb{C}$ to $\mathbb{C}$, and let $\sigma$ be a real number. Then we define
$$\int_{(\sigma)}f(s)ds = \int_{\sigma-i\infty}^{\sigma+i\infty}f(s)ds.$$
\end{definition}
%%-/
noncomputable def VerticalIntegral (f : ℂ → E) (σ : ℝ) : E := I • ∫ t : ℝ, f (σ + t * I)
--%% We also have a version with a factor of $1/(2\pi i)$.
noncomputable abbrev VerticalIntegral' (f : ℂ → E) (σ : ℝ) : E :=
(1 / (2 * π * I)) • VerticalIntegral f σ
lemma verticalIntegral_split_three (a b : ℝ) (hf : Integrable (fun t : ℝ ↦ f (σ + t * I))) :
VerticalIntegral f σ = I • (∫ t in Iic a, f (σ + t * I)) + VIntegral f σ a b
+ I • ∫ t in Ici b, f (σ + t * I) := by
simp_rw [VerticalIntegral, VIntegral, ← smul_add]
congr
rw [← intervalIntegral.integral_Iic_sub_Iic hf.restrict hf.restrict, add_sub_cancel,
integral_Iic_eq_integral_Iio, intervalIntegral.integral_Iio_add_Ici hf.restrict hf.restrict]
/-% ** Wrong delimiter on purpose **
\begin{lemma}[DiffVertRect_eq_UpperLowerUs]\label{DiffVertRect_eq_UpperLowerUs}\lean{DiffVertRect_eq_UpperLowerUs}\leanok
The difference of two vertical integrals and a rectangle is the difference of an upper and a lower U integrals.
\end{lemma}
%-/
lemma DiffVertRect_eq_UpperLowerUs {σ σ' T : ℝ}
(f_int_σ : Integrable (fun (t : ℝ) ↦ f (σ + t * I)))
(f_int_σ' : Integrable (fun (t : ℝ) ↦ f (σ' + t * I))) :
(VerticalIntegral f σ') - (VerticalIntegral f σ) - (RectangleIntegral f (σ - I * T) (σ' + I * T)) =
(UpperUIntegral f σ σ' T) - (LowerUIntegral f σ σ' T) := by
rw [verticalIntegral_split_three (-T) T f_int_σ, verticalIntegral_split_three (-T) T f_int_σ']
simp only [smul_eq_mul, RectangleIntegral, sub_re, ofReal_re, mul_re, I_re, zero_mul, I_im,
ofReal_im, mul_zero, sub_self, sub_zero, add_re, add_zero, sub_im, mul_im, one_mul, zero_add,
zero_sub, add_im, UpperUIntegral, LowerUIntegral]
abel
/-%
\begin{proof}\uses{UpperUIntegral, LowerUIntegral}\leanok
Follows directly from the definitions.
\end{proof}
%-/
/-- A function is `HolomorphicOn` a set if it is complex differentiable on that set. -/
abbrev HolomorphicOn (f : ℂ → E) (s : Set ℂ) : Prop := DifferentiableOn ℂ f s
/-%%
\begin{theorem}[existsDifferentiableOn_of_bddAbove]\label{existsDifferentiableOn_of_bddAbove}\lean{existsDifferentiableOn_of_bddAbove}\leanok
If $f$ is differentiable on a set $s$ except at $c\in s$, and $f$ is bounded above on $s\setminus\{c\}$, then there exists a differentiable function $g$ on $s$ such that $f$ and $g$ agree on $s\setminus\{c\}$.
\end{theorem}
%%-/
theorem existsDifferentiableOn_of_bddAbove [CompleteSpace E] {s : Set ℂ} {c : ℂ} (hc : s ∈ nhds c)
(hd : HolomorphicOn f (s \ {c})) (hb : BddAbove (norm ∘ f '' (s \ {c}))) :
∃ (g : ℂ → E), HolomorphicOn g s ∧ (Set.EqOn f g (s \ {c})) :=
⟨Function.update f c (limUnder (𝓝[{c}ᶜ] c) f),
differentiableOn_update_limUnder_of_bddAbove hc hd hb,
fun z hz ↦ if h : z = c then (hz.2 h).elim else by simp [h]⟩
/-%%
\begin{proof}\leanok
This is the Riemann Removable Singularity Theorem, slightly rephrased from what's in Mathlib. (We don't care what the function $g$ is, just that it's holomorphic.)
\end{proof}
%%-/
/-%%
\begin{theorem}[HolomorphicOn.vanishesOnRectangle]\label{HolomorphicOn.vanishesOnRectangle}\lean{HolomorphicOn.vanishesOnRectangle}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$, then the integral of $f$ over the rectangle with corners $z$ and $w$ is $0$.
\end{theorem}
%%-/
theorem HolomorphicOn.vanishesOnRectangle [CompleteSpace E] {U : Set ℂ}
(f_holo : HolomorphicOn f U) (hU : Rectangle z w ⊆ U) :
RectangleIntegral f z w = 0 :=
integral_boundary_rect_eq_zero_of_differentiableOn f z w (f_holo.mono hU)
/-%%
\begin{proof}\leanok
This is in a Mathlib PR.
\end{proof}
%%-/
theorem RectangleIntegral_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral f z w = RectangleIntegral g z w := by
unfold RectangleIntegral VIntegral
congr 2; swap; congr 1; swap; congr 1
all_goals refine intervalIntegral.integral_congr fun _ _ ↦ h ?_
· exact Or.inl <| Or.inl <| Or.inl ⟨by simpa, by simp⟩
· exact Or.inl <| Or.inr ⟨by simpa, by simp⟩
· exact Or.inr ⟨by simp, by simpa⟩
· exact Or.inl <| Or.inl <| Or.inr ⟨by simp, by simpa⟩
theorem RectangleIntegral'_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral' f z w = RectangleIntegral' g z w := by
rw [RectangleIntegral', RectangleIntegral_congr h]
theorem rectangleIntegral_symm (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f z w = RectangleIntegral f w z := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, intervalIntegral.integral_symm w.re,
intervalIntegral.integral_symm w.im, sub_neg_eq_add, smul_neg, sub_neg_eq_add, ← sub_eq_add_neg,
neg_add_eq_sub, sub_add_eq_add_sub]
theorem rectangleIntegral_symm_re (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f (w.re + z.im * I) (z.re + w.im * I) = - RectangleIntegral f z w := by
simp [RectangleIntegral, ← sub_eq_zero]
rw [HIntegral_symm (y := z.im), HIntegral_symm (y := w.im)]
abel
def RectangleBorderIntegrable (f : ℂ → E) (z w : ℂ) : Prop :=
IntervalIntegrable (fun x => f (x + z.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun x => f (x + w.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun y => f (w.re + y * I)) volume z.im w.im ∧
IntervalIntegrable (fun y => f (z.re + y * I)) volume z.im w.im
theorem RectangleBorderIntegrable.add {f g : ℂ → E} (hf : RectangleBorderIntegrable f z w)
(hg : RectangleBorderIntegrable g z w) :
RectangleIntegral (f + g) z w = RectangleIntegral f z w + RectangleIntegral g z w := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
rw [intervalIntegral.integral_add hf.1 hg.1, intervalIntegral.integral_add hf.2.1 hg.2.1,
intervalIntegral.integral_add hf.2.2.1 hg.2.2.1, intervalIntegral.integral_add hf.2.2.2 hg.2.2.2]
rw [← sub_eq_zero]
simp only [smul_add]; abel
theorem ContinuousOn.rectangleBorder_integrable (hf : ContinuousOn f (RectangleBorder z w)) :
RectangleBorderIntegrable f z w :=
⟨(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_re z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_re z w)).intervalIntegrable⟩
theorem ContinuousOn.rectangleBorderIntegrable (hf : ContinuousOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
(hf.mono (rectangleBorder_subset_rectangle z w)).rectangleBorder_integrable
theorem ContinuousOn.rectangleBorderNoPIntegrable (hf : ContinuousOn f (Rectangle z w \ {p}))
(pNotOnBorder : p ∉ RectangleBorder z w) : RectangleBorderIntegrable f z w := by
refine (hf.mono (Set.subset_diff.mpr ?_)).rectangleBorder_integrable
exact ⟨rectangleBorder_subset_rectangle z w, disjoint_singleton_right.mpr pNotOnBorder⟩
theorem HolomorphicOn.rectangleBorderIntegrable' (hf : HolomorphicOn f (Rectangle z w \ {p}))
(hp : Rectangle z w ∈ nhds p) : RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderNoPIntegrable (not_mem_rectangleBorder_of_rectangle_mem_nhds hp)
theorem HolomorphicOn.rectangleBorderIntegrable (hf : HolomorphicOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderIntegrable
/--
Given `x₀ a x₁ : ℝ`, and `y₀ y₁ : ℝ` and a function `f : ℂ → ℂ` so that
both `(t : ℝ) ↦ f(t + y₀ * I)` and `(t : ℝ) ↦ f(t + y₁ * I)` are integrable over both
`t ∈ Icc x₀ a` and `t ∈ Icc a x₁`, we have that
`RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I)` is the sum of
`RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I)` and
`RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I)`.
-/
lemma RectangleIntegralHSplit {a x₀ x₁ y₀ y₁ : ℝ}
(f_int_x₀_a_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume x₀ a)
(f_int_a_x₁_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume a x₁)
(f_int_x₀_a_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume x₀ a)
(f_int_a_x₁_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume a x₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_bot f_int_a_x₁_bot,
← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_top f_int_a_x₁_top]
abel
lemma RectangleIntegralHSplit' {a x₀ x₁ y₀ y₁ : ℝ} (ha : a ∈ [[x₀, x₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) :=
RectangleIntegralHSplit
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
lemma RectangleIntegralVSplit {b x₀ x₁ y₀ y₁ : ℝ}
(f_int_y₀_b_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume y₀ b)
(f_int_b_y₁_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume b y₁)
(f_int_y₀_b_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume y₀ b)
(f_int_b_y₁_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume b y₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_left f_int_b_y₁_left,
← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_right f_int_b_y₁_right, ← sub_eq_zero]
simp only [smul_add]; abel
lemma RectangleIntegralVSplit' {b x₀ x₁ y₀ y₁ : ℝ} (hb : b ∈ [[y₀, y₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) :=
RectangleIntegralVSplit
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
lemma RectanglePullToNhdOfPole' [CompleteSpace E] {z₀ z₁ z₂ z₃ p : ℂ}
(h_orientation : z₀.re ≤ z₃.re ∧ z₀.im ≤ z₃.im ∧ z₁.re ≤ z₂.re ∧ z₁.im ≤ z₂.im)
(hp : Rectangle z₁ z₂ ∈ 𝓝 p) (hz : Rectangle z₁ z₂ ⊆ Rectangle z₀ z₃)
(fHolo : HolomorphicOn f (Rectangle z₀ z₃ \ {p})) :
RectangleIntegral f z₀ z₃ = RectangleIntegral f z₁ z₂ := by
obtain ⟨hz₀_re, hz₀_im, hz₁_re, hz₁_im⟩ := h_orientation
have := rect_subset_iff.mp hz
rw [Rectangle, uIcc_of_le hz₀_re, uIcc_of_le hz₀_im] at this
obtain ⟨⟨⟨_, _⟩, ⟨_, _⟩⟩, ⟨_, _⟩, ⟨_, _⟩⟩ := this
obtain ⟨⟨_, _⟩, ⟨_, _⟩⟩ := (uIoo_of_le hz₁_re) ▸ (uIoo_of_le hz₁_im) ▸ rectangle_mem_nhds_iff.mp hp
obtain ⟨_, _, _, _⟩ := show p.re < z₂.re ∧ p.re < z₃.re ∧ p.im < z₂.im ∧ p.im < z₃.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
obtain ⟨_, _, _, _⟩ := show z₀.re < p.re ∧ z₁.re < p.re ∧ z₀.im < p.im ∧ z₁.im < p.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
have fCont := fHolo.continuousOn
have hbot : RectangleBorderIntegrable f (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have htop : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have hleft : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
have hright : RectangleBorderIntegrable f (↑z₁.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
all_goals try {
refine (fCont.mono (rectangleBorder_subset_punctured_rect ?_ ?_)).rectangleBorder_integrable
· simp_all
· simpa using ⟨by linarith, by linarith, by linarith, by linarith⟩
}
have hbot' : z₁.im ∈ [[z₀.im, z₃.im]] := ?_
have htop' : z₂.im ∈ [[z₁.im, z₃.im]] := ?_
have hleft' : z₁.re ∈ [[z₀.re, z₃.re]] := ?_
have hright' : z₂.re ∈ [[z₁.re, z₃.re]] := ?_
all_goals try { rw [Set.uIcc_of_le]; constructor; all_goals assumption }
have hbot'' : Rectangle (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₁.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have htop'' : Rectangle (↑z₀.re + ↑z₂.im * I) (↑z₃.re + ↑z₃.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hleft'' : Rectangle (↑z₀.re + ↑z₁.im * I) (↑z₁.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hright'' : Rectangle (↑z₂.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
all_goals try { apply rectangle_subset_punctured_rect <;> simp_all }
rw [← re_add_im z₀, ← re_add_im z₃,
RectangleIntegralVSplit' hbot' hbot, fHolo.vanishesOnRectangle hbot'', zero_add,
RectangleIntegralVSplit' htop' htop, fHolo.vanishesOnRectangle htop'', add_zero,
RectangleIntegralHSplit' hleft' hleft, fHolo.vanishesOnRectangle hleft'', zero_add,
RectangleIntegralHSplit' hright' hright, fHolo.vanishesOnRectangle hright'', add_zero,
re_add_im, re_add_im]
/-%%
The next lemma allows to zoom a big rectangle down to a small square, centered at a pole.
\begin{lemma}[RectanglePullToNhdOfPole]\label{RectanglePullToNhdOfPole}\lean{RectanglePullToNhdOfPole}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$ except at a point $p$, then the integral of $f$
over the rectangle with corners $z$ and $w$ is the same as the integral of $f$ over a small square
centered at $p$.
\end{lemma}
%%-/
/-- Given `f` holomorphic on a rectangle `z` and `w` except at a point `p`, the integral of `f` over
the rectangle with corners `z` and `w` is the same as the integral of `f` over a small square
centered at `p`. -/
lemma RectanglePullToNhdOfPole [CompleteSpace E] {z w p : ℂ} (zRe_lt_wRe : z.re ≤ w.re)
(zIm_lt_wIm : z.im ≤ w.im) (hp : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral f z w = RectangleIntegral f (-c - I * c + p) (c + I * c + p) := by
/-%%
\begin{proof}\uses{HolomorphicOn.vanishesOnRectangle}\leanok
Chop the big rectangle with two vertical cuts and two horizontal cuts into smaller rectangles,
the middle one being the desired square. The integral over each of the outer rectangles
vanishes, since $f$ is holomorphic there. (The constant $c$ being ``small enough'' here just means
that the inner square is strictly contained in the big rectangle.)
%%-/
filter_upwards [Ioo_mem_nhdsWithin_Ioi' zero_lt_one, SmallSquareInRectangle hp]
intro c ⟨cpos, _⟩ hc
simp_rw [mul_comm I]
exact RectanglePullToNhdOfPole' (by simp_all [cpos.le])
(square_mem_nhds p (ne_of_gt cpos)) hc fHolo
--%%\end{proof}
lemma RectanglePullToNhdOfPole'' [CompleteSpace E] {z w p : ℂ} (zRe_le_wRe : z.re ≤ w.re)
(zIm_le_wIm : z.im ≤ w.im) (pInRectInterior : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral' f z w = RectangleIntegral' f (-c - I * c + p) (c + I * c + p) := by
filter_upwards [RectanglePullToNhdOfPole zRe_le_wRe zIm_le_wIm pInRectInterior fHolo] with c h
simp_rw [RectangleIntegral', h]
theorem ResidueTheoremAtOrigin_aux1c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y + I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux1c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y - I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (-1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem RectangleIntegral.const_smul (f : ℂ → E) (z w c : ℂ) :
RectangleIntegral (fun s => c • f s) z w = c • RectangleIntegral f z w := by
simp [RectangleIntegral, HIntegral, VIntegral, smul_add, smul_sub, smul_smul, mul_comm]
theorem RectangleIntegral.const_mul' (f : ℂ → E) (z w c : ℂ) :
RectangleIntegral' (fun s => c • f s) z w = c • RectangleIntegral' f z w := by
simp [RectangleIntegral', RectangleIntegral.const_smul, smul_smul] ; ring_nf
theorem RectangleIntegral.translate (f : ℂ → E) (z w p : ℂ) :
RectangleIntegral (fun s => f (s - p)) z w = RectangleIntegral f (z - p) (w - p) := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, sub_re, sub_im, ← intervalIntegral.integral_comp_sub_right]
congr <;> ext <;> congr 1 <;> simp [Complex.ext_iff]
theorem RectangleIntegral.translate' (f : ℂ → E) (z w p : ℂ) :
RectangleIntegral' (fun s => f (s - p)) z w = RectangleIntegral' f (z - p) (w - p) := by
simp_rw [RectangleIntegral', RectangleIntegral.translate]
lemma Complex.inv_re_add_im : (x + y * I)⁻¹ = (x - I * y) / (x ^ 2 + y ^ 2) := by
rw [Complex.inv_def, div_eq_mul_inv] ; congr <;> simp [conj_ofReal, normSq] <;> ring
lemma sq_add_sq_ne_zero (hy : y ≠ 0) : x ^ 2 + y ^ 2 ≠ 0 := by linarith [sq_nonneg x, (sq_pos_iff y).mpr hy]
| lemma continuous_self_div_sq_add_sq (hy : y ≠ 0) : Continuous fun x => x / (x ^ 2 + y ^ 2) | continuous_self_div_sq_add_sq | f36a520 20240122 | 1909a40 20240209 | PrimeNumberTheoremAnd/PrimeNumberTheoremAnd/ResidueCalcOnRectangles.lean | {
"lineInFile": 388,
"tokenPositionInFile": 21206,
"theoremPositionInFile": 45
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": ":=\n continuous_id.div (continuous_id.pow 2 |>.add continuous_const) (λ _ => sq_add_sq_ne_zero hy)",
"proofType": "term",
"proofLengthLines": 1,
"proofLengthTokens": 98
} | prime |
import Mathlib.Analysis.Complex.CauchyIntegral
import Mathlib.Analysis.Complex.Convex
import Mathlib.Analysis.Complex.RemovableSingularity
import Mathlib.Analysis.Analytic.Meromorphic
import Mathlib.Analysis.SpecialFunctions.Integrals
import Mathlib.MeasureTheory.Measure.Lebesgue.Integral
import PrimeNumberTheoremAnd.Rectangle
open Complex BigOperators Nat Classical Real Topology Filter Set MeasureTheory intervalIntegral
open scoped Interval
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f g : ℂ → E}
{z w p c A : ℂ} {x x₁ x₂ y y₁ y₂ σ : ℝ}
noncomputable def HIntegral (f : ℂ → E) (x₁ x₂ y : ℝ) : E := ∫ x in x₁..x₂, f (x + y * I)
noncomputable def VIntegral (f : ℂ → E) (x y₁ y₂ : ℝ) : E := I • ∫ y in y₁..y₂, f (x + y * I)
noncomputable def HIntegral' (f : ℂ → E) (x₁ x₂ y : ℝ) : E := (1 / (2 * π * I)) • HIntegral f x₁ x₂ y
noncomputable def VIntegral' (f : ℂ → E) (x y₁ y₂ : ℝ) : E := (1 / (2 * π * I)) • VIntegral f x y₁ y₂
lemma HIntegral_symm : HIntegral f x₁ x₂ y = - HIntegral f x₂ x₁ y := integral_symm _ _
lemma VIntegral_symm : VIntegral f x y₁ y₂ = - VIntegral f x y₂ y₁ := by
simp_rw [VIntegral, integral_symm y₁ y₂, smul_neg, neg_neg]
/-%%
\begin{definition}[RectangleIntegral]\label{RectangleIntegral}\lean{RectangleIntegral}\leanok
A RectangleIntegral of a function $f$ is one over a rectangle determined by $z$ and $w$ in $\C$.
We will sometimes denote it by $\int_{z}^{w} f$. (There is also a primed version, which is $1/(2\pi i)$ times the original.)
\end{definition}
%%-/
/-- A `RectangleIntegral` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`. -/
noncomputable def RectangleIntegral (f : ℂ → E) (z w : ℂ) : E := HIntegral f z.re w.re z.im -
HIntegral f z.re w.re w.im + VIntegral f w.re z.im w.im - VIntegral f z.re z.im w.im
/-- A `RectangleIntegral'` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`, divided by `2 * π * I`. -/
noncomputable abbrev RectangleIntegral' (f : ℂ → E) (z w : ℂ) : E :=
(1 / (2 * π * I)) • RectangleIntegral f z w
/-% ** Wrong delimiter on purpose **
An UpperUIntegral is the integral of a function over a |\_| shape.
\begin{definition}\label{UpperUIntegral}\lean{UpperUIntegral}\leanok
An UpperUIntegral of a function $f$ comes from $\sigma+i\infty$ down to $\sigma+iT$, over to $\sigma'+iT$, and back up to $\sigma'+i\infty$.
\end{definition}
%-/
noncomputable def UpperUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' T +
I • (∫ y : ℝ in Ici T, f (σ' + y * I)) - I • (∫ y : ℝ in Ici T, f (σ + y * I))
/-% ** Wrong delimiter on purpose **
A LowerUIntegral is the integral of a function over a |-| shape.
\begin{definition}[LowerUIntegral]\label{LowerUIntegral}\lean{LowerUIntegral}\leanok
A LowerUIntegral of a function $f$ comes from $\sigma-i\infty$ up to $\sigma-iT$, over to $\sigma'-iT$, and back down to $\sigma'-i\infty$.
\end{definition}
%-/
noncomputable def LowerUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' (-T) -
I • (∫ y : ℝ in Iic (-T), f (σ' + y * I)) + I • (∫ y : ℝ in Iic (-T), f (σ + y * I))
/-%%
It is very convenient to define integrals along vertical lines in the complex plane, as follows.
\begin{definition}[VerticalIntegral]\label{VerticalIntegral}\lean{VerticalIntegral}\leanok
Let $f$ be a function from $\mathbb{C}$ to $\mathbb{C}$, and let $\sigma$ be a real number. Then we define
$$\int_{(\sigma)}f(s)ds = \int_{\sigma-i\infty}^{\sigma+i\infty}f(s)ds.$$
\end{definition}
%%-/
noncomputable def VerticalIntegral (f : ℂ → E) (σ : ℝ) : E := I • ∫ t : ℝ, f (σ + t * I)
--%% We also have a version with a factor of $1/(2\pi i)$.
noncomputable abbrev VerticalIntegral' (f : ℂ → E) (σ : ℝ) : E :=
(1 / (2 * π * I)) • VerticalIntegral f σ
lemma verticalIntegral_split_three (a b : ℝ) (hf : Integrable (fun t : ℝ ↦ f (σ + t * I))) :
VerticalIntegral f σ = I • (∫ t in Iic a, f (σ + t * I)) + VIntegral f σ a b
+ I • ∫ t in Ici b, f (σ + t * I) := by
simp_rw [VerticalIntegral, VIntegral, ← smul_add]
congr
rw [← intervalIntegral.integral_Iic_sub_Iic hf.restrict hf.restrict, add_sub_cancel,
integral_Iic_eq_integral_Iio, intervalIntegral.integral_Iio_add_Ici hf.restrict hf.restrict]
/-% ** Wrong delimiter on purpose **
\begin{lemma}[DiffVertRect_eq_UpperLowerUs]\label{DiffVertRect_eq_UpperLowerUs}\lean{DiffVertRect_eq_UpperLowerUs}\leanok
The difference of two vertical integrals and a rectangle is the difference of an upper and a lower U integrals.
\end{lemma}
%-/
lemma DiffVertRect_eq_UpperLowerUs {σ σ' T : ℝ}
(f_int_σ : Integrable (fun (t : ℝ) ↦ f (σ + t * I)))
(f_int_σ' : Integrable (fun (t : ℝ) ↦ f (σ' + t * I))) :
(VerticalIntegral f σ') - (VerticalIntegral f σ) - (RectangleIntegral f (σ - I * T) (σ' + I * T)) =
(UpperUIntegral f σ σ' T) - (LowerUIntegral f σ σ' T) := by
rw [verticalIntegral_split_three (-T) T f_int_σ, verticalIntegral_split_three (-T) T f_int_σ']
simp only [smul_eq_mul, RectangleIntegral, sub_re, ofReal_re, mul_re, I_re, zero_mul, I_im,
ofReal_im, mul_zero, sub_self, sub_zero, add_re, add_zero, sub_im, mul_im, one_mul, zero_add,
zero_sub, add_im, UpperUIntegral, LowerUIntegral]
abel
/-%
\begin{proof}\uses{UpperUIntegral, LowerUIntegral}\leanok
Follows directly from the definitions.
\end{proof}
%-/
/-- A function is `HolomorphicOn` a set if it is complex differentiable on that set. -/
abbrev HolomorphicOn (f : ℂ → E) (s : Set ℂ) : Prop := DifferentiableOn ℂ f s
/-%%
\begin{theorem}[existsDifferentiableOn_of_bddAbove]\label{existsDifferentiableOn_of_bddAbove}\lean{existsDifferentiableOn_of_bddAbove}\leanok
If $f$ is differentiable on a set $s$ except at $c\in s$, and $f$ is bounded above on $s\setminus\{c\}$, then there exists a differentiable function $g$ on $s$ such that $f$ and $g$ agree on $s\setminus\{c\}$.
\end{theorem}
%%-/
theorem existsDifferentiableOn_of_bddAbove [CompleteSpace E] {s : Set ℂ} {c : ℂ} (hc : s ∈ nhds c)
(hd : HolomorphicOn f (s \ {c})) (hb : BddAbove (norm ∘ f '' (s \ {c}))) :
∃ (g : ℂ → E), HolomorphicOn g s ∧ (Set.EqOn f g (s \ {c})) :=
⟨Function.update f c (limUnder (𝓝[{c}ᶜ] c) f),
differentiableOn_update_limUnder_of_bddAbove hc hd hb,
fun z hz ↦ if h : z = c then (hz.2 h).elim else by simp [h]⟩
/-%%
\begin{proof}\leanok
This is the Riemann Removable Singularity Theorem, slightly rephrased from what's in Mathlib. (We don't care what the function $g$ is, just that it's holomorphic.)
\end{proof}
%%-/
/-%%
\begin{theorem}[HolomorphicOn.vanishesOnRectangle]\label{HolomorphicOn.vanishesOnRectangle}\lean{HolomorphicOn.vanishesOnRectangle}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$, then the integral of $f$ over the rectangle with corners $z$ and $w$ is $0$.
\end{theorem}
%%-/
theorem HolomorphicOn.vanishesOnRectangle [CompleteSpace E] {U : Set ℂ}
(f_holo : HolomorphicOn f U) (hU : Rectangle z w ⊆ U) :
RectangleIntegral f z w = 0 :=
integral_boundary_rect_eq_zero_of_differentiableOn f z w (f_holo.mono hU)
/-%%
\begin{proof}\leanok
This is in a Mathlib PR.
\end{proof}
%%-/
theorem RectangleIntegral_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral f z w = RectangleIntegral g z w := by
unfold RectangleIntegral VIntegral
congr 2; swap; congr 1; swap; congr 1
all_goals refine intervalIntegral.integral_congr fun _ _ ↦ h ?_
· exact Or.inl <| Or.inl <| Or.inl ⟨by simpa, by simp⟩
· exact Or.inl <| Or.inr ⟨by simpa, by simp⟩
· exact Or.inr ⟨by simp, by simpa⟩
· exact Or.inl <| Or.inl <| Or.inr ⟨by simp, by simpa⟩
theorem RectangleIntegral'_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral' f z w = RectangleIntegral' g z w := by
rw [RectangleIntegral', RectangleIntegral_congr h]
theorem rectangleIntegral_symm (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f z w = RectangleIntegral f w z := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, intervalIntegral.integral_symm w.re,
intervalIntegral.integral_symm w.im, sub_neg_eq_add, smul_neg, sub_neg_eq_add, ← sub_eq_add_neg,
neg_add_eq_sub, sub_add_eq_add_sub]
theorem rectangleIntegral_symm_re (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f (w.re + z.im * I) (z.re + w.im * I) = - RectangleIntegral f z w := by
simp [RectangleIntegral, ← sub_eq_zero]
rw [HIntegral_symm (y := z.im), HIntegral_symm (y := w.im)]
abel
def RectangleBorderIntegrable (f : ℂ → E) (z w : ℂ) : Prop :=
IntervalIntegrable (fun x => f (x + z.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun x => f (x + w.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun y => f (w.re + y * I)) volume z.im w.im ∧
IntervalIntegrable (fun y => f (z.re + y * I)) volume z.im w.im
theorem RectangleBorderIntegrable.add {f g : ℂ → E} (hf : RectangleBorderIntegrable f z w)
(hg : RectangleBorderIntegrable g z w) :
RectangleIntegral (f + g) z w = RectangleIntegral f z w + RectangleIntegral g z w := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
rw [intervalIntegral.integral_add hf.1 hg.1, intervalIntegral.integral_add hf.2.1 hg.2.1,
intervalIntegral.integral_add hf.2.2.1 hg.2.2.1, intervalIntegral.integral_add hf.2.2.2 hg.2.2.2]
rw [← sub_eq_zero]
simp only [smul_add]; abel
theorem ContinuousOn.rectangleBorder_integrable (hf : ContinuousOn f (RectangleBorder z w)) :
RectangleBorderIntegrable f z w :=
⟨(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_re z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_re z w)).intervalIntegrable⟩
theorem ContinuousOn.rectangleBorderIntegrable (hf : ContinuousOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
(hf.mono (rectangleBorder_subset_rectangle z w)).rectangleBorder_integrable
theorem ContinuousOn.rectangleBorderNoPIntegrable (hf : ContinuousOn f (Rectangle z w \ {p}))
(pNotOnBorder : p ∉ RectangleBorder z w) : RectangleBorderIntegrable f z w := by
refine (hf.mono (Set.subset_diff.mpr ?_)).rectangleBorder_integrable
exact ⟨rectangleBorder_subset_rectangle z w, disjoint_singleton_right.mpr pNotOnBorder⟩
theorem HolomorphicOn.rectangleBorderIntegrable' (hf : HolomorphicOn f (Rectangle z w \ {p}))
(hp : Rectangle z w ∈ nhds p) : RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderNoPIntegrable (not_mem_rectangleBorder_of_rectangle_mem_nhds hp)
theorem HolomorphicOn.rectangleBorderIntegrable (hf : HolomorphicOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderIntegrable
/--
Given `x₀ a x₁ : ℝ`, and `y₀ y₁ : ℝ` and a function `f : ℂ → ℂ` so that
both `(t : ℝ) ↦ f(t + y₀ * I)` and `(t : ℝ) ↦ f(t + y₁ * I)` are integrable over both
`t ∈ Icc x₀ a` and `t ∈ Icc a x₁`, we have that
`RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I)` is the sum of
`RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I)` and
`RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I)`.
-/
lemma RectangleIntegralHSplit {a x₀ x₁ y₀ y₁ : ℝ}
(f_int_x₀_a_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume x₀ a)
(f_int_a_x₁_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume a x₁)
(f_int_x₀_a_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume x₀ a)
(f_int_a_x₁_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume a x₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_bot f_int_a_x₁_bot,
← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_top f_int_a_x₁_top]
abel
lemma RectangleIntegralHSplit' {a x₀ x₁ y₀ y₁ : ℝ} (ha : a ∈ [[x₀, x₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) :=
RectangleIntegralHSplit
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
lemma RectangleIntegralVSplit {b x₀ x₁ y₀ y₁ : ℝ}
(f_int_y₀_b_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume y₀ b)
(f_int_b_y₁_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume b y₁)
(f_int_y₀_b_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume y₀ b)
(f_int_b_y₁_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume b y₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_left f_int_b_y₁_left,
← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_right f_int_b_y₁_right, ← sub_eq_zero]
simp only [smul_add]; abel
lemma RectangleIntegralVSplit' {b x₀ x₁ y₀ y₁ : ℝ} (hb : b ∈ [[y₀, y₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) :=
RectangleIntegralVSplit
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
lemma RectanglePullToNhdOfPole' [CompleteSpace E] {z₀ z₁ z₂ z₃ p : ℂ}
(h_orientation : z₀.re ≤ z₃.re ∧ z₀.im ≤ z₃.im ∧ z₁.re ≤ z₂.re ∧ z₁.im ≤ z₂.im)
(hp : Rectangle z₁ z₂ ∈ 𝓝 p) (hz : Rectangle z₁ z₂ ⊆ Rectangle z₀ z₃)
(fHolo : HolomorphicOn f (Rectangle z₀ z₃ \ {p})) :
RectangleIntegral f z₀ z₃ = RectangleIntegral f z₁ z₂ := by
obtain ⟨hz₀_re, hz₀_im, hz₁_re, hz₁_im⟩ := h_orientation
have := rect_subset_iff.mp hz
rw [Rectangle, uIcc_of_le hz₀_re, uIcc_of_le hz₀_im] at this
obtain ⟨⟨⟨_, _⟩, ⟨_, _⟩⟩, ⟨_, _⟩, ⟨_, _⟩⟩ := this
obtain ⟨⟨_, _⟩, ⟨_, _⟩⟩ := (uIoo_of_le hz₁_re) ▸ (uIoo_of_le hz₁_im) ▸ rectangle_mem_nhds_iff.mp hp
obtain ⟨_, _, _, _⟩ := show p.re < z₂.re ∧ p.re < z₃.re ∧ p.im < z₂.im ∧ p.im < z₃.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
obtain ⟨_, _, _, _⟩ := show z₀.re < p.re ∧ z₁.re < p.re ∧ z₀.im < p.im ∧ z₁.im < p.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
have fCont := fHolo.continuousOn
have hbot : RectangleBorderIntegrable f (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have htop : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have hleft : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
have hright : RectangleBorderIntegrable f (↑z₁.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
all_goals try {
refine (fCont.mono (rectangleBorder_subset_punctured_rect ?_ ?_)).rectangleBorder_integrable
· simp_all
· simpa using ⟨by linarith, by linarith, by linarith, by linarith⟩
}
have hbot' : z₁.im ∈ [[z₀.im, z₃.im]] := ?_
have htop' : z₂.im ∈ [[z₁.im, z₃.im]] := ?_
have hleft' : z₁.re ∈ [[z₀.re, z₃.re]] := ?_
have hright' : z₂.re ∈ [[z₁.re, z₃.re]] := ?_
all_goals try { rw [Set.uIcc_of_le]; constructor; all_goals assumption }
have hbot'' : Rectangle (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₁.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have htop'' : Rectangle (↑z₀.re + ↑z₂.im * I) (↑z₃.re + ↑z₃.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hleft'' : Rectangle (↑z₀.re + ↑z₁.im * I) (↑z₁.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hright'' : Rectangle (↑z₂.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
all_goals try { apply rectangle_subset_punctured_rect <;> simp_all }
rw [← re_add_im z₀, ← re_add_im z₃,
RectangleIntegralVSplit' hbot' hbot, fHolo.vanishesOnRectangle hbot'', zero_add,
RectangleIntegralVSplit' htop' htop, fHolo.vanishesOnRectangle htop'', add_zero,
RectangleIntegralHSplit' hleft' hleft, fHolo.vanishesOnRectangle hleft'', zero_add,
RectangleIntegralHSplit' hright' hright, fHolo.vanishesOnRectangle hright'', add_zero,
re_add_im, re_add_im]
/-%%
The next lemma allows to zoom a big rectangle down to a small square, centered at a pole.
\begin{lemma}[RectanglePullToNhdOfPole]\label{RectanglePullToNhdOfPole}\lean{RectanglePullToNhdOfPole}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$ except at a point $p$, then the integral of $f$
over the rectangle with corners $z$ and $w$ is the same as the integral of $f$ over a small square
centered at $p$.
\end{lemma}
%%-/
/-- Given `f` holomorphic on a rectangle `z` and `w` except at a point `p`, the integral of `f` over
the rectangle with corners `z` and `w` is the same as the integral of `f` over a small square
centered at `p`. -/
lemma RectanglePullToNhdOfPole [CompleteSpace E] {z w p : ℂ} (zRe_lt_wRe : z.re ≤ w.re)
(zIm_lt_wIm : z.im ≤ w.im) (hp : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral f z w = RectangleIntegral f (-c - I * c + p) (c + I * c + p) := by
/-%%
\begin{proof}\uses{HolomorphicOn.vanishesOnRectangle}\leanok
Chop the big rectangle with two vertical cuts and two horizontal cuts into smaller rectangles,
the middle one being the desired square. The integral over each of the outer rectangles
vanishes, since $f$ is holomorphic there. (The constant $c$ being ``small enough'' here just means
that the inner square is strictly contained in the big rectangle.)
%%-/
filter_upwards [Ioo_mem_nhdsWithin_Ioi' zero_lt_one, SmallSquareInRectangle hp]
intro c ⟨cpos, _⟩ hc
simp_rw [mul_comm I]
exact RectanglePullToNhdOfPole' (by simp_all [cpos.le])
(square_mem_nhds p (ne_of_gt cpos)) hc fHolo
--%%\end{proof}
lemma RectanglePullToNhdOfPole'' [CompleteSpace E] {z w p : ℂ} (zRe_le_wRe : z.re ≤ w.re)
(zIm_le_wIm : z.im ≤ w.im) (pInRectInterior : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral' f z w = RectangleIntegral' f (-c - I * c + p) (c + I * c + p) := by
filter_upwards [RectanglePullToNhdOfPole zRe_le_wRe zIm_le_wIm pInRectInterior fHolo] with c h
simp_rw [RectangleIntegral', h]
theorem ResidueTheoremAtOrigin_aux1c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y + I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux1c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y - I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (-1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem RectangleIntegral.const_smul (f : ℂ → E) (z w c : ℂ) :
RectangleIntegral (fun s => c • f s) z w = c • RectangleIntegral f z w := by
simp [RectangleIntegral, HIntegral, VIntegral, smul_add, smul_sub, smul_smul, mul_comm]
theorem RectangleIntegral.const_mul' (f : ℂ → E) (z w c : ℂ) :
RectangleIntegral' (fun s => c • f s) z w = c • RectangleIntegral' f z w := by
simp [RectangleIntegral', RectangleIntegral.const_smul, smul_smul] ; ring_nf
theorem RectangleIntegral.translate (f : ℂ → E) (z w p : ℂ) :
RectangleIntegral (fun s => f (s - p)) z w = RectangleIntegral f (z - p) (w - p) := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, sub_re, sub_im, ← intervalIntegral.integral_comp_sub_right]
congr <;> ext <;> congr 1 <;> simp [Complex.ext_iff]
theorem RectangleIntegral.translate' (f : ℂ → E) (z w p : ℂ) :
RectangleIntegral' (fun s => f (s - p)) z w = RectangleIntegral' f (z - p) (w - p) := by
simp_rw [RectangleIntegral', RectangleIntegral.translate]
lemma Complex.inv_re_add_im : (x + y * I)⁻¹ = (x - I * y) / (x ^ 2 + y ^ 2) := by
rw [Complex.inv_def, div_eq_mul_inv] ; congr <;> simp [conj_ofReal, normSq] <;> ring
lemma sq_add_sq_ne_zero (hy : y ≠ 0) : x ^ 2 + y ^ 2 ≠ 0 := by linarith [sq_nonneg x, (sq_pos_iff y).mpr hy]
lemma continuous_self_div_sq_add_sq (hy : y ≠ 0) : Continuous fun x => x / (x ^ 2 + y ^ 2) :=
continuous_id.div (continuous_id.pow 2 |>.add continuous_const) (λ _ => sq_add_sq_ne_zero hy)
| lemma integral_self_div_sq_add_sq (hy : y ≠ 0) : ∫ x in x₁..x₂, x / (x ^ 2 + y ^ 2) =
Real.log (x₂ ^ 2 + y ^ 2) / 2 - Real.log (x₁ ^ 2 + y ^ 2) / 2 | integral_self_div_sq_add_sq | f36a520 20240122 | 1909a40 20240209 | PrimeNumberTheoremAnd/PrimeNumberTheoremAnd/ResidueCalcOnRectangles.lean | {
"lineInFile": 391,
"tokenPositionInFile": 21397,
"theoremPositionInFile": 46
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": ":= by\n let f (x : ℝ) : ℝ := Real.log (x ^ 2 + y ^ 2) / 2\n have e1 {x} := HasDerivAt.add_const (by simpa using hasDerivAt_pow 2 x) (y ^ 2)\n have e2 {x} : HasDerivAt f (x / (x ^ 2 + y ^ 2)) x := by\n convert (e1.log (sq_add_sq_ne_zero hy)).div_const 2 using 1 ; field_simp ; ring\n have e3 : deriv f = λ x => x / (x ^ 2 + y ^ 2) := funext (λ _ => e2.deriv)\n have e4 : Continuous (deriv f) := by simpa only [e3] using continuous_self_div_sq_add_sq hy\n simp_rw [← e2.deriv]\n exact integral_deriv_eq_sub (λ _ _ => e2.differentiableAt) <| e4.intervalIntegrable _ _",
"proofType": "tactic",
"proofLengthLines": 8,
"proofLengthTokens": 566
} | prime |
import Mathlib.Analysis.Complex.CauchyIntegral
import Mathlib.Analysis.Complex.Convex
import Mathlib.Analysis.Complex.RemovableSingularity
import Mathlib.Analysis.Analytic.Meromorphic
import Mathlib.Analysis.SpecialFunctions.Integrals
import Mathlib.MeasureTheory.Measure.Lebesgue.Integral
import PrimeNumberTheoremAnd.Rectangle
open Complex BigOperators Nat Classical Real Topology Filter Set MeasureTheory intervalIntegral
open scoped Interval
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f g : ℂ → E}
{z w p c A : ℂ} {x x₁ x₂ y y₁ y₂ σ : ℝ}
noncomputable def HIntegral (f : ℂ → E) (x₁ x₂ y : ℝ) : E := ∫ x in x₁..x₂, f (x + y * I)
noncomputable def VIntegral (f : ℂ → E) (x y₁ y₂ : ℝ) : E := I • ∫ y in y₁..y₂, f (x + y * I)
noncomputable def HIntegral' (f : ℂ → E) (x₁ x₂ y : ℝ) : E := (1 / (2 * π * I)) • HIntegral f x₁ x₂ y
noncomputable def VIntegral' (f : ℂ → E) (x y₁ y₂ : ℝ) : E := (1 / (2 * π * I)) • VIntegral f x y₁ y₂
lemma HIntegral_symm : HIntegral f x₁ x₂ y = - HIntegral f x₂ x₁ y := integral_symm _ _
lemma VIntegral_symm : VIntegral f x y₁ y₂ = - VIntegral f x y₂ y₁ := by
simp_rw [VIntegral, integral_symm y₁ y₂, smul_neg, neg_neg]
/-%%
\begin{definition}[RectangleIntegral]\label{RectangleIntegral}\lean{RectangleIntegral}\leanok
A RectangleIntegral of a function $f$ is one over a rectangle determined by $z$ and $w$ in $\C$.
We will sometimes denote it by $\int_{z}^{w} f$. (There is also a primed version, which is $1/(2\pi i)$ times the original.)
\end{definition}
%%-/
/-- A `RectangleIntegral` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`. -/
noncomputable def RectangleIntegral (f : ℂ → E) (z w : ℂ) : E := HIntegral f z.re w.re z.im -
HIntegral f z.re w.re w.im + VIntegral f w.re z.im w.im - VIntegral f z.re z.im w.im
/-- A `RectangleIntegral'` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`, divided by `2 * π * I`. -/
noncomputable abbrev RectangleIntegral' (f : ℂ → E) (z w : ℂ) : E :=
(1 / (2 * π * I)) • RectangleIntegral f z w
/-% ** Wrong delimiter on purpose **
An UpperUIntegral is the integral of a function over a |\_| shape.
\begin{definition}\label{UpperUIntegral}\lean{UpperUIntegral}\leanok
An UpperUIntegral of a function $f$ comes from $\sigma+i\infty$ down to $\sigma+iT$, over to $\sigma'+iT$, and back up to $\sigma'+i\infty$.
\end{definition}
%-/
noncomputable def UpperUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' T +
I • (∫ y : ℝ in Ici T, f (σ' + y * I)) - I • (∫ y : ℝ in Ici T, f (σ + y * I))
/-% ** Wrong delimiter on purpose **
A LowerUIntegral is the integral of a function over a |-| shape.
\begin{definition}[LowerUIntegral]\label{LowerUIntegral}\lean{LowerUIntegral}\leanok
A LowerUIntegral of a function $f$ comes from $\sigma-i\infty$ up to $\sigma-iT$, over to $\sigma'-iT$, and back down to $\sigma'-i\infty$.
\end{definition}
%-/
noncomputable def LowerUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' (-T) -
I • (∫ y : ℝ in Iic (-T), f (σ' + y * I)) + I • (∫ y : ℝ in Iic (-T), f (σ + y * I))
/-%%
It is very convenient to define integrals along vertical lines in the complex plane, as follows.
\begin{definition}[VerticalIntegral]\label{VerticalIntegral}\lean{VerticalIntegral}\leanok
Let $f$ be a function from $\mathbb{C}$ to $\mathbb{C}$, and let $\sigma$ be a real number. Then we define
$$\int_{(\sigma)}f(s)ds = \int_{\sigma-i\infty}^{\sigma+i\infty}f(s)ds.$$
\end{definition}
%%-/
noncomputable def VerticalIntegral (f : ℂ → E) (σ : ℝ) : E := I • ∫ t : ℝ, f (σ + t * I)
--%% We also have a version with a factor of $1/(2\pi i)$.
noncomputable abbrev VerticalIntegral' (f : ℂ → E) (σ : ℝ) : E :=
(1 / (2 * π * I)) • VerticalIntegral f σ
lemma verticalIntegral_split_three (a b : ℝ) (hf : Integrable (fun t : ℝ ↦ f (σ + t * I))) :
VerticalIntegral f σ = I • (∫ t in Iic a, f (σ + t * I)) + VIntegral f σ a b
+ I • ∫ t in Ici b, f (σ + t * I) := by
simp_rw [VerticalIntegral, VIntegral, ← smul_add]
congr
rw [← intervalIntegral.integral_Iic_sub_Iic hf.restrict hf.restrict, add_sub_cancel,
integral_Iic_eq_integral_Iio, intervalIntegral.integral_Iio_add_Ici hf.restrict hf.restrict]
/-% ** Wrong delimiter on purpose **
\begin{lemma}[DiffVertRect_eq_UpperLowerUs]\label{DiffVertRect_eq_UpperLowerUs}\lean{DiffVertRect_eq_UpperLowerUs}\leanok
The difference of two vertical integrals and a rectangle is the difference of an upper and a lower U integrals.
\end{lemma}
%-/
lemma DiffVertRect_eq_UpperLowerUs {σ σ' T : ℝ}
(f_int_σ : Integrable (fun (t : ℝ) ↦ f (σ + t * I)))
(f_int_σ' : Integrable (fun (t : ℝ) ↦ f (σ' + t * I))) :
(VerticalIntegral f σ') - (VerticalIntegral f σ) - (RectangleIntegral f (σ - I * T) (σ' + I * T)) =
(UpperUIntegral f σ σ' T) - (LowerUIntegral f σ σ' T) := by
rw [verticalIntegral_split_three (-T) T f_int_σ, verticalIntegral_split_three (-T) T f_int_σ']
simp only [smul_eq_mul, RectangleIntegral, sub_re, ofReal_re, mul_re, I_re, zero_mul, I_im,
ofReal_im, mul_zero, sub_self, sub_zero, add_re, add_zero, sub_im, mul_im, one_mul, zero_add,
zero_sub, add_im, UpperUIntegral, LowerUIntegral]
abel
/-%
\begin{proof}\uses{UpperUIntegral, LowerUIntegral}\leanok
Follows directly from the definitions.
\end{proof}
%-/
/-- A function is `HolomorphicOn` a set if it is complex differentiable on that set. -/
abbrev HolomorphicOn (f : ℂ → E) (s : Set ℂ) : Prop := DifferentiableOn ℂ f s
/-%%
\begin{theorem}[existsDifferentiableOn_of_bddAbove]\label{existsDifferentiableOn_of_bddAbove}\lean{existsDifferentiableOn_of_bddAbove}\leanok
If $f$ is differentiable on a set $s$ except at $c\in s$, and $f$ is bounded above on $s\setminus\{c\}$, then there exists a differentiable function $g$ on $s$ such that $f$ and $g$ agree on $s\setminus\{c\}$.
\end{theorem}
%%-/
theorem existsDifferentiableOn_of_bddAbove [CompleteSpace E] {s : Set ℂ} {c : ℂ} (hc : s ∈ nhds c)
(hd : HolomorphicOn f (s \ {c})) (hb : BddAbove (norm ∘ f '' (s \ {c}))) :
∃ (g : ℂ → E), HolomorphicOn g s ∧ (Set.EqOn f g (s \ {c})) :=
⟨Function.update f c (limUnder (𝓝[{c}ᶜ] c) f),
differentiableOn_update_limUnder_of_bddAbove hc hd hb,
fun z hz ↦ if h : z = c then (hz.2 h).elim else by simp [h]⟩
/-%%
\begin{proof}\leanok
This is the Riemann Removable Singularity Theorem, slightly rephrased from what's in Mathlib. (We don't care what the function $g$ is, just that it's holomorphic.)
\end{proof}
%%-/
/-%%
\begin{theorem}[HolomorphicOn.vanishesOnRectangle]\label{HolomorphicOn.vanishesOnRectangle}\lean{HolomorphicOn.vanishesOnRectangle}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$, then the integral of $f$ over the rectangle with corners $z$ and $w$ is $0$.
\end{theorem}
%%-/
theorem HolomorphicOn.vanishesOnRectangle [CompleteSpace E] {U : Set ℂ}
(f_holo : HolomorphicOn f U) (hU : Rectangle z w ⊆ U) :
RectangleIntegral f z w = 0 :=
integral_boundary_rect_eq_zero_of_differentiableOn f z w (f_holo.mono hU)
/-%%
\begin{proof}\leanok
This is in a Mathlib PR.
\end{proof}
%%-/
theorem RectangleIntegral_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral f z w = RectangleIntegral g z w := by
unfold RectangleIntegral VIntegral
congr 2; swap; congr 1; swap; congr 1
all_goals refine intervalIntegral.integral_congr fun _ _ ↦ h ?_
· exact Or.inl <| Or.inl <| Or.inl ⟨by simpa, by simp⟩
· exact Or.inl <| Or.inr ⟨by simpa, by simp⟩
· exact Or.inr ⟨by simp, by simpa⟩
· exact Or.inl <| Or.inl <| Or.inr ⟨by simp, by simpa⟩
theorem RectangleIntegral'_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral' f z w = RectangleIntegral' g z w := by
rw [RectangleIntegral', RectangleIntegral_congr h]
theorem rectangleIntegral_symm (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f z w = RectangleIntegral f w z := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, intervalIntegral.integral_symm w.re,
intervalIntegral.integral_symm w.im, sub_neg_eq_add, smul_neg, sub_neg_eq_add, ← sub_eq_add_neg,
neg_add_eq_sub, sub_add_eq_add_sub]
theorem rectangleIntegral_symm_re (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f (w.re + z.im * I) (z.re + w.im * I) = - RectangleIntegral f z w := by
simp [RectangleIntegral, ← sub_eq_zero]
rw [HIntegral_symm (y := z.im), HIntegral_symm (y := w.im)]
abel
def RectangleBorderIntegrable (f : ℂ → E) (z w : ℂ) : Prop :=
IntervalIntegrable (fun x => f (x + z.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun x => f (x + w.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun y => f (w.re + y * I)) volume z.im w.im ∧
IntervalIntegrable (fun y => f (z.re + y * I)) volume z.im w.im
theorem RectangleBorderIntegrable.add {f g : ℂ → E} (hf : RectangleBorderIntegrable f z w)
(hg : RectangleBorderIntegrable g z w) :
RectangleIntegral (f + g) z w = RectangleIntegral f z w + RectangleIntegral g z w := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
rw [intervalIntegral.integral_add hf.1 hg.1, intervalIntegral.integral_add hf.2.1 hg.2.1,
intervalIntegral.integral_add hf.2.2.1 hg.2.2.1, intervalIntegral.integral_add hf.2.2.2 hg.2.2.2]
rw [← sub_eq_zero]
simp only [smul_add]; abel
theorem ContinuousOn.rectangleBorder_integrable (hf : ContinuousOn f (RectangleBorder z w)) :
RectangleBorderIntegrable f z w :=
⟨(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_re z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_re z w)).intervalIntegrable⟩
theorem ContinuousOn.rectangleBorderIntegrable (hf : ContinuousOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
(hf.mono (rectangleBorder_subset_rectangle z w)).rectangleBorder_integrable
theorem ContinuousOn.rectangleBorderNoPIntegrable (hf : ContinuousOn f (Rectangle z w \ {p}))
(pNotOnBorder : p ∉ RectangleBorder z w) : RectangleBorderIntegrable f z w := by
refine (hf.mono (Set.subset_diff.mpr ?_)).rectangleBorder_integrable
exact ⟨rectangleBorder_subset_rectangle z w, disjoint_singleton_right.mpr pNotOnBorder⟩
theorem HolomorphicOn.rectangleBorderIntegrable' (hf : HolomorphicOn f (Rectangle z w \ {p}))
(hp : Rectangle z w ∈ nhds p) : RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderNoPIntegrable (not_mem_rectangleBorder_of_rectangle_mem_nhds hp)
theorem HolomorphicOn.rectangleBorderIntegrable (hf : HolomorphicOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderIntegrable
/--
Given `x₀ a x₁ : ℝ`, and `y₀ y₁ : ℝ` and a function `f : ℂ → ℂ` so that
both `(t : ℝ) ↦ f(t + y₀ * I)` and `(t : ℝ) ↦ f(t + y₁ * I)` are integrable over both
`t ∈ Icc x₀ a` and `t ∈ Icc a x₁`, we have that
`RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I)` is the sum of
`RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I)` and
`RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I)`.
-/
lemma RectangleIntegralHSplit {a x₀ x₁ y₀ y₁ : ℝ}
(f_int_x₀_a_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume x₀ a)
(f_int_a_x₁_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume a x₁)
(f_int_x₀_a_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume x₀ a)
(f_int_a_x₁_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume a x₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_bot f_int_a_x₁_bot,
← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_top f_int_a_x₁_top]
abel
lemma RectangleIntegralHSplit' {a x₀ x₁ y₀ y₁ : ℝ} (ha : a ∈ [[x₀, x₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) :=
RectangleIntegralHSplit
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
lemma RectangleIntegralVSplit {b x₀ x₁ y₀ y₁ : ℝ}
(f_int_y₀_b_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume y₀ b)
(f_int_b_y₁_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume b y₁)
(f_int_y₀_b_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume y₀ b)
(f_int_b_y₁_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume b y₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_left f_int_b_y₁_left,
← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_right f_int_b_y₁_right, ← sub_eq_zero]
simp only [smul_add]; abel
lemma RectangleIntegralVSplit' {b x₀ x₁ y₀ y₁ : ℝ} (hb : b ∈ [[y₀, y₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) :=
RectangleIntegralVSplit
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
lemma RectanglePullToNhdOfPole' [CompleteSpace E] {z₀ z₁ z₂ z₃ p : ℂ}
(h_orientation : z₀.re ≤ z₃.re ∧ z₀.im ≤ z₃.im ∧ z₁.re ≤ z₂.re ∧ z₁.im ≤ z₂.im)
(hp : Rectangle z₁ z₂ ∈ 𝓝 p) (hz : Rectangle z₁ z₂ ⊆ Rectangle z₀ z₃)
(fHolo : HolomorphicOn f (Rectangle z₀ z₃ \ {p})) :
RectangleIntegral f z₀ z₃ = RectangleIntegral f z₁ z₂ := by
obtain ⟨hz₀_re, hz₀_im, hz₁_re, hz₁_im⟩ := h_orientation
have := rect_subset_iff.mp hz
rw [Rectangle, uIcc_of_le hz₀_re, uIcc_of_le hz₀_im] at this
obtain ⟨⟨⟨_, _⟩, ⟨_, _⟩⟩, ⟨_, _⟩, ⟨_, _⟩⟩ := this
obtain ⟨⟨_, _⟩, ⟨_, _⟩⟩ := (uIoo_of_le hz₁_re) ▸ (uIoo_of_le hz₁_im) ▸ rectangle_mem_nhds_iff.mp hp
obtain ⟨_, _, _, _⟩ := show p.re < z₂.re ∧ p.re < z₃.re ∧ p.im < z₂.im ∧ p.im < z₃.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
obtain ⟨_, _, _, _⟩ := show z₀.re < p.re ∧ z₁.re < p.re ∧ z₀.im < p.im ∧ z₁.im < p.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
have fCont := fHolo.continuousOn
have hbot : RectangleBorderIntegrable f (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have htop : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have hleft : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
have hright : RectangleBorderIntegrable f (↑z₁.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
all_goals try {
refine (fCont.mono (rectangleBorder_subset_punctured_rect ?_ ?_)).rectangleBorder_integrable
· simp_all
· simpa using ⟨by linarith, by linarith, by linarith, by linarith⟩
}
have hbot' : z₁.im ∈ [[z₀.im, z₃.im]] := ?_
have htop' : z₂.im ∈ [[z₁.im, z₃.im]] := ?_
have hleft' : z₁.re ∈ [[z₀.re, z₃.re]] := ?_
have hright' : z₂.re ∈ [[z₁.re, z₃.re]] := ?_
all_goals try { rw [Set.uIcc_of_le]; constructor; all_goals assumption }
have hbot'' : Rectangle (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₁.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have htop'' : Rectangle (↑z₀.re + ↑z₂.im * I) (↑z₃.re + ↑z₃.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hleft'' : Rectangle (↑z₀.re + ↑z₁.im * I) (↑z₁.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hright'' : Rectangle (↑z₂.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
all_goals try { apply rectangle_subset_punctured_rect <;> simp_all }
rw [← re_add_im z₀, ← re_add_im z₃,
RectangleIntegralVSplit' hbot' hbot, fHolo.vanishesOnRectangle hbot'', zero_add,
RectangleIntegralVSplit' htop' htop, fHolo.vanishesOnRectangle htop'', add_zero,
RectangleIntegralHSplit' hleft' hleft, fHolo.vanishesOnRectangle hleft'', zero_add,
RectangleIntegralHSplit' hright' hright, fHolo.vanishesOnRectangle hright'', add_zero,
re_add_im, re_add_im]
/-%%
The next lemma allows to zoom a big rectangle down to a small square, centered at a pole.
\begin{lemma}[RectanglePullToNhdOfPole]\label{RectanglePullToNhdOfPole}\lean{RectanglePullToNhdOfPole}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$ except at a point $p$, then the integral of $f$
over the rectangle with corners $z$ and $w$ is the same as the integral of $f$ over a small square
centered at $p$.
\end{lemma}
%%-/
/-- Given `f` holomorphic on a rectangle `z` and `w` except at a point `p`, the integral of `f` over
the rectangle with corners `z` and `w` is the same as the integral of `f` over a small square
centered at `p`. -/
lemma RectanglePullToNhdOfPole [CompleteSpace E] {z w p : ℂ} (zRe_lt_wRe : z.re ≤ w.re)
(zIm_lt_wIm : z.im ≤ w.im) (hp : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral f z w = RectangleIntegral f (-c - I * c + p) (c + I * c + p) := by
/-%%
\begin{proof}\uses{HolomorphicOn.vanishesOnRectangle}\leanok
Chop the big rectangle with two vertical cuts and two horizontal cuts into smaller rectangles,
the middle one being the desired square. The integral over each of the outer rectangles
vanishes, since $f$ is holomorphic there. (The constant $c$ being ``small enough'' here just means
that the inner square is strictly contained in the big rectangle.)
%%-/
filter_upwards [Ioo_mem_nhdsWithin_Ioi' zero_lt_one, SmallSquareInRectangle hp]
intro c ⟨cpos, _⟩ hc
simp_rw [mul_comm I]
exact RectanglePullToNhdOfPole' (by simp_all [cpos.le])
(square_mem_nhds p (ne_of_gt cpos)) hc fHolo
--%%\end{proof}
lemma RectanglePullToNhdOfPole'' [CompleteSpace E] {z w p : ℂ} (zRe_le_wRe : z.re ≤ w.re)
(zIm_le_wIm : z.im ≤ w.im) (pInRectInterior : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral' f z w = RectangleIntegral' f (-c - I * c + p) (c + I * c + p) := by
filter_upwards [RectanglePullToNhdOfPole zRe_le_wRe zIm_le_wIm pInRectInterior fHolo] with c h
simp_rw [RectangleIntegral', h]
theorem ResidueTheoremAtOrigin_aux1c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y + I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux1c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y - I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (-1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem RectangleIntegral.const_smul (f : ℂ → E) (z w c : ℂ) :
RectangleIntegral (fun s => c • f s) z w = c • RectangleIntegral f z w := by
simp [RectangleIntegral, HIntegral, VIntegral, smul_add, smul_sub, smul_smul, mul_comm]
theorem RectangleIntegral.const_mul' (f : ℂ → E) (z w c : ℂ) :
RectangleIntegral' (fun s => c • f s) z w = c • RectangleIntegral' f z w := by
simp [RectangleIntegral', RectangleIntegral.const_smul, smul_smul] ; ring_nf
theorem RectangleIntegral.translate (f : ℂ → E) (z w p : ℂ) :
RectangleIntegral (fun s => f (s - p)) z w = RectangleIntegral f (z - p) (w - p) := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, sub_re, sub_im, ← intervalIntegral.integral_comp_sub_right]
congr <;> ext <;> congr 1 <;> simp [Complex.ext_iff]
theorem RectangleIntegral.translate' (f : ℂ → E) (z w p : ℂ) :
RectangleIntegral' (fun s => f (s - p)) z w = RectangleIntegral' f (z - p) (w - p) := by
simp_rw [RectangleIntegral', RectangleIntegral.translate]
lemma Complex.inv_re_add_im : (x + y * I)⁻¹ = (x - I * y) / (x ^ 2 + y ^ 2) := by
rw [Complex.inv_def, div_eq_mul_inv] ; congr <;> simp [conj_ofReal, normSq] <;> ring
lemma sq_add_sq_ne_zero (hy : y ≠ 0) : x ^ 2 + y ^ 2 ≠ 0 := by linarith [sq_nonneg x, (sq_pos_iff y).mpr hy]
lemma continuous_self_div_sq_add_sq (hy : y ≠ 0) : Continuous fun x => x / (x ^ 2 + y ^ 2) :=
continuous_id.div (continuous_id.pow 2 |>.add continuous_const) (λ _ => sq_add_sq_ne_zero hy)
lemma integral_self_div_sq_add_sq (hy : y ≠ 0) : ∫ x in x₁..x₂, x / (x ^ 2 + y ^ 2) =
Real.log (x₂ ^ 2 + y ^ 2) / 2 - Real.log (x₁ ^ 2 + y ^ 2) / 2 := by
let f (x : ℝ) : ℝ := Real.log (x ^ 2 + y ^ 2) / 2
have e1 {x} := HasDerivAt.add_const (by simpa using hasDerivAt_pow 2 x) (y ^ 2)
have e2 {x} : HasDerivAt f (x / (x ^ 2 + y ^ 2)) x := by
convert (e1.log (sq_add_sq_ne_zero hy)).div_const 2 using 1 ; field_simp ; ring
have e3 : deriv f = λ x => x / (x ^ 2 + y ^ 2) := funext (λ _ => e2.deriv)
have e4 : Continuous (deriv f) := by simpa only [e3] using continuous_self_div_sq_add_sq hy
simp_rw [← e2.deriv]
exact integral_deriv_eq_sub (λ _ _ => e2.differentiableAt) <| e4.intervalIntegrable _ _
| lemma integral_const_div_sq_add_sq (hy : y ≠ 0) : ∫ x in x₁..x₂, y / (x ^ 2 + y ^ 2) =
arctan (x₂ / y) - arctan (x₁ / y) | integral_const_div_sq_add_sq | f36a520 20240122 | 1909a40 20240209 | PrimeNumberTheoremAnd/PrimeNumberTheoremAnd/ResidueCalcOnRectangles.lean | {
"lineInFile": 402,
"tokenPositionInFile": 22117,
"theoremPositionInFile": 47
} | {
"inFilePremises": false,
"repositoryPremises": false
} | {
"hasProof": true,
"proof": ":= by\n nth_rewrite 1 [← div_mul_cancel₀ x₁ hy, ← div_mul_cancel₀ x₂ hy]\n simp_rw [← mul_integral_comp_mul_right, ← integral_const_mul, ← integral_one_div_one_add_sq]\n exact integral_congr <| λ x _ => by field_simp; ring",
"proofType": "tactic",
"proofLengthLines": 3,
"proofLengthTokens": 222
} | prime |
import Mathlib.Analysis.Complex.CauchyIntegral
import Mathlib.Analysis.Complex.Convex
import Mathlib.Analysis.Complex.RemovableSingularity
import Mathlib.Analysis.Analytic.Meromorphic
import Mathlib.Analysis.SpecialFunctions.Integrals
import Mathlib.MeasureTheory.Measure.Lebesgue.Integral
import PrimeNumberTheoremAnd.Rectangle
open Complex BigOperators Nat Classical Real Topology Filter Set MeasureTheory intervalIntegral
open scoped Interval
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f g : ℂ → E}
{z w p c A : ℂ} {x x₁ x₂ y y₁ y₂ σ : ℝ}
noncomputable def HIntegral (f : ℂ → E) (x₁ x₂ y : ℝ) : E := ∫ x in x₁..x₂, f (x + y * I)
noncomputable def VIntegral (f : ℂ → E) (x y₁ y₂ : ℝ) : E := I • ∫ y in y₁..y₂, f (x + y * I)
noncomputable def HIntegral' (f : ℂ → E) (x₁ x₂ y : ℝ) : E := (1 / (2 * π * I)) • HIntegral f x₁ x₂ y
noncomputable def VIntegral' (f : ℂ → E) (x y₁ y₂ : ℝ) : E := (1 / (2 * π * I)) • VIntegral f x y₁ y₂
lemma HIntegral_symm : HIntegral f x₁ x₂ y = - HIntegral f x₂ x₁ y := integral_symm _ _
lemma VIntegral_symm : VIntegral f x y₁ y₂ = - VIntegral f x y₂ y₁ := by
simp_rw [VIntegral, integral_symm y₁ y₂, smul_neg, neg_neg]
/-%%
\begin{definition}[RectangleIntegral]\label{RectangleIntegral}\lean{RectangleIntegral}\leanok
A RectangleIntegral of a function $f$ is one over a rectangle determined by $z$ and $w$ in $\C$.
We will sometimes denote it by $\int_{z}^{w} f$. (There is also a primed version, which is $1/(2\pi i)$ times the original.)
\end{definition}
%%-/
/-- A `RectangleIntegral` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`. -/
noncomputable def RectangleIntegral (f : ℂ → E) (z w : ℂ) : E := HIntegral f z.re w.re z.im -
HIntegral f z.re w.re w.im + VIntegral f w.re z.im w.im - VIntegral f z.re z.im w.im
/-- A `RectangleIntegral'` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`, divided by `2 * π * I`. -/
noncomputable abbrev RectangleIntegral' (f : ℂ → E) (z w : ℂ) : E :=
(1 / (2 * π * I)) • RectangleIntegral f z w
/-% ** Wrong delimiter on purpose **
An UpperUIntegral is the integral of a function over a |\_| shape.
\begin{definition}\label{UpperUIntegral}\lean{UpperUIntegral}\leanok
An UpperUIntegral of a function $f$ comes from $\sigma+i\infty$ down to $\sigma+iT$, over to $\sigma'+iT$, and back up to $\sigma'+i\infty$.
\end{definition}
%-/
noncomputable def UpperUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' T +
I • (∫ y : ℝ in Ici T, f (σ' + y * I)) - I • (∫ y : ℝ in Ici T, f (σ + y * I))
/-% ** Wrong delimiter on purpose **
A LowerUIntegral is the integral of a function over a |-| shape.
\begin{definition}[LowerUIntegral]\label{LowerUIntegral}\lean{LowerUIntegral}\leanok
A LowerUIntegral of a function $f$ comes from $\sigma-i\infty$ up to $\sigma-iT$, over to $\sigma'-iT$, and back down to $\sigma'-i\infty$.
\end{definition}
%-/
noncomputable def LowerUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' (-T) -
I • (∫ y : ℝ in Iic (-T), f (σ' + y * I)) + I • (∫ y : ℝ in Iic (-T), f (σ + y * I))
/-%%
It is very convenient to define integrals along vertical lines in the complex plane, as follows.
\begin{definition}[VerticalIntegral]\label{VerticalIntegral}\lean{VerticalIntegral}\leanok
Let $f$ be a function from $\mathbb{C}$ to $\mathbb{C}$, and let $\sigma$ be a real number. Then we define
$$\int_{(\sigma)}f(s)ds = \int_{\sigma-i\infty}^{\sigma+i\infty}f(s)ds.$$
\end{definition}
%%-/
noncomputable def VerticalIntegral (f : ℂ → E) (σ : ℝ) : E := I • ∫ t : ℝ, f (σ + t * I)
--%% We also have a version with a factor of $1/(2\pi i)$.
noncomputable abbrev VerticalIntegral' (f : ℂ → E) (σ : ℝ) : E :=
(1 / (2 * π * I)) • VerticalIntegral f σ
lemma verticalIntegral_split_three (a b : ℝ) (hf : Integrable (fun t : ℝ ↦ f (σ + t * I))) :
VerticalIntegral f σ = I • (∫ t in Iic a, f (σ + t * I)) + VIntegral f σ a b
+ I • ∫ t in Ici b, f (σ + t * I) := by
simp_rw [VerticalIntegral, VIntegral, ← smul_add]
congr
rw [← intervalIntegral.integral_Iic_sub_Iic hf.restrict hf.restrict, add_sub_cancel,
integral_Iic_eq_integral_Iio, intervalIntegral.integral_Iio_add_Ici hf.restrict hf.restrict]
/-% ** Wrong delimiter on purpose **
\begin{lemma}[DiffVertRect_eq_UpperLowerUs]\label{DiffVertRect_eq_UpperLowerUs}\lean{DiffVertRect_eq_UpperLowerUs}\leanok
The difference of two vertical integrals and a rectangle is the difference of an upper and a lower U integrals.
\end{lemma}
%-/
lemma DiffVertRect_eq_UpperLowerUs {σ σ' T : ℝ}
(f_int_σ : Integrable (fun (t : ℝ) ↦ f (σ + t * I)))
(f_int_σ' : Integrable (fun (t : ℝ) ↦ f (σ' + t * I))) :
(VerticalIntegral f σ') - (VerticalIntegral f σ) - (RectangleIntegral f (σ - I * T) (σ' + I * T)) =
(UpperUIntegral f σ σ' T) - (LowerUIntegral f σ σ' T) := by
rw [verticalIntegral_split_three (-T) T f_int_σ, verticalIntegral_split_three (-T) T f_int_σ']
simp only [smul_eq_mul, RectangleIntegral, sub_re, ofReal_re, mul_re, I_re, zero_mul, I_im,
ofReal_im, mul_zero, sub_self, sub_zero, add_re, add_zero, sub_im, mul_im, one_mul, zero_add,
zero_sub, add_im, UpperUIntegral, LowerUIntegral]
abel
/-%
\begin{proof}\uses{UpperUIntegral, LowerUIntegral}\leanok
Follows directly from the definitions.
\end{proof}
%-/
/-- A function is `HolomorphicOn` a set if it is complex differentiable on that set. -/
abbrev HolomorphicOn (f : ℂ → E) (s : Set ℂ) : Prop := DifferentiableOn ℂ f s
/-%%
\begin{theorem}[existsDifferentiableOn_of_bddAbove]\label{existsDifferentiableOn_of_bddAbove}\lean{existsDifferentiableOn_of_bddAbove}\leanok
If $f$ is differentiable on a set $s$ except at $c\in s$, and $f$ is bounded above on $s\setminus\{c\}$, then there exists a differentiable function $g$ on $s$ such that $f$ and $g$ agree on $s\setminus\{c\}$.
\end{theorem}
%%-/
theorem existsDifferentiableOn_of_bddAbove [CompleteSpace E] {s : Set ℂ} {c : ℂ} (hc : s ∈ nhds c)
(hd : HolomorphicOn f (s \ {c})) (hb : BddAbove (norm ∘ f '' (s \ {c}))) :
∃ (g : ℂ → E), HolomorphicOn g s ∧ (Set.EqOn f g (s \ {c})) :=
⟨Function.update f c (limUnder (𝓝[{c}ᶜ] c) f),
differentiableOn_update_limUnder_of_bddAbove hc hd hb,
fun z hz ↦ if h : z = c then (hz.2 h).elim else by simp [h]⟩
/-%%
\begin{proof}\leanok
This is the Riemann Removable Singularity Theorem, slightly rephrased from what's in Mathlib. (We don't care what the function $g$ is, just that it's holomorphic.)
\end{proof}
%%-/
/-%%
\begin{theorem}[HolomorphicOn.vanishesOnRectangle]\label{HolomorphicOn.vanishesOnRectangle}\lean{HolomorphicOn.vanishesOnRectangle}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$, then the integral of $f$ over the rectangle with corners $z$ and $w$ is $0$.
\end{theorem}
%%-/
theorem HolomorphicOn.vanishesOnRectangle [CompleteSpace E] {U : Set ℂ}
(f_holo : HolomorphicOn f U) (hU : Rectangle z w ⊆ U) :
RectangleIntegral f z w = 0 :=
integral_boundary_rect_eq_zero_of_differentiableOn f z w (f_holo.mono hU)
/-%%
\begin{proof}\leanok
This is in a Mathlib PR.
\end{proof}
%%-/
theorem RectangleIntegral_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral f z w = RectangleIntegral g z w := by
unfold RectangleIntegral VIntegral
congr 2; swap; congr 1; swap; congr 1
all_goals refine intervalIntegral.integral_congr fun _ _ ↦ h ?_
· exact Or.inl <| Or.inl <| Or.inl ⟨by simpa, by simp⟩
· exact Or.inl <| Or.inr ⟨by simpa, by simp⟩
· exact Or.inr ⟨by simp, by simpa⟩
· exact Or.inl <| Or.inl <| Or.inr ⟨by simp, by simpa⟩
theorem RectangleIntegral'_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral' f z w = RectangleIntegral' g z w := by
rw [RectangleIntegral', RectangleIntegral_congr h]
theorem rectangleIntegral_symm (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f z w = RectangleIntegral f w z := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, intervalIntegral.integral_symm w.re,
intervalIntegral.integral_symm w.im, sub_neg_eq_add, smul_neg, sub_neg_eq_add, ← sub_eq_add_neg,
neg_add_eq_sub, sub_add_eq_add_sub]
theorem rectangleIntegral_symm_re (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f (w.re + z.im * I) (z.re + w.im * I) = - RectangleIntegral f z w := by
simp [RectangleIntegral, ← sub_eq_zero]
rw [HIntegral_symm (y := z.im), HIntegral_symm (y := w.im)]
abel
def RectangleBorderIntegrable (f : ℂ → E) (z w : ℂ) : Prop :=
IntervalIntegrable (fun x => f (x + z.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun x => f (x + w.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun y => f (w.re + y * I)) volume z.im w.im ∧
IntervalIntegrable (fun y => f (z.re + y * I)) volume z.im w.im
theorem RectangleBorderIntegrable.add {f g : ℂ → E} (hf : RectangleBorderIntegrable f z w)
(hg : RectangleBorderIntegrable g z w) :
RectangleIntegral (f + g) z w = RectangleIntegral f z w + RectangleIntegral g z w := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
rw [intervalIntegral.integral_add hf.1 hg.1, intervalIntegral.integral_add hf.2.1 hg.2.1,
intervalIntegral.integral_add hf.2.2.1 hg.2.2.1, intervalIntegral.integral_add hf.2.2.2 hg.2.2.2]
rw [← sub_eq_zero]
simp only [smul_add]; abel
theorem ContinuousOn.rectangleBorder_integrable (hf : ContinuousOn f (RectangleBorder z w)) :
RectangleBorderIntegrable f z w :=
⟨(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_re z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_re z w)).intervalIntegrable⟩
theorem ContinuousOn.rectangleBorderIntegrable (hf : ContinuousOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
(hf.mono (rectangleBorder_subset_rectangle z w)).rectangleBorder_integrable
theorem ContinuousOn.rectangleBorderNoPIntegrable (hf : ContinuousOn f (Rectangle z w \ {p}))
(pNotOnBorder : p ∉ RectangleBorder z w) : RectangleBorderIntegrable f z w := by
refine (hf.mono (Set.subset_diff.mpr ?_)).rectangleBorder_integrable
exact ⟨rectangleBorder_subset_rectangle z w, disjoint_singleton_right.mpr pNotOnBorder⟩
theorem HolomorphicOn.rectangleBorderIntegrable' (hf : HolomorphicOn f (Rectangle z w \ {p}))
(hp : Rectangle z w ∈ nhds p) : RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderNoPIntegrable (not_mem_rectangleBorder_of_rectangle_mem_nhds hp)
theorem HolomorphicOn.rectangleBorderIntegrable (hf : HolomorphicOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderIntegrable
/--
Given `x₀ a x₁ : ℝ`, and `y₀ y₁ : ℝ` and a function `f : ℂ → ℂ` so that
both `(t : ℝ) ↦ f(t + y₀ * I)` and `(t : ℝ) ↦ f(t + y₁ * I)` are integrable over both
`t ∈ Icc x₀ a` and `t ∈ Icc a x₁`, we have that
`RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I)` is the sum of
`RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I)` and
`RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I)`.
-/
lemma RectangleIntegralHSplit {a x₀ x₁ y₀ y₁ : ℝ}
(f_int_x₀_a_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume x₀ a)
(f_int_a_x₁_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume a x₁)
(f_int_x₀_a_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume x₀ a)
(f_int_a_x₁_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume a x₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_bot f_int_a_x₁_bot,
← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_top f_int_a_x₁_top]
abel
lemma RectangleIntegralHSplit' {a x₀ x₁ y₀ y₁ : ℝ} (ha : a ∈ [[x₀, x₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) :=
RectangleIntegralHSplit
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
lemma RectangleIntegralVSplit {b x₀ x₁ y₀ y₁ : ℝ}
(f_int_y₀_b_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume y₀ b)
(f_int_b_y₁_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume b y₁)
(f_int_y₀_b_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume y₀ b)
(f_int_b_y₁_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume b y₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_left f_int_b_y₁_left,
← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_right f_int_b_y₁_right, ← sub_eq_zero]
simp only [smul_add]; abel
lemma RectangleIntegralVSplit' {b x₀ x₁ y₀ y₁ : ℝ} (hb : b ∈ [[y₀, y₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) :=
RectangleIntegralVSplit
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
lemma RectanglePullToNhdOfPole' [CompleteSpace E] {z₀ z₁ z₂ z₃ p : ℂ}
(h_orientation : z₀.re ≤ z₃.re ∧ z₀.im ≤ z₃.im ∧ z₁.re ≤ z₂.re ∧ z₁.im ≤ z₂.im)
(hp : Rectangle z₁ z₂ ∈ 𝓝 p) (hz : Rectangle z₁ z₂ ⊆ Rectangle z₀ z₃)
(fHolo : HolomorphicOn f (Rectangle z₀ z₃ \ {p})) :
RectangleIntegral f z₀ z₃ = RectangleIntegral f z₁ z₂ := by
obtain ⟨hz₀_re, hz₀_im, hz₁_re, hz₁_im⟩ := h_orientation
have := rect_subset_iff.mp hz
rw [Rectangle, uIcc_of_le hz₀_re, uIcc_of_le hz₀_im] at this
obtain ⟨⟨⟨_, _⟩, ⟨_, _⟩⟩, ⟨_, _⟩, ⟨_, _⟩⟩ := this
obtain ⟨⟨_, _⟩, ⟨_, _⟩⟩ := (uIoo_of_le hz₁_re) ▸ (uIoo_of_le hz₁_im) ▸ rectangle_mem_nhds_iff.mp hp
obtain ⟨_, _, _, _⟩ := show p.re < z₂.re ∧ p.re < z₃.re ∧ p.im < z₂.im ∧ p.im < z₃.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
obtain ⟨_, _, _, _⟩ := show z₀.re < p.re ∧ z₁.re < p.re ∧ z₀.im < p.im ∧ z₁.im < p.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
have fCont := fHolo.continuousOn
have hbot : RectangleBorderIntegrable f (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have htop : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have hleft : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
have hright : RectangleBorderIntegrable f (↑z₁.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
all_goals try {
refine (fCont.mono (rectangleBorder_subset_punctured_rect ?_ ?_)).rectangleBorder_integrable
· simp_all
· simpa using ⟨by linarith, by linarith, by linarith, by linarith⟩
}
have hbot' : z₁.im ∈ [[z₀.im, z₃.im]] := ?_
have htop' : z₂.im ∈ [[z₁.im, z₃.im]] := ?_
have hleft' : z₁.re ∈ [[z₀.re, z₃.re]] := ?_
have hright' : z₂.re ∈ [[z₁.re, z₃.re]] := ?_
all_goals try { rw [Set.uIcc_of_le]; constructor; all_goals assumption }
have hbot'' : Rectangle (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₁.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have htop'' : Rectangle (↑z₀.re + ↑z₂.im * I) (↑z₃.re + ↑z₃.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hleft'' : Rectangle (↑z₀.re + ↑z₁.im * I) (↑z₁.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hright'' : Rectangle (↑z₂.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
all_goals try { apply rectangle_subset_punctured_rect <;> simp_all }
rw [← re_add_im z₀, ← re_add_im z₃,
RectangleIntegralVSplit' hbot' hbot, fHolo.vanishesOnRectangle hbot'', zero_add,
RectangleIntegralVSplit' htop' htop, fHolo.vanishesOnRectangle htop'', add_zero,
RectangleIntegralHSplit' hleft' hleft, fHolo.vanishesOnRectangle hleft'', zero_add,
RectangleIntegralHSplit' hright' hright, fHolo.vanishesOnRectangle hright'', add_zero,
re_add_im, re_add_im]
/-%%
The next lemma allows to zoom a big rectangle down to a small square, centered at a pole.
\begin{lemma}[RectanglePullToNhdOfPole]\label{RectanglePullToNhdOfPole}\lean{RectanglePullToNhdOfPole}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$ except at a point $p$, then the integral of $f$
over the rectangle with corners $z$ and $w$ is the same as the integral of $f$ over a small square
centered at $p$.
\end{lemma}
%%-/
/-- Given `f` holomorphic on a rectangle `z` and `w` except at a point `p`, the integral of `f` over
the rectangle with corners `z` and `w` is the same as the integral of `f` over a small square
centered at `p`. -/
lemma RectanglePullToNhdOfPole [CompleteSpace E] {z w p : ℂ} (zRe_lt_wRe : z.re ≤ w.re)
(zIm_lt_wIm : z.im ≤ w.im) (hp : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral f z w = RectangleIntegral f (-c - I * c + p) (c + I * c + p) := by
/-%%
\begin{proof}\uses{HolomorphicOn.vanishesOnRectangle}\leanok
Chop the big rectangle with two vertical cuts and two horizontal cuts into smaller rectangles,
the middle one being the desired square. The integral over each of the outer rectangles
vanishes, since $f$ is holomorphic there. (The constant $c$ being ``small enough'' here just means
that the inner square is strictly contained in the big rectangle.)
%%-/
filter_upwards [Ioo_mem_nhdsWithin_Ioi' zero_lt_one, SmallSquareInRectangle hp]
intro c ⟨cpos, _⟩ hc
simp_rw [mul_comm I]
exact RectanglePullToNhdOfPole' (by simp_all [cpos.le])
(square_mem_nhds p (ne_of_gt cpos)) hc fHolo
--%%\end{proof}
lemma RectanglePullToNhdOfPole'' [CompleteSpace E] {z w p : ℂ} (zRe_le_wRe : z.re ≤ w.re)
(zIm_le_wIm : z.im ≤ w.im) (pInRectInterior : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral' f z w = RectangleIntegral' f (-c - I * c + p) (c + I * c + p) := by
filter_upwards [RectanglePullToNhdOfPole zRe_le_wRe zIm_le_wIm pInRectInterior fHolo] with c h
simp_rw [RectangleIntegral', h]
theorem ResidueTheoremAtOrigin_aux1c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y + I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux1c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y - I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (-1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem RectangleIntegral.const_smul (f : ℂ → E) (z w c : ℂ) :
RectangleIntegral (fun s => c • f s) z w = c • RectangleIntegral f z w := by
simp [RectangleIntegral, HIntegral, VIntegral, smul_add, smul_sub, smul_smul, mul_comm]
theorem RectangleIntegral.const_mul' (f : ℂ → E) (z w c : ℂ) :
RectangleIntegral' (fun s => c • f s) z w = c • RectangleIntegral' f z w := by
simp [RectangleIntegral', RectangleIntegral.const_smul, smul_smul] ; ring_nf
theorem RectangleIntegral.translate (f : ℂ → E) (z w p : ℂ) :
RectangleIntegral (fun s => f (s - p)) z w = RectangleIntegral f (z - p) (w - p) := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, sub_re, sub_im, ← intervalIntegral.integral_comp_sub_right]
congr <;> ext <;> congr 1 <;> simp [Complex.ext_iff]
theorem RectangleIntegral.translate' (f : ℂ → E) (z w p : ℂ) :
RectangleIntegral' (fun s => f (s - p)) z w = RectangleIntegral' f (z - p) (w - p) := by
simp_rw [RectangleIntegral', RectangleIntegral.translate]
lemma Complex.inv_re_add_im : (x + y * I)⁻¹ = (x - I * y) / (x ^ 2 + y ^ 2) := by
rw [Complex.inv_def, div_eq_mul_inv] ; congr <;> simp [conj_ofReal, normSq] <;> ring
lemma sq_add_sq_ne_zero (hy : y ≠ 0) : x ^ 2 + y ^ 2 ≠ 0 := by linarith [sq_nonneg x, (sq_pos_iff y).mpr hy]
lemma continuous_self_div_sq_add_sq (hy : y ≠ 0) : Continuous fun x => x / (x ^ 2 + y ^ 2) :=
continuous_id.div (continuous_id.pow 2 |>.add continuous_const) (λ _ => sq_add_sq_ne_zero hy)
lemma integral_self_div_sq_add_sq (hy : y ≠ 0) : ∫ x in x₁..x₂, x / (x ^ 2 + y ^ 2) =
Real.log (x₂ ^ 2 + y ^ 2) / 2 - Real.log (x₁ ^ 2 + y ^ 2) / 2 := by
let f (x : ℝ) : ℝ := Real.log (x ^ 2 + y ^ 2) / 2
have e1 {x} := HasDerivAt.add_const (by simpa using hasDerivAt_pow 2 x) (y ^ 2)
have e2 {x} : HasDerivAt f (x / (x ^ 2 + y ^ 2)) x := by
convert (e1.log (sq_add_sq_ne_zero hy)).div_const 2 using 1 ; field_simp ; ring
have e3 : deriv f = λ x => x / (x ^ 2 + y ^ 2) := funext (λ _ => e2.deriv)
have e4 : Continuous (deriv f) := by simpa only [e3] using continuous_self_div_sq_add_sq hy
simp_rw [← e2.deriv]
exact integral_deriv_eq_sub (λ _ _ => e2.differentiableAt) <| e4.intervalIntegrable _ _
lemma integral_const_div_sq_add_sq (hy : y ≠ 0) : ∫ x in x₁..x₂, y / (x ^ 2 + y ^ 2) =
arctan (x₂ / y) - arctan (x₁ / y) := by
nth_rewrite 1 [← div_mul_cancel₀ x₁ hy, ← div_mul_cancel₀ x₂ hy]
simp_rw [← mul_integral_comp_mul_right, ← integral_const_mul, ← integral_one_div_one_add_sq]
exact integral_congr <| λ x _ => by field_simp; ring
| lemma integral_const_div_self_add_im (hy : y ≠ 0) : ∫ x : ℝ in x₁..x₂, A / (x + y * I) =
A * (Real.log (x₂ ^ 2 + y ^ 2) / 2 - Real.log (x₁ ^ 2 + y ^ 2) / 2) -
A * I * (arctan (x₂ / y) - arctan (x₁ / y)) | integral_const_div_self_add_im | f36a520 20240122 | 1909a40 20240209 | PrimeNumberTheoremAnd/PrimeNumberTheoremAnd/ResidueCalcOnRectangles.lean | {
"lineInFile": 408,
"tokenPositionInFile": 22466,
"theoremPositionInFile": 48
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": ":= by\n have e1 {x : ℝ} : A / (x + y * I) = A * x / (x ^ 2 + y ^ 2) - A * I * y / (x ^ 2 + y ^ 2) := by\n ring_nf ; simp_rw [inv_re_add_im] ; ring\n have e2 : IntervalIntegrable (fun x ↦ A * x / (x ^ 2 + y ^ 2)) volume x₁ x₂ := by\n apply Continuous.intervalIntegrable\n simp_rw [mul_div_assoc] ; norm_cast\n exact continuous_const.mul <| continuous_ofReal.comp <| continuous_self_div_sq_add_sq hy\n have e3 : IntervalIntegrable (fun x ↦ A * I * y / (x ^ 2 + y ^ 2)) volume x₁ x₂ := by\n apply Continuous.intervalIntegrable\n refine continuous_const.div (by continuity) (λ x => ?_)\n norm_cast ; exact sq_add_sq_ne_zero hy\n simp_rw [integral_congr (λ _ _ => e1), integral_sub e2 e3, mul_div_assoc]\n norm_cast\n simp_rw [integral_const_mul, intervalIntegral.integral_ofReal, integral_self_div_sq_add_sq hy,\n integral_const_div_sq_add_sq hy]",
"proofType": "tactic",
"proofLengthLines": 14,
"proofLengthTokens": 858
} | prime |
import Mathlib.Analysis.Complex.CauchyIntegral
import Mathlib.Analysis.Complex.Convex
import Mathlib.Analysis.Complex.RemovableSingularity
import Mathlib.Analysis.Analytic.Meromorphic
import Mathlib.Analysis.SpecialFunctions.Integrals
import Mathlib.MeasureTheory.Measure.Lebesgue.Integral
import PrimeNumberTheoremAnd.Rectangle
open Complex BigOperators Nat Classical Real Topology Filter Set MeasureTheory intervalIntegral
open scoped Interval
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f g : ℂ → E}
{z w p c A : ℂ} {x x₁ x₂ y y₁ y₂ σ : ℝ}
noncomputable def HIntegral (f : ℂ → E) (x₁ x₂ y : ℝ) : E := ∫ x in x₁..x₂, f (x + y * I)
noncomputable def VIntegral (f : ℂ → E) (x y₁ y₂ : ℝ) : E := I • ∫ y in y₁..y₂, f (x + y * I)
noncomputable def HIntegral' (f : ℂ → E) (x₁ x₂ y : ℝ) : E := (1 / (2 * π * I)) • HIntegral f x₁ x₂ y
noncomputable def VIntegral' (f : ℂ → E) (x y₁ y₂ : ℝ) : E := (1 / (2 * π * I)) • VIntegral f x y₁ y₂
lemma HIntegral_symm : HIntegral f x₁ x₂ y = - HIntegral f x₂ x₁ y := integral_symm _ _
lemma VIntegral_symm : VIntegral f x y₁ y₂ = - VIntegral f x y₂ y₁ := by
simp_rw [VIntegral, integral_symm y₁ y₂, smul_neg, neg_neg]
/-%%
\begin{definition}[RectangleIntegral]\label{RectangleIntegral}\lean{RectangleIntegral}\leanok
A RectangleIntegral of a function $f$ is one over a rectangle determined by $z$ and $w$ in $\C$.
We will sometimes denote it by $\int_{z}^{w} f$. (There is also a primed version, which is $1/(2\pi i)$ times the original.)
\end{definition}
%%-/
/-- A `RectangleIntegral` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`. -/
noncomputable def RectangleIntegral (f : ℂ → E) (z w : ℂ) : E := HIntegral f z.re w.re z.im -
HIntegral f z.re w.re w.im + VIntegral f w.re z.im w.im - VIntegral f z.re z.im w.im
/-- A `RectangleIntegral'` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`, divided by `2 * π * I`. -/
noncomputable abbrev RectangleIntegral' (f : ℂ → E) (z w : ℂ) : E :=
(1 / (2 * π * I)) • RectangleIntegral f z w
/-% ** Wrong delimiter on purpose **
An UpperUIntegral is the integral of a function over a |\_| shape.
\begin{definition}\label{UpperUIntegral}\lean{UpperUIntegral}\leanok
An UpperUIntegral of a function $f$ comes from $\sigma+i\infty$ down to $\sigma+iT$, over to $\sigma'+iT$, and back up to $\sigma'+i\infty$.
\end{definition}
%-/
noncomputable def UpperUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' T +
I • (∫ y : ℝ in Ici T, f (σ' + y * I)) - I • (∫ y : ℝ in Ici T, f (σ + y * I))
/-% ** Wrong delimiter on purpose **
A LowerUIntegral is the integral of a function over a |-| shape.
\begin{definition}[LowerUIntegral]\label{LowerUIntegral}\lean{LowerUIntegral}\leanok
A LowerUIntegral of a function $f$ comes from $\sigma-i\infty$ up to $\sigma-iT$, over to $\sigma'-iT$, and back down to $\sigma'-i\infty$.
\end{definition}
%-/
noncomputable def LowerUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' (-T) -
I • (∫ y : ℝ in Iic (-T), f (σ' + y * I)) + I • (∫ y : ℝ in Iic (-T), f (σ + y * I))
/-%%
It is very convenient to define integrals along vertical lines in the complex plane, as follows.
\begin{definition}[VerticalIntegral]\label{VerticalIntegral}\lean{VerticalIntegral}\leanok
Let $f$ be a function from $\mathbb{C}$ to $\mathbb{C}$, and let $\sigma$ be a real number. Then we define
$$\int_{(\sigma)}f(s)ds = \int_{\sigma-i\infty}^{\sigma+i\infty}f(s)ds.$$
\end{definition}
%%-/
noncomputable def VerticalIntegral (f : ℂ → E) (σ : ℝ) : E := I • ∫ t : ℝ, f (σ + t * I)
--%% We also have a version with a factor of $1/(2\pi i)$.
noncomputable abbrev VerticalIntegral' (f : ℂ → E) (σ : ℝ) : E :=
(1 / (2 * π * I)) • VerticalIntegral f σ
lemma verticalIntegral_split_three (a b : ℝ) (hf : Integrable (fun t : ℝ ↦ f (σ + t * I))) :
VerticalIntegral f σ = I • (∫ t in Iic a, f (σ + t * I)) + VIntegral f σ a b
+ I • ∫ t in Ici b, f (σ + t * I) := by
simp_rw [VerticalIntegral, VIntegral, ← smul_add]
congr
rw [← intervalIntegral.integral_Iic_sub_Iic hf.restrict hf.restrict, add_sub_cancel,
integral_Iic_eq_integral_Iio, intervalIntegral.integral_Iio_add_Ici hf.restrict hf.restrict]
/-% ** Wrong delimiter on purpose **
\begin{lemma}[DiffVertRect_eq_UpperLowerUs]\label{DiffVertRect_eq_UpperLowerUs}\lean{DiffVertRect_eq_UpperLowerUs}\leanok
The difference of two vertical integrals and a rectangle is the difference of an upper and a lower U integrals.
\end{lemma}
%-/
lemma DiffVertRect_eq_UpperLowerUs {σ σ' T : ℝ}
(f_int_σ : Integrable (fun (t : ℝ) ↦ f (σ + t * I)))
(f_int_σ' : Integrable (fun (t : ℝ) ↦ f (σ' + t * I))) :
(VerticalIntegral f σ') - (VerticalIntegral f σ) - (RectangleIntegral f (σ - I * T) (σ' + I * T)) =
(UpperUIntegral f σ σ' T) - (LowerUIntegral f σ σ' T) := by
rw [verticalIntegral_split_three (-T) T f_int_σ, verticalIntegral_split_three (-T) T f_int_σ']
simp only [smul_eq_mul, RectangleIntegral, sub_re, ofReal_re, mul_re, I_re, zero_mul, I_im,
ofReal_im, mul_zero, sub_self, sub_zero, add_re, add_zero, sub_im, mul_im, one_mul, zero_add,
zero_sub, add_im, UpperUIntegral, LowerUIntegral]
abel
/-%
\begin{proof}\uses{UpperUIntegral, LowerUIntegral}\leanok
Follows directly from the definitions.
\end{proof}
%-/
/-- A function is `HolomorphicOn` a set if it is complex differentiable on that set. -/
abbrev HolomorphicOn (f : ℂ → E) (s : Set ℂ) : Prop := DifferentiableOn ℂ f s
/-%%
\begin{theorem}[existsDifferentiableOn_of_bddAbove]\label{existsDifferentiableOn_of_bddAbove}\lean{existsDifferentiableOn_of_bddAbove}\leanok
If $f$ is differentiable on a set $s$ except at $c\in s$, and $f$ is bounded above on $s\setminus\{c\}$, then there exists a differentiable function $g$ on $s$ such that $f$ and $g$ agree on $s\setminus\{c\}$.
\end{theorem}
%%-/
theorem existsDifferentiableOn_of_bddAbove [CompleteSpace E] {s : Set ℂ} {c : ℂ} (hc : s ∈ nhds c)
(hd : HolomorphicOn f (s \ {c})) (hb : BddAbove (norm ∘ f '' (s \ {c}))) :
∃ (g : ℂ → E), HolomorphicOn g s ∧ (Set.EqOn f g (s \ {c})) :=
⟨Function.update f c (limUnder (𝓝[{c}ᶜ] c) f),
differentiableOn_update_limUnder_of_bddAbove hc hd hb,
fun z hz ↦ if h : z = c then (hz.2 h).elim else by simp [h]⟩
/-%%
\begin{proof}\leanok
This is the Riemann Removable Singularity Theorem, slightly rephrased from what's in Mathlib. (We don't care what the function $g$ is, just that it's holomorphic.)
\end{proof}
%%-/
/-%%
\begin{theorem}[HolomorphicOn.vanishesOnRectangle]\label{HolomorphicOn.vanishesOnRectangle}\lean{HolomorphicOn.vanishesOnRectangle}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$, then the integral of $f$ over the rectangle with corners $z$ and $w$ is $0$.
\end{theorem}
%%-/
theorem HolomorphicOn.vanishesOnRectangle [CompleteSpace E] {U : Set ℂ}
(f_holo : HolomorphicOn f U) (hU : Rectangle z w ⊆ U) :
RectangleIntegral f z w = 0 :=
integral_boundary_rect_eq_zero_of_differentiableOn f z w (f_holo.mono hU)
/-%%
\begin{proof}\leanok
This is in a Mathlib PR.
\end{proof}
%%-/
theorem RectangleIntegral_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral f z w = RectangleIntegral g z w := by
unfold RectangleIntegral VIntegral
congr 2; swap; congr 1; swap; congr 1
all_goals refine intervalIntegral.integral_congr fun _ _ ↦ h ?_
· exact Or.inl <| Or.inl <| Or.inl ⟨by simpa, by simp⟩
· exact Or.inl <| Or.inr ⟨by simpa, by simp⟩
· exact Or.inr ⟨by simp, by simpa⟩
· exact Or.inl <| Or.inl <| Or.inr ⟨by simp, by simpa⟩
theorem RectangleIntegral'_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral' f z w = RectangleIntegral' g z w := by
rw [RectangleIntegral', RectangleIntegral_congr h]
theorem rectangleIntegral_symm (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f z w = RectangleIntegral f w z := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, intervalIntegral.integral_symm w.re,
intervalIntegral.integral_symm w.im, sub_neg_eq_add, smul_neg, sub_neg_eq_add, ← sub_eq_add_neg,
neg_add_eq_sub, sub_add_eq_add_sub]
theorem rectangleIntegral_symm_re (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f (w.re + z.im * I) (z.re + w.im * I) = - RectangleIntegral f z w := by
simp [RectangleIntegral, ← sub_eq_zero]
rw [HIntegral_symm (y := z.im), HIntegral_symm (y := w.im)]
abel
def RectangleBorderIntegrable (f : ℂ → E) (z w : ℂ) : Prop :=
IntervalIntegrable (fun x => f (x + z.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun x => f (x + w.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun y => f (w.re + y * I)) volume z.im w.im ∧
IntervalIntegrable (fun y => f (z.re + y * I)) volume z.im w.im
theorem RectangleBorderIntegrable.add {f g : ℂ → E} (hf : RectangleBorderIntegrable f z w)
(hg : RectangleBorderIntegrable g z w) :
RectangleIntegral (f + g) z w = RectangleIntegral f z w + RectangleIntegral g z w := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
rw [intervalIntegral.integral_add hf.1 hg.1, intervalIntegral.integral_add hf.2.1 hg.2.1,
intervalIntegral.integral_add hf.2.2.1 hg.2.2.1, intervalIntegral.integral_add hf.2.2.2 hg.2.2.2]
rw [← sub_eq_zero]
simp only [smul_add]; abel
theorem ContinuousOn.rectangleBorder_integrable (hf : ContinuousOn f (RectangleBorder z w)) :
RectangleBorderIntegrable f z w :=
⟨(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_re z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_re z w)).intervalIntegrable⟩
theorem ContinuousOn.rectangleBorderIntegrable (hf : ContinuousOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
(hf.mono (rectangleBorder_subset_rectangle z w)).rectangleBorder_integrable
theorem ContinuousOn.rectangleBorderNoPIntegrable (hf : ContinuousOn f (Rectangle z w \ {p}))
(pNotOnBorder : p ∉ RectangleBorder z w) : RectangleBorderIntegrable f z w := by
refine (hf.mono (Set.subset_diff.mpr ?_)).rectangleBorder_integrable
exact ⟨rectangleBorder_subset_rectangle z w, disjoint_singleton_right.mpr pNotOnBorder⟩
theorem HolomorphicOn.rectangleBorderIntegrable' (hf : HolomorphicOn f (Rectangle z w \ {p}))
(hp : Rectangle z w ∈ nhds p) : RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderNoPIntegrable (not_mem_rectangleBorder_of_rectangle_mem_nhds hp)
theorem HolomorphicOn.rectangleBorderIntegrable (hf : HolomorphicOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderIntegrable
/--
Given `x₀ a x₁ : ℝ`, and `y₀ y₁ : ℝ` and a function `f : ℂ → ℂ` so that
both `(t : ℝ) ↦ f(t + y₀ * I)` and `(t : ℝ) ↦ f(t + y₁ * I)` are integrable over both
`t ∈ Icc x₀ a` and `t ∈ Icc a x₁`, we have that
`RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I)` is the sum of
`RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I)` and
`RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I)`.
-/
lemma RectangleIntegralHSplit {a x₀ x₁ y₀ y₁ : ℝ}
(f_int_x₀_a_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume x₀ a)
(f_int_a_x₁_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume a x₁)
(f_int_x₀_a_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume x₀ a)
(f_int_a_x₁_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume a x₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_bot f_int_a_x₁_bot,
← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_top f_int_a_x₁_top]
abel
lemma RectangleIntegralHSplit' {a x₀ x₁ y₀ y₁ : ℝ} (ha : a ∈ [[x₀, x₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) :=
RectangleIntegralHSplit
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
lemma RectangleIntegralVSplit {b x₀ x₁ y₀ y₁ : ℝ}
(f_int_y₀_b_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume y₀ b)
(f_int_b_y₁_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume b y₁)
(f_int_y₀_b_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume y₀ b)
(f_int_b_y₁_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume b y₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_left f_int_b_y₁_left,
← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_right f_int_b_y₁_right, ← sub_eq_zero]
simp only [smul_add]; abel
lemma RectangleIntegralVSplit' {b x₀ x₁ y₀ y₁ : ℝ} (hb : b ∈ [[y₀, y₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) :=
RectangleIntegralVSplit
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
lemma RectanglePullToNhdOfPole' [CompleteSpace E] {z₀ z₁ z₂ z₃ p : ℂ}
(h_orientation : z₀.re ≤ z₃.re ∧ z₀.im ≤ z₃.im ∧ z₁.re ≤ z₂.re ∧ z₁.im ≤ z₂.im)
(hp : Rectangle z₁ z₂ ∈ 𝓝 p) (hz : Rectangle z₁ z₂ ⊆ Rectangle z₀ z₃)
(fHolo : HolomorphicOn f (Rectangle z₀ z₃ \ {p})) :
RectangleIntegral f z₀ z₃ = RectangleIntegral f z₁ z₂ := by
obtain ⟨hz₀_re, hz₀_im, hz₁_re, hz₁_im⟩ := h_orientation
have := rect_subset_iff.mp hz
rw [Rectangle, uIcc_of_le hz₀_re, uIcc_of_le hz₀_im] at this
obtain ⟨⟨⟨_, _⟩, ⟨_, _⟩⟩, ⟨_, _⟩, ⟨_, _⟩⟩ := this
obtain ⟨⟨_, _⟩, ⟨_, _⟩⟩ := (uIoo_of_le hz₁_re) ▸ (uIoo_of_le hz₁_im) ▸ rectangle_mem_nhds_iff.mp hp
obtain ⟨_, _, _, _⟩ := show p.re < z₂.re ∧ p.re < z₃.re ∧ p.im < z₂.im ∧ p.im < z₃.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
obtain ⟨_, _, _, _⟩ := show z₀.re < p.re ∧ z₁.re < p.re ∧ z₀.im < p.im ∧ z₁.im < p.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
have fCont := fHolo.continuousOn
have hbot : RectangleBorderIntegrable f (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have htop : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have hleft : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
have hright : RectangleBorderIntegrable f (↑z₁.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
all_goals try {
refine (fCont.mono (rectangleBorder_subset_punctured_rect ?_ ?_)).rectangleBorder_integrable
· simp_all
· simpa using ⟨by linarith, by linarith, by linarith, by linarith⟩
}
have hbot' : z₁.im ∈ [[z₀.im, z₃.im]] := ?_
have htop' : z₂.im ∈ [[z₁.im, z₃.im]] := ?_
have hleft' : z₁.re ∈ [[z₀.re, z₃.re]] := ?_
have hright' : z₂.re ∈ [[z₁.re, z₃.re]] := ?_
all_goals try { rw [Set.uIcc_of_le]; constructor; all_goals assumption }
have hbot'' : Rectangle (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₁.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have htop'' : Rectangle (↑z₀.re + ↑z₂.im * I) (↑z₃.re + ↑z₃.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hleft'' : Rectangle (↑z₀.re + ↑z₁.im * I) (↑z₁.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hright'' : Rectangle (↑z₂.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
all_goals try { apply rectangle_subset_punctured_rect <;> simp_all }
rw [← re_add_im z₀, ← re_add_im z₃,
RectangleIntegralVSplit' hbot' hbot, fHolo.vanishesOnRectangle hbot'', zero_add,
RectangleIntegralVSplit' htop' htop, fHolo.vanishesOnRectangle htop'', add_zero,
RectangleIntegralHSplit' hleft' hleft, fHolo.vanishesOnRectangle hleft'', zero_add,
RectangleIntegralHSplit' hright' hright, fHolo.vanishesOnRectangle hright'', add_zero,
re_add_im, re_add_im]
/-%%
The next lemma allows to zoom a big rectangle down to a small square, centered at a pole.
\begin{lemma}[RectanglePullToNhdOfPole]\label{RectanglePullToNhdOfPole}\lean{RectanglePullToNhdOfPole}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$ except at a point $p$, then the integral of $f$
over the rectangle with corners $z$ and $w$ is the same as the integral of $f$ over a small square
centered at $p$.
\end{lemma}
%%-/
/-- Given `f` holomorphic on a rectangle `z` and `w` except at a point `p`, the integral of `f` over
the rectangle with corners `z` and `w` is the same as the integral of `f` over a small square
centered at `p`. -/
lemma RectanglePullToNhdOfPole [CompleteSpace E] {z w p : ℂ} (zRe_lt_wRe : z.re ≤ w.re)
(zIm_lt_wIm : z.im ≤ w.im) (hp : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral f z w = RectangleIntegral f (-c - I * c + p) (c + I * c + p) := by
/-%%
\begin{proof}\uses{HolomorphicOn.vanishesOnRectangle}\leanok
Chop the big rectangle with two vertical cuts and two horizontal cuts into smaller rectangles,
the middle one being the desired square. The integral over each of the outer rectangles
vanishes, since $f$ is holomorphic there. (The constant $c$ being ``small enough'' here just means
that the inner square is strictly contained in the big rectangle.)
%%-/
filter_upwards [Ioo_mem_nhdsWithin_Ioi' zero_lt_one, SmallSquareInRectangle hp]
intro c ⟨cpos, _⟩ hc
simp_rw [mul_comm I]
exact RectanglePullToNhdOfPole' (by simp_all [cpos.le])
(square_mem_nhds p (ne_of_gt cpos)) hc fHolo
--%%\end{proof}
lemma RectanglePullToNhdOfPole'' [CompleteSpace E] {z w p : ℂ} (zRe_le_wRe : z.re ≤ w.re)
(zIm_le_wIm : z.im ≤ w.im) (pInRectInterior : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral' f z w = RectangleIntegral' f (-c - I * c + p) (c + I * c + p) := by
filter_upwards [RectanglePullToNhdOfPole zRe_le_wRe zIm_le_wIm pInRectInterior fHolo] with c h
simp_rw [RectangleIntegral', h]
theorem ResidueTheoremAtOrigin_aux1c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y + I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux1c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y - I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (-1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem RectangleIntegral.const_smul (f : ℂ → E) (z w c : ℂ) :
RectangleIntegral (fun s => c • f s) z w = c • RectangleIntegral f z w := by
simp [RectangleIntegral, HIntegral, VIntegral, smul_add, smul_sub, smul_smul, mul_comm]
theorem RectangleIntegral.const_mul' (f : ℂ → E) (z w c : ℂ) :
RectangleIntegral' (fun s => c • f s) z w = c • RectangleIntegral' f z w := by
simp [RectangleIntegral', RectangleIntegral.const_smul, smul_smul] ; ring_nf
theorem RectangleIntegral.translate (f : ℂ → E) (z w p : ℂ) :
RectangleIntegral (fun s => f (s - p)) z w = RectangleIntegral f (z - p) (w - p) := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, sub_re, sub_im, ← intervalIntegral.integral_comp_sub_right]
congr <;> ext <;> congr 1 <;> simp [Complex.ext_iff]
theorem RectangleIntegral.translate' (f : ℂ → E) (z w p : ℂ) :
RectangleIntegral' (fun s => f (s - p)) z w = RectangleIntegral' f (z - p) (w - p) := by
simp_rw [RectangleIntegral', RectangleIntegral.translate]
lemma Complex.inv_re_add_im : (x + y * I)⁻¹ = (x - I * y) / (x ^ 2 + y ^ 2) := by
rw [Complex.inv_def, div_eq_mul_inv] ; congr <;> simp [conj_ofReal, normSq] <;> ring
lemma sq_add_sq_ne_zero (hy : y ≠ 0) : x ^ 2 + y ^ 2 ≠ 0 := by linarith [sq_nonneg x, (sq_pos_iff y).mpr hy]
lemma continuous_self_div_sq_add_sq (hy : y ≠ 0) : Continuous fun x => x / (x ^ 2 + y ^ 2) :=
continuous_id.div (continuous_id.pow 2 |>.add continuous_const) (λ _ => sq_add_sq_ne_zero hy)
lemma integral_self_div_sq_add_sq (hy : y ≠ 0) : ∫ x in x₁..x₂, x / (x ^ 2 + y ^ 2) =
Real.log (x₂ ^ 2 + y ^ 2) / 2 - Real.log (x₁ ^ 2 + y ^ 2) / 2 := by
let f (x : ℝ) : ℝ := Real.log (x ^ 2 + y ^ 2) / 2
have e1 {x} := HasDerivAt.add_const (by simpa using hasDerivAt_pow 2 x) (y ^ 2)
have e2 {x} : HasDerivAt f (x / (x ^ 2 + y ^ 2)) x := by
convert (e1.log (sq_add_sq_ne_zero hy)).div_const 2 using 1 ; field_simp ; ring
have e3 : deriv f = λ x => x / (x ^ 2 + y ^ 2) := funext (λ _ => e2.deriv)
have e4 : Continuous (deriv f) := by simpa only [e3] using continuous_self_div_sq_add_sq hy
simp_rw [← e2.deriv]
exact integral_deriv_eq_sub (λ _ _ => e2.differentiableAt) <| e4.intervalIntegrable _ _
lemma integral_const_div_sq_add_sq (hy : y ≠ 0) : ∫ x in x₁..x₂, y / (x ^ 2 + y ^ 2) =
arctan (x₂ / y) - arctan (x₁ / y) := by
nth_rewrite 1 [← div_mul_cancel₀ x₁ hy, ← div_mul_cancel₀ x₂ hy]
simp_rw [← mul_integral_comp_mul_right, ← integral_const_mul, ← integral_one_div_one_add_sq]
exact integral_congr <| λ x _ => by field_simp; ring
lemma integral_const_div_self_add_im (hy : y ≠ 0) : ∫ x : ℝ in x₁..x₂, A / (x + y * I) =
A * (Real.log (x₂ ^ 2 + y ^ 2) / 2 - Real.log (x₁ ^ 2 + y ^ 2) / 2) -
A * I * (arctan (x₂ / y) - arctan (x₁ / y)) := by
have e1 {x : ℝ} : A / (x + y * I) = A * x / (x ^ 2 + y ^ 2) - A * I * y / (x ^ 2 + y ^ 2) := by
ring_nf ; simp_rw [inv_re_add_im] ; ring
have e2 : IntervalIntegrable (fun x ↦ A * x / (x ^ 2 + y ^ 2)) volume x₁ x₂ := by
apply Continuous.intervalIntegrable
simp_rw [mul_div_assoc] ; norm_cast
exact continuous_const.mul <| continuous_ofReal.comp <| continuous_self_div_sq_add_sq hy
have e3 : IntervalIntegrable (fun x ↦ A * I * y / (x ^ 2 + y ^ 2)) volume x₁ x₂ := by
apply Continuous.intervalIntegrable
refine continuous_const.div (by continuity) (λ x => ?_)
norm_cast ; exact sq_add_sq_ne_zero hy
simp_rw [integral_congr (λ _ _ => e1), integral_sub e2 e3, mul_div_assoc]
norm_cast
simp_rw [integral_const_mul, intervalIntegral.integral_ofReal, integral_self_div_sq_add_sq hy,
integral_const_div_sq_add_sq hy]
| lemma integral_const_div_re_add_self (hx : x ≠ 0) : ∫ y : ℝ in y₁..y₂, A / (x + y * I) =
A / I * (Real.log (y₂ ^ 2 + (-x) ^ 2) / 2 - Real.log (y₁ ^ 2 + (-x) ^ 2) / 2) -
A / I * I * (arctan (y₂ / -x) - arctan (y₁ / -x)) | integral_const_div_re_add_self | f36a520 20240122 | 1909a40 20240209 | PrimeNumberTheoremAnd/PrimeNumberTheoremAnd/ResidueCalcOnRectangles.lean | {
"lineInFile": 426,
"tokenPositionInFile": 23537,
"theoremPositionInFile": 49
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": ":= by\n have l1 {y : ℝ} : A / (x + y * I) = A / I / (y + ↑(-x) * I) := by\n have e1 : x + y * I ≠ 0 := by contrapose! hx ; simpa using congr_arg re hx\n have e2 : y + -(x * I) ≠ 0 := by contrapose! hx ; simpa using congr_arg im hx\n field_simp ; ring_nf ; simp\n have l2 : -x ≠ 0 := by rwa [neg_ne_zero]\n simp_rw [l1, integral_const_div_self_add_im l2]",
"proofType": "tactic",
"proofLengthLines": 6,
"proofLengthTokens": 359
} | prime |
import Mathlib.Analysis.Complex.CauchyIntegral
import Mathlib.Analysis.Complex.Convex
import Mathlib.Analysis.Complex.RemovableSingularity
import Mathlib.Analysis.Analytic.Meromorphic
import Mathlib.Analysis.SpecialFunctions.Integrals
import Mathlib.MeasureTheory.Measure.Lebesgue.Integral
import PrimeNumberTheoremAnd.Rectangle
open Complex BigOperators Nat Classical Real Topology Filter Set MeasureTheory intervalIntegral
open scoped Interval
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f g : ℂ → E}
{z w p c A : ℂ} {x x₁ x₂ y y₁ y₂ σ : ℝ}
noncomputable def HIntegral (f : ℂ → E) (x₁ x₂ y : ℝ) : E := ∫ x in x₁..x₂, f (x + y * I)
noncomputable def VIntegral (f : ℂ → E) (x y₁ y₂ : ℝ) : E := I • ∫ y in y₁..y₂, f (x + y * I)
noncomputable def HIntegral' (f : ℂ → E) (x₁ x₂ y : ℝ) : E := (1 / (2 * π * I)) • HIntegral f x₁ x₂ y
noncomputable def VIntegral' (f : ℂ → E) (x y₁ y₂ : ℝ) : E := (1 / (2 * π * I)) • VIntegral f x y₁ y₂
lemma HIntegral_symm : HIntegral f x₁ x₂ y = - HIntegral f x₂ x₁ y := integral_symm _ _
lemma VIntegral_symm : VIntegral f x y₁ y₂ = - VIntegral f x y₂ y₁ := by
simp_rw [VIntegral, integral_symm y₁ y₂, smul_neg, neg_neg]
/-%%
\begin{definition}[RectangleIntegral]\label{RectangleIntegral}\lean{RectangleIntegral}\leanok
A RectangleIntegral of a function $f$ is one over a rectangle determined by $z$ and $w$ in $\C$.
We will sometimes denote it by $\int_{z}^{w} f$. (There is also a primed version, which is $1/(2\pi i)$ times the original.)
\end{definition}
%%-/
/-- A `RectangleIntegral` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`. -/
noncomputable def RectangleIntegral (f : ℂ → E) (z w : ℂ) : E := HIntegral f z.re w.re z.im -
HIntegral f z.re w.re w.im + VIntegral f w.re z.im w.im - VIntegral f z.re z.im w.im
/-- A `RectangleIntegral'` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`, divided by `2 * π * I`. -/
noncomputable abbrev RectangleIntegral' (f : ℂ → E) (z w : ℂ) : E :=
(1 / (2 * π * I)) • RectangleIntegral f z w
/-% ** Wrong delimiter on purpose **
An UpperUIntegral is the integral of a function over a |\_| shape.
\begin{definition}\label{UpperUIntegral}\lean{UpperUIntegral}\leanok
An UpperUIntegral of a function $f$ comes from $\sigma+i\infty$ down to $\sigma+iT$, over to $\sigma'+iT$, and back up to $\sigma'+i\infty$.
\end{definition}
%-/
noncomputable def UpperUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' T +
I • (∫ y : ℝ in Ici T, f (σ' + y * I)) - I • (∫ y : ℝ in Ici T, f (σ + y * I))
/-% ** Wrong delimiter on purpose **
A LowerUIntegral is the integral of a function over a |-| shape.
\begin{definition}[LowerUIntegral]\label{LowerUIntegral}\lean{LowerUIntegral}\leanok
A LowerUIntegral of a function $f$ comes from $\sigma-i\infty$ up to $\sigma-iT$, over to $\sigma'-iT$, and back down to $\sigma'-i\infty$.
\end{definition}
%-/
noncomputable def LowerUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' (-T) -
I • (∫ y : ℝ in Iic (-T), f (σ' + y * I)) + I • (∫ y : ℝ in Iic (-T), f (σ + y * I))
/-%%
It is very convenient to define integrals along vertical lines in the complex plane, as follows.
\begin{definition}[VerticalIntegral]\label{VerticalIntegral}\lean{VerticalIntegral}\leanok
Let $f$ be a function from $\mathbb{C}$ to $\mathbb{C}$, and let $\sigma$ be a real number. Then we define
$$\int_{(\sigma)}f(s)ds = \int_{\sigma-i\infty}^{\sigma+i\infty}f(s)ds.$$
\end{definition}
%%-/
noncomputable def VerticalIntegral (f : ℂ → E) (σ : ℝ) : E := I • ∫ t : ℝ, f (σ + t * I)
--%% We also have a version with a factor of $1/(2\pi i)$.
noncomputable abbrev VerticalIntegral' (f : ℂ → E) (σ : ℝ) : E :=
(1 / (2 * π * I)) • VerticalIntegral f σ
lemma verticalIntegral_split_three (a b : ℝ) (hf : Integrable (fun t : ℝ ↦ f (σ + t * I))) :
VerticalIntegral f σ = I • (∫ t in Iic a, f (σ + t * I)) + VIntegral f σ a b
+ I • ∫ t in Ici b, f (σ + t * I) := by
simp_rw [VerticalIntegral, VIntegral, ← smul_add]
congr
rw [← intervalIntegral.integral_Iic_sub_Iic hf.restrict hf.restrict, add_sub_cancel,
integral_Iic_eq_integral_Iio, intervalIntegral.integral_Iio_add_Ici hf.restrict hf.restrict]
/-% ** Wrong delimiter on purpose **
\begin{lemma}[DiffVertRect_eq_UpperLowerUs]\label{DiffVertRect_eq_UpperLowerUs}\lean{DiffVertRect_eq_UpperLowerUs}\leanok
The difference of two vertical integrals and a rectangle is the difference of an upper and a lower U integrals.
\end{lemma}
%-/
lemma DiffVertRect_eq_UpperLowerUs {σ σ' T : ℝ}
(f_int_σ : Integrable (fun (t : ℝ) ↦ f (σ + t * I)))
(f_int_σ' : Integrable (fun (t : ℝ) ↦ f (σ' + t * I))) :
(VerticalIntegral f σ') - (VerticalIntegral f σ) - (RectangleIntegral f (σ - I * T) (σ' + I * T)) =
(UpperUIntegral f σ σ' T) - (LowerUIntegral f σ σ' T) := by
rw [verticalIntegral_split_three (-T) T f_int_σ, verticalIntegral_split_three (-T) T f_int_σ']
simp only [smul_eq_mul, RectangleIntegral, sub_re, ofReal_re, mul_re, I_re, zero_mul, I_im,
ofReal_im, mul_zero, sub_self, sub_zero, add_re, add_zero, sub_im, mul_im, one_mul, zero_add,
zero_sub, add_im, UpperUIntegral, LowerUIntegral]
abel
/-%
\begin{proof}\uses{UpperUIntegral, LowerUIntegral}\leanok
Follows directly from the definitions.
\end{proof}
%-/
/-- A function is `HolomorphicOn` a set if it is complex differentiable on that set. -/
abbrev HolomorphicOn (f : ℂ → E) (s : Set ℂ) : Prop := DifferentiableOn ℂ f s
/-%%
\begin{theorem}[existsDifferentiableOn_of_bddAbove]\label{existsDifferentiableOn_of_bddAbove}\lean{existsDifferentiableOn_of_bddAbove}\leanok
If $f$ is differentiable on a set $s$ except at $c\in s$, and $f$ is bounded above on $s\setminus\{c\}$, then there exists a differentiable function $g$ on $s$ such that $f$ and $g$ agree on $s\setminus\{c\}$.
\end{theorem}
%%-/
theorem existsDifferentiableOn_of_bddAbove [CompleteSpace E] {s : Set ℂ} {c : ℂ} (hc : s ∈ nhds c)
(hd : HolomorphicOn f (s \ {c})) (hb : BddAbove (norm ∘ f '' (s \ {c}))) :
∃ (g : ℂ → E), HolomorphicOn g s ∧ (Set.EqOn f g (s \ {c})) :=
⟨Function.update f c (limUnder (𝓝[{c}ᶜ] c) f),
differentiableOn_update_limUnder_of_bddAbove hc hd hb,
fun z hz ↦ if h : z = c then (hz.2 h).elim else by simp [h]⟩
/-%%
\begin{proof}\leanok
This is the Riemann Removable Singularity Theorem, slightly rephrased from what's in Mathlib. (We don't care what the function $g$ is, just that it's holomorphic.)
\end{proof}
%%-/
/-%%
\begin{theorem}[HolomorphicOn.vanishesOnRectangle]\label{HolomorphicOn.vanishesOnRectangle}\lean{HolomorphicOn.vanishesOnRectangle}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$, then the integral of $f$ over the rectangle with corners $z$ and $w$ is $0$.
\end{theorem}
%%-/
theorem HolomorphicOn.vanishesOnRectangle [CompleteSpace E] {U : Set ℂ}
(f_holo : HolomorphicOn f U) (hU : Rectangle z w ⊆ U) :
RectangleIntegral f z w = 0 :=
integral_boundary_rect_eq_zero_of_differentiableOn f z w (f_holo.mono hU)
/-%%
\begin{proof}\leanok
This is in a Mathlib PR.
\end{proof}
%%-/
theorem RectangleIntegral_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral f z w = RectangleIntegral g z w := by
unfold RectangleIntegral VIntegral
congr 2; swap; congr 1; swap; congr 1
all_goals refine intervalIntegral.integral_congr fun _ _ ↦ h ?_
· exact Or.inl <| Or.inl <| Or.inl ⟨by simpa, by simp⟩
· exact Or.inl <| Or.inr ⟨by simpa, by simp⟩
· exact Or.inr ⟨by simp, by simpa⟩
· exact Or.inl <| Or.inl <| Or.inr ⟨by simp, by simpa⟩
theorem RectangleIntegral'_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral' f z w = RectangleIntegral' g z w := by
rw [RectangleIntegral', RectangleIntegral_congr h]
theorem rectangleIntegral_symm (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f z w = RectangleIntegral f w z := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, intervalIntegral.integral_symm w.re,
intervalIntegral.integral_symm w.im, sub_neg_eq_add, smul_neg, sub_neg_eq_add, ← sub_eq_add_neg,
neg_add_eq_sub, sub_add_eq_add_sub]
theorem rectangleIntegral_symm_re (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f (w.re + z.im * I) (z.re + w.im * I) = - RectangleIntegral f z w := by
simp [RectangleIntegral, ← sub_eq_zero]
rw [HIntegral_symm (y := z.im), HIntegral_symm (y := w.im)]
abel
def RectangleBorderIntegrable (f : ℂ → E) (z w : ℂ) : Prop :=
IntervalIntegrable (fun x => f (x + z.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun x => f (x + w.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun y => f (w.re + y * I)) volume z.im w.im ∧
IntervalIntegrable (fun y => f (z.re + y * I)) volume z.im w.im
theorem RectangleBorderIntegrable.add {f g : ℂ → E} (hf : RectangleBorderIntegrable f z w)
(hg : RectangleBorderIntegrable g z w) :
RectangleIntegral (f + g) z w = RectangleIntegral f z w + RectangleIntegral g z w := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
rw [intervalIntegral.integral_add hf.1 hg.1, intervalIntegral.integral_add hf.2.1 hg.2.1,
intervalIntegral.integral_add hf.2.2.1 hg.2.2.1, intervalIntegral.integral_add hf.2.2.2 hg.2.2.2]
rw [← sub_eq_zero]
simp only [smul_add]; abel
theorem ContinuousOn.rectangleBorder_integrable (hf : ContinuousOn f (RectangleBorder z w)) :
RectangleBorderIntegrable f z w :=
⟨(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_re z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_re z w)).intervalIntegrable⟩
theorem ContinuousOn.rectangleBorderIntegrable (hf : ContinuousOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
(hf.mono (rectangleBorder_subset_rectangle z w)).rectangleBorder_integrable
theorem ContinuousOn.rectangleBorderNoPIntegrable (hf : ContinuousOn f (Rectangle z w \ {p}))
(pNotOnBorder : p ∉ RectangleBorder z w) : RectangleBorderIntegrable f z w := by
refine (hf.mono (Set.subset_diff.mpr ?_)).rectangleBorder_integrable
exact ⟨rectangleBorder_subset_rectangle z w, disjoint_singleton_right.mpr pNotOnBorder⟩
theorem HolomorphicOn.rectangleBorderIntegrable' (hf : HolomorphicOn f (Rectangle z w \ {p}))
(hp : Rectangle z w ∈ nhds p) : RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderNoPIntegrable (not_mem_rectangleBorder_of_rectangle_mem_nhds hp)
theorem HolomorphicOn.rectangleBorderIntegrable (hf : HolomorphicOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderIntegrable
/--
Given `x₀ a x₁ : ℝ`, and `y₀ y₁ : ℝ` and a function `f : ℂ → ℂ` so that
both `(t : ℝ) ↦ f(t + y₀ * I)` and `(t : ℝ) ↦ f(t + y₁ * I)` are integrable over both
`t ∈ Icc x₀ a` and `t ∈ Icc a x₁`, we have that
`RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I)` is the sum of
`RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I)` and
`RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I)`.
-/
lemma RectangleIntegralHSplit {a x₀ x₁ y₀ y₁ : ℝ}
(f_int_x₀_a_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume x₀ a)
(f_int_a_x₁_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume a x₁)
(f_int_x₀_a_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume x₀ a)
(f_int_a_x₁_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume a x₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_bot f_int_a_x₁_bot,
← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_top f_int_a_x₁_top]
abel
lemma RectangleIntegralHSplit' {a x₀ x₁ y₀ y₁ : ℝ} (ha : a ∈ [[x₀, x₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) :=
RectangleIntegralHSplit
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
lemma RectangleIntegralVSplit {b x₀ x₁ y₀ y₁ : ℝ}
(f_int_y₀_b_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume y₀ b)
(f_int_b_y₁_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume b y₁)
(f_int_y₀_b_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume y₀ b)
(f_int_b_y₁_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume b y₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_left f_int_b_y₁_left,
← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_right f_int_b_y₁_right, ← sub_eq_zero]
simp only [smul_add]; abel
lemma RectangleIntegralVSplit' {b x₀ x₁ y₀ y₁ : ℝ} (hb : b ∈ [[y₀, y₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) :=
RectangleIntegralVSplit
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
lemma RectanglePullToNhdOfPole' [CompleteSpace E] {z₀ z₁ z₂ z₃ p : ℂ}
(h_orientation : z₀.re ≤ z₃.re ∧ z₀.im ≤ z₃.im ∧ z₁.re ≤ z₂.re ∧ z₁.im ≤ z₂.im)
(hp : Rectangle z₁ z₂ ∈ 𝓝 p) (hz : Rectangle z₁ z₂ ⊆ Rectangle z₀ z₃)
(fHolo : HolomorphicOn f (Rectangle z₀ z₃ \ {p})) :
RectangleIntegral f z₀ z₃ = RectangleIntegral f z₁ z₂ := by
obtain ⟨hz₀_re, hz₀_im, hz₁_re, hz₁_im⟩ := h_orientation
have := rect_subset_iff.mp hz
rw [Rectangle, uIcc_of_le hz₀_re, uIcc_of_le hz₀_im] at this
obtain ⟨⟨⟨_, _⟩, ⟨_, _⟩⟩, ⟨_, _⟩, ⟨_, _⟩⟩ := this
obtain ⟨⟨_, _⟩, ⟨_, _⟩⟩ := (uIoo_of_le hz₁_re) ▸ (uIoo_of_le hz₁_im) ▸ rectangle_mem_nhds_iff.mp hp
obtain ⟨_, _, _, _⟩ := show p.re < z₂.re ∧ p.re < z₃.re ∧ p.im < z₂.im ∧ p.im < z₃.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
obtain ⟨_, _, _, _⟩ := show z₀.re < p.re ∧ z₁.re < p.re ∧ z₀.im < p.im ∧ z₁.im < p.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
have fCont := fHolo.continuousOn
have hbot : RectangleBorderIntegrable f (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have htop : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have hleft : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
have hright : RectangleBorderIntegrable f (↑z₁.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
all_goals try {
refine (fCont.mono (rectangleBorder_subset_punctured_rect ?_ ?_)).rectangleBorder_integrable
· simp_all
· simpa using ⟨by linarith, by linarith, by linarith, by linarith⟩
}
have hbot' : z₁.im ∈ [[z₀.im, z₃.im]] := ?_
have htop' : z₂.im ∈ [[z₁.im, z₃.im]] := ?_
have hleft' : z₁.re ∈ [[z₀.re, z₃.re]] := ?_
have hright' : z₂.re ∈ [[z₁.re, z₃.re]] := ?_
all_goals try { rw [Set.uIcc_of_le]; constructor; all_goals assumption }
have hbot'' : Rectangle (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₁.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have htop'' : Rectangle (↑z₀.re + ↑z₂.im * I) (↑z₃.re + ↑z₃.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hleft'' : Rectangle (↑z₀.re + ↑z₁.im * I) (↑z₁.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hright'' : Rectangle (↑z₂.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
all_goals try { apply rectangle_subset_punctured_rect <;> simp_all }
rw [← re_add_im z₀, ← re_add_im z₃,
RectangleIntegralVSplit' hbot' hbot, fHolo.vanishesOnRectangle hbot'', zero_add,
RectangleIntegralVSplit' htop' htop, fHolo.vanishesOnRectangle htop'', add_zero,
RectangleIntegralHSplit' hleft' hleft, fHolo.vanishesOnRectangle hleft'', zero_add,
RectangleIntegralHSplit' hright' hright, fHolo.vanishesOnRectangle hright'', add_zero,
re_add_im, re_add_im]
/-%%
The next lemma allows to zoom a big rectangle down to a small square, centered at a pole.
\begin{lemma}[RectanglePullToNhdOfPole]\label{RectanglePullToNhdOfPole}\lean{RectanglePullToNhdOfPole}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$ except at a point $p$, then the integral of $f$
over the rectangle with corners $z$ and $w$ is the same as the integral of $f$ over a small square
centered at $p$.
\end{lemma}
%%-/
/-- Given `f` holomorphic on a rectangle `z` and `w` except at a point `p`, the integral of `f` over
the rectangle with corners `z` and `w` is the same as the integral of `f` over a small square
centered at `p`. -/
lemma RectanglePullToNhdOfPole [CompleteSpace E] {z w p : ℂ} (zRe_lt_wRe : z.re ≤ w.re)
(zIm_lt_wIm : z.im ≤ w.im) (hp : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral f z w = RectangleIntegral f (-c - I * c + p) (c + I * c + p) := by
/-%%
\begin{proof}\uses{HolomorphicOn.vanishesOnRectangle}\leanok
Chop the big rectangle with two vertical cuts and two horizontal cuts into smaller rectangles,
the middle one being the desired square. The integral over each of the outer rectangles
vanishes, since $f$ is holomorphic there. (The constant $c$ being ``small enough'' here just means
that the inner square is strictly contained in the big rectangle.)
%%-/
filter_upwards [Ioo_mem_nhdsWithin_Ioi' zero_lt_one, SmallSquareInRectangle hp]
intro c ⟨cpos, _⟩ hc
simp_rw [mul_comm I]
exact RectanglePullToNhdOfPole' (by simp_all [cpos.le])
(square_mem_nhds p (ne_of_gt cpos)) hc fHolo
--%%\end{proof}
lemma RectanglePullToNhdOfPole'' [CompleteSpace E] {z w p : ℂ} (zRe_le_wRe : z.re ≤ w.re)
(zIm_le_wIm : z.im ≤ w.im) (pInRectInterior : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral' f z w = RectangleIntegral' f (-c - I * c + p) (c + I * c + p) := by
filter_upwards [RectanglePullToNhdOfPole zRe_le_wRe zIm_le_wIm pInRectInterior fHolo] with c h
simp_rw [RectangleIntegral', h]
theorem ResidueTheoremAtOrigin_aux1c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y + I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux1c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y - I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (-1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem RectangleIntegral.const_smul (f : ℂ → E) (z w c : ℂ) :
RectangleIntegral (fun s => c • f s) z w = c • RectangleIntegral f z w := by
simp [RectangleIntegral, HIntegral, VIntegral, smul_add, smul_sub, smul_smul, mul_comm]
theorem RectangleIntegral.const_mul' (f : ℂ → E) (z w c : ℂ) :
RectangleIntegral' (fun s => c • f s) z w = c • RectangleIntegral' f z w := by
simp [RectangleIntegral', RectangleIntegral.const_smul, smul_smul] ; ring_nf
theorem RectangleIntegral.translate (f : ℂ → E) (z w p : ℂ) :
RectangleIntegral (fun s => f (s - p)) z w = RectangleIntegral f (z - p) (w - p) := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, sub_re, sub_im, ← intervalIntegral.integral_comp_sub_right]
congr <;> ext <;> congr 1 <;> simp [Complex.ext_iff]
theorem RectangleIntegral.translate' (f : ℂ → E) (z w p : ℂ) :
RectangleIntegral' (fun s => f (s - p)) z w = RectangleIntegral' f (z - p) (w - p) := by
simp_rw [RectangleIntegral', RectangleIntegral.translate]
lemma Complex.inv_re_add_im : (x + y * I)⁻¹ = (x - I * y) / (x ^ 2 + y ^ 2) := by
rw [Complex.inv_def, div_eq_mul_inv] ; congr <;> simp [conj_ofReal, normSq] <;> ring
lemma sq_add_sq_ne_zero (hy : y ≠ 0) : x ^ 2 + y ^ 2 ≠ 0 := by linarith [sq_nonneg x, (sq_pos_iff y).mpr hy]
lemma continuous_self_div_sq_add_sq (hy : y ≠ 0) : Continuous fun x => x / (x ^ 2 + y ^ 2) :=
continuous_id.div (continuous_id.pow 2 |>.add continuous_const) (λ _ => sq_add_sq_ne_zero hy)
lemma integral_self_div_sq_add_sq (hy : y ≠ 0) : ∫ x in x₁..x₂, x / (x ^ 2 + y ^ 2) =
Real.log (x₂ ^ 2 + y ^ 2) / 2 - Real.log (x₁ ^ 2 + y ^ 2) / 2 := by
let f (x : ℝ) : ℝ := Real.log (x ^ 2 + y ^ 2) / 2
have e1 {x} := HasDerivAt.add_const (by simpa using hasDerivAt_pow 2 x) (y ^ 2)
have e2 {x} : HasDerivAt f (x / (x ^ 2 + y ^ 2)) x := by
convert (e1.log (sq_add_sq_ne_zero hy)).div_const 2 using 1 ; field_simp ; ring
have e3 : deriv f = λ x => x / (x ^ 2 + y ^ 2) := funext (λ _ => e2.deriv)
have e4 : Continuous (deriv f) := by simpa only [e3] using continuous_self_div_sq_add_sq hy
simp_rw [← e2.deriv]
exact integral_deriv_eq_sub (λ _ _ => e2.differentiableAt) <| e4.intervalIntegrable _ _
lemma integral_const_div_sq_add_sq (hy : y ≠ 0) : ∫ x in x₁..x₂, y / (x ^ 2 + y ^ 2) =
arctan (x₂ / y) - arctan (x₁ / y) := by
nth_rewrite 1 [← div_mul_cancel₀ x₁ hy, ← div_mul_cancel₀ x₂ hy]
simp_rw [← mul_integral_comp_mul_right, ← integral_const_mul, ← integral_one_div_one_add_sq]
exact integral_congr <| λ x _ => by field_simp; ring
lemma integral_const_div_self_add_im (hy : y ≠ 0) : ∫ x : ℝ in x₁..x₂, A / (x + y * I) =
A * (Real.log (x₂ ^ 2 + y ^ 2) / 2 - Real.log (x₁ ^ 2 + y ^ 2) / 2) -
A * I * (arctan (x₂ / y) - arctan (x₁ / y)) := by
have e1 {x : ℝ} : A / (x + y * I) = A * x / (x ^ 2 + y ^ 2) - A * I * y / (x ^ 2 + y ^ 2) := by
ring_nf ; simp_rw [inv_re_add_im] ; ring
have e2 : IntervalIntegrable (fun x ↦ A * x / (x ^ 2 + y ^ 2)) volume x₁ x₂ := by
apply Continuous.intervalIntegrable
simp_rw [mul_div_assoc] ; norm_cast
exact continuous_const.mul <| continuous_ofReal.comp <| continuous_self_div_sq_add_sq hy
have e3 : IntervalIntegrable (fun x ↦ A * I * y / (x ^ 2 + y ^ 2)) volume x₁ x₂ := by
apply Continuous.intervalIntegrable
refine continuous_const.div (by continuity) (λ x => ?_)
norm_cast ; exact sq_add_sq_ne_zero hy
simp_rw [integral_congr (λ _ _ => e1), integral_sub e2 e3, mul_div_assoc]
norm_cast
simp_rw [integral_const_mul, intervalIntegral.integral_ofReal, integral_self_div_sq_add_sq hy,
integral_const_div_sq_add_sq hy]
lemma integral_const_div_re_add_self (hx : x ≠ 0) : ∫ y : ℝ in y₁..y₂, A / (x + y * I) =
A / I * (Real.log (y₂ ^ 2 + (-x) ^ 2) / 2 - Real.log (y₁ ^ 2 + (-x) ^ 2) / 2) -
A / I * I * (arctan (y₂ / -x) - arctan (y₁ / -x)) := by
have l1 {y : ℝ} : A / (x + y * I) = A / I / (y + ↑(-x) * I) := by
have e1 : x + y * I ≠ 0 := by contrapose! hx ; simpa using congr_arg re hx
have e2 : y + -(x * I) ≠ 0 := by contrapose! hx ; simpa using congr_arg im hx
field_simp ; ring_nf ; simp
have l2 : -x ≠ 0 := by rwa [neg_ne_zero]
simp_rw [l1, integral_const_div_self_add_im l2]
| lemma ResidueTheoremAtOrigin' {z w c : ℂ} (h1 : z.re < 0) (h2 : z.im < 0) (h3 : 0 < w.re) (h4 : 0 < w.im) :
RectangleIntegral (λ s => c / s) z w = 2 * I * π * c | ResidueTheoremAtOrigin' | f36a520 20240122 | 1909a40 20240209 | PrimeNumberTheoremAnd/PrimeNumberTheoremAnd/ResidueCalcOnRectangles.lean | {
"lineInFile": 436,
"tokenPositionInFile": 24125,
"theoremPositionInFile": 50
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": ":= by\n simp only [RectangleIntegral, HIntegral, VIntegral, smul_eq_mul]\n rw [integral_const_div_re_add_self h1.ne, integral_const_div_re_add_self h3.ne.symm]\n rw [integral_const_div_self_add_im h2.ne, integral_const_div_self_add_im h4.ne.symm]\n have l1 : z.im * w.re⁻¹ = (w.re * z.im⁻¹)⁻¹ := by group\n have l3 := arctan_inv_of_neg <| mul_neg_of_pos_of_neg h3 <| inv_lt_zero.mpr h2\n have l4 : w.im * z.re⁻¹ = (z.re * w.im⁻¹)⁻¹ := by group\n have l6 := arctan_inv_of_neg <| mul_neg_of_neg_of_pos h1 <| inv_pos.mpr h4\n have r1 : z.im * z.re⁻¹ = (z.re * z.im⁻¹)⁻¹ := by group\n have r3 := arctan_inv_of_pos <| mul_pos_of_neg_of_neg h1 <| inv_lt_zero.mpr h2\n have r4 : w.im * w.re⁻¹ = (w.re * w.im⁻¹)⁻¹ := by group\n have r6 := arctan_inv_of_pos <| mul_pos h3 <| inv_pos.mpr h4\n ring_nf\n simp only [one_div, inv_I, mul_neg, neg_mul, I_sq, one_mul, neg_neg, arctan_neg, ofReal_neg, sub_neg_eq_add]\n rw [l1, l3, l4, l6, r1, r3, r4, r6]\n ring_nf\n simp only [I_sq, ofReal_sub, ofReal_mul, ofReal_ofNat, ofReal_div, ofReal_neg, ofReal_one]\n ring_nf",
"proofType": "tactic",
"proofLengthLines": 17,
"proofLengthTokens": 1052
} | prime |
import Mathlib.Analysis.Complex.CauchyIntegral
import Mathlib.Analysis.Complex.Convex
import Mathlib.Analysis.Complex.RemovableSingularity
import Mathlib.Analysis.Analytic.Meromorphic
import Mathlib.Analysis.SpecialFunctions.Integrals
import Mathlib.MeasureTheory.Measure.Lebesgue.Integral
import PrimeNumberTheoremAnd.Rectangle
open Complex BigOperators Nat Classical Real Topology Filter Set MeasureTheory intervalIntegral
open scoped Interval
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f g : ℂ → E}
{z w p c A : ℂ} {x x₁ x₂ y y₁ y₂ σ : ℝ}
noncomputable def HIntegral (f : ℂ → E) (x₁ x₂ y : ℝ) : E := ∫ x in x₁..x₂, f (x + y * I)
noncomputable def VIntegral (f : ℂ → E) (x y₁ y₂ : ℝ) : E := I • ∫ y in y₁..y₂, f (x + y * I)
noncomputable def HIntegral' (f : ℂ → E) (x₁ x₂ y : ℝ) : E := (1 / (2 * π * I)) • HIntegral f x₁ x₂ y
noncomputable def VIntegral' (f : ℂ → E) (x y₁ y₂ : ℝ) : E := (1 / (2 * π * I)) • VIntegral f x y₁ y₂
lemma HIntegral_symm : HIntegral f x₁ x₂ y = - HIntegral f x₂ x₁ y := integral_symm _ _
lemma VIntegral_symm : VIntegral f x y₁ y₂ = - VIntegral f x y₂ y₁ := by
simp_rw [VIntegral, integral_symm y₁ y₂, smul_neg, neg_neg]
/-%%
\begin{definition}[RectangleIntegral]\label{RectangleIntegral}\lean{RectangleIntegral}\leanok
A RectangleIntegral of a function $f$ is one over a rectangle determined by $z$ and $w$ in $\C$.
We will sometimes denote it by $\int_{z}^{w} f$. (There is also a primed version, which is $1/(2\pi i)$ times the original.)
\end{definition}
%%-/
/-- A `RectangleIntegral` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`. -/
noncomputable def RectangleIntegral (f : ℂ → E) (z w : ℂ) : E := HIntegral f z.re w.re z.im -
HIntegral f z.re w.re w.im + VIntegral f w.re z.im w.im - VIntegral f z.re z.im w.im
/-- A `RectangleIntegral'` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`, divided by `2 * π * I`. -/
noncomputable abbrev RectangleIntegral' (f : ℂ → E) (z w : ℂ) : E :=
(1 / (2 * π * I)) • RectangleIntegral f z w
/-% ** Wrong delimiter on purpose **
An UpperUIntegral is the integral of a function over a |\_| shape.
\begin{definition}\label{UpperUIntegral}\lean{UpperUIntegral}\leanok
An UpperUIntegral of a function $f$ comes from $\sigma+i\infty$ down to $\sigma+iT$, over to $\sigma'+iT$, and back up to $\sigma'+i\infty$.
\end{definition}
%-/
noncomputable def UpperUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' T +
I • (∫ y : ℝ in Ici T, f (σ' + y * I)) - I • (∫ y : ℝ in Ici T, f (σ + y * I))
/-% ** Wrong delimiter on purpose **
A LowerUIntegral is the integral of a function over a |-| shape.
\begin{definition}[LowerUIntegral]\label{LowerUIntegral}\lean{LowerUIntegral}\leanok
A LowerUIntegral of a function $f$ comes from $\sigma-i\infty$ up to $\sigma-iT$, over to $\sigma'-iT$, and back down to $\sigma'-i\infty$.
\end{definition}
%-/
noncomputable def LowerUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' (-T) -
I • (∫ y : ℝ in Iic (-T), f (σ' + y * I)) + I • (∫ y : ℝ in Iic (-T), f (σ + y * I))
/-%%
It is very convenient to define integrals along vertical lines in the complex plane, as follows.
\begin{definition}[VerticalIntegral]\label{VerticalIntegral}\lean{VerticalIntegral}\leanok
Let $f$ be a function from $\mathbb{C}$ to $\mathbb{C}$, and let $\sigma$ be a real number. Then we define
$$\int_{(\sigma)}f(s)ds = \int_{\sigma-i\infty}^{\sigma+i\infty}f(s)ds.$$
\end{definition}
%%-/
noncomputable def VerticalIntegral (f : ℂ → E) (σ : ℝ) : E := I • ∫ t : ℝ, f (σ + t * I)
--%% We also have a version with a factor of $1/(2\pi i)$.
noncomputable abbrev VerticalIntegral' (f : ℂ → E) (σ : ℝ) : E :=
(1 / (2 * π * I)) • VerticalIntegral f σ
lemma verticalIntegral_split_three (a b : ℝ) (hf : Integrable (fun t : ℝ ↦ f (σ + t * I))) :
VerticalIntegral f σ = I • (∫ t in Iic a, f (σ + t * I)) + VIntegral f σ a b
+ I • ∫ t in Ici b, f (σ + t * I) := by
simp_rw [VerticalIntegral, VIntegral, ← smul_add]
congr
rw [← intervalIntegral.integral_Iic_sub_Iic hf.restrict hf.restrict, add_sub_cancel,
integral_Iic_eq_integral_Iio, intervalIntegral.integral_Iio_add_Ici hf.restrict hf.restrict]
/-% ** Wrong delimiter on purpose **
\begin{lemma}[DiffVertRect_eq_UpperLowerUs]\label{DiffVertRect_eq_UpperLowerUs}\lean{DiffVertRect_eq_UpperLowerUs}\leanok
The difference of two vertical integrals and a rectangle is the difference of an upper and a lower U integrals.
\end{lemma}
%-/
lemma DiffVertRect_eq_UpperLowerUs {σ σ' T : ℝ}
(f_int_σ : Integrable (fun (t : ℝ) ↦ f (σ + t * I)))
(f_int_σ' : Integrable (fun (t : ℝ) ↦ f (σ' + t * I))) :
(VerticalIntegral f σ') - (VerticalIntegral f σ) - (RectangleIntegral f (σ - I * T) (σ' + I * T)) =
(UpperUIntegral f σ σ' T) - (LowerUIntegral f σ σ' T) := by
rw [verticalIntegral_split_three (-T) T f_int_σ, verticalIntegral_split_three (-T) T f_int_σ']
simp only [smul_eq_mul, RectangleIntegral, sub_re, ofReal_re, mul_re, I_re, zero_mul, I_im,
ofReal_im, mul_zero, sub_self, sub_zero, add_re, add_zero, sub_im, mul_im, one_mul, zero_add,
zero_sub, add_im, UpperUIntegral, LowerUIntegral]
abel
/-%
\begin{proof}\uses{UpperUIntegral, LowerUIntegral}\leanok
Follows directly from the definitions.
\end{proof}
%-/
/-- A function is `HolomorphicOn` a set if it is complex differentiable on that set. -/
abbrev HolomorphicOn (f : ℂ → E) (s : Set ℂ) : Prop := DifferentiableOn ℂ f s
/-%%
\begin{theorem}[existsDifferentiableOn_of_bddAbove]\label{existsDifferentiableOn_of_bddAbove}\lean{existsDifferentiableOn_of_bddAbove}\leanok
If $f$ is differentiable on a set $s$ except at $c\in s$, and $f$ is bounded above on $s\setminus\{c\}$, then there exists a differentiable function $g$ on $s$ such that $f$ and $g$ agree on $s\setminus\{c\}$.
\end{theorem}
%%-/
theorem existsDifferentiableOn_of_bddAbove [CompleteSpace E] {s : Set ℂ} {c : ℂ} (hc : s ∈ nhds c)
(hd : HolomorphicOn f (s \ {c})) (hb : BddAbove (norm ∘ f '' (s \ {c}))) :
∃ (g : ℂ → E), HolomorphicOn g s ∧ (Set.EqOn f g (s \ {c})) :=
⟨Function.update f c (limUnder (𝓝[{c}ᶜ] c) f),
differentiableOn_update_limUnder_of_bddAbove hc hd hb,
fun z hz ↦ if h : z = c then (hz.2 h).elim else by simp [h]⟩
/-%%
\begin{proof}\leanok
This is the Riemann Removable Singularity Theorem, slightly rephrased from what's in Mathlib. (We don't care what the function $g$ is, just that it's holomorphic.)
\end{proof}
%%-/
/-%%
\begin{theorem}[HolomorphicOn.vanishesOnRectangle]\label{HolomorphicOn.vanishesOnRectangle}\lean{HolomorphicOn.vanishesOnRectangle}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$, then the integral of $f$ over the rectangle with corners $z$ and $w$ is $0$.
\end{theorem}
%%-/
theorem HolomorphicOn.vanishesOnRectangle [CompleteSpace E] {U : Set ℂ}
(f_holo : HolomorphicOn f U) (hU : Rectangle z w ⊆ U) :
RectangleIntegral f z w = 0 :=
integral_boundary_rect_eq_zero_of_differentiableOn f z w (f_holo.mono hU)
/-%%
\begin{proof}\leanok
This is in a Mathlib PR.
\end{proof}
%%-/
theorem RectangleIntegral_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral f z w = RectangleIntegral g z w := by
unfold RectangleIntegral VIntegral
congr 2; swap; congr 1; swap; congr 1
all_goals refine intervalIntegral.integral_congr fun _ _ ↦ h ?_
· exact Or.inl <| Or.inl <| Or.inl ⟨by simpa, by simp⟩
· exact Or.inl <| Or.inr ⟨by simpa, by simp⟩
· exact Or.inr ⟨by simp, by simpa⟩
· exact Or.inl <| Or.inl <| Or.inr ⟨by simp, by simpa⟩
theorem RectangleIntegral'_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral' f z w = RectangleIntegral' g z w := by
rw [RectangleIntegral', RectangleIntegral_congr h]
theorem rectangleIntegral_symm (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f z w = RectangleIntegral f w z := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, intervalIntegral.integral_symm w.re,
intervalIntegral.integral_symm w.im, sub_neg_eq_add, smul_neg, sub_neg_eq_add, ← sub_eq_add_neg,
neg_add_eq_sub, sub_add_eq_add_sub]
theorem rectangleIntegral_symm_re (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f (w.re + z.im * I) (z.re + w.im * I) = - RectangleIntegral f z w := by
simp [RectangleIntegral, ← sub_eq_zero]
rw [HIntegral_symm (y := z.im), HIntegral_symm (y := w.im)]
abel
def RectangleBorderIntegrable (f : ℂ → E) (z w : ℂ) : Prop :=
IntervalIntegrable (fun x => f (x + z.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun x => f (x + w.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun y => f (w.re + y * I)) volume z.im w.im ∧
IntervalIntegrable (fun y => f (z.re + y * I)) volume z.im w.im
theorem RectangleBorderIntegrable.add {f g : ℂ → E} (hf : RectangleBorderIntegrable f z w)
(hg : RectangleBorderIntegrable g z w) :
RectangleIntegral (f + g) z w = RectangleIntegral f z w + RectangleIntegral g z w := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
rw [intervalIntegral.integral_add hf.1 hg.1, intervalIntegral.integral_add hf.2.1 hg.2.1,
intervalIntegral.integral_add hf.2.2.1 hg.2.2.1, intervalIntegral.integral_add hf.2.2.2 hg.2.2.2]
rw [← sub_eq_zero]
simp only [smul_add]; abel
theorem ContinuousOn.rectangleBorder_integrable (hf : ContinuousOn f (RectangleBorder z w)) :
RectangleBorderIntegrable f z w :=
⟨(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_re z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_re z w)).intervalIntegrable⟩
theorem ContinuousOn.rectangleBorderIntegrable (hf : ContinuousOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
(hf.mono (rectangleBorder_subset_rectangle z w)).rectangleBorder_integrable
theorem ContinuousOn.rectangleBorderNoPIntegrable (hf : ContinuousOn f (Rectangle z w \ {p}))
(pNotOnBorder : p ∉ RectangleBorder z w) : RectangleBorderIntegrable f z w := by
refine (hf.mono (Set.subset_diff.mpr ?_)).rectangleBorder_integrable
exact ⟨rectangleBorder_subset_rectangle z w, disjoint_singleton_right.mpr pNotOnBorder⟩
theorem HolomorphicOn.rectangleBorderIntegrable' (hf : HolomorphicOn f (Rectangle z w \ {p}))
(hp : Rectangle z w ∈ nhds p) : RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderNoPIntegrable (not_mem_rectangleBorder_of_rectangle_mem_nhds hp)
theorem HolomorphicOn.rectangleBorderIntegrable (hf : HolomorphicOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderIntegrable
/--
Given `x₀ a x₁ : ℝ`, and `y₀ y₁ : ℝ` and a function `f : ℂ → ℂ` so that
both `(t : ℝ) ↦ f(t + y₀ * I)` and `(t : ℝ) ↦ f(t + y₁ * I)` are integrable over both
`t ∈ Icc x₀ a` and `t ∈ Icc a x₁`, we have that
`RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I)` is the sum of
`RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I)` and
`RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I)`.
-/
lemma RectangleIntegralHSplit {a x₀ x₁ y₀ y₁ : ℝ}
(f_int_x₀_a_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume x₀ a)
(f_int_a_x₁_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume a x₁)
(f_int_x₀_a_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume x₀ a)
(f_int_a_x₁_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume a x₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_bot f_int_a_x₁_bot,
← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_top f_int_a_x₁_top]
abel
lemma RectangleIntegralHSplit' {a x₀ x₁ y₀ y₁ : ℝ} (ha : a ∈ [[x₀, x₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) :=
RectangleIntegralHSplit
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
lemma RectangleIntegralVSplit {b x₀ x₁ y₀ y₁ : ℝ}
(f_int_y₀_b_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume y₀ b)
(f_int_b_y₁_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume b y₁)
(f_int_y₀_b_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume y₀ b)
(f_int_b_y₁_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume b y₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_left f_int_b_y₁_left,
← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_right f_int_b_y₁_right, ← sub_eq_zero]
simp only [smul_add]; abel
lemma RectangleIntegralVSplit' {b x₀ x₁ y₀ y₁ : ℝ} (hb : b ∈ [[y₀, y₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) :=
RectangleIntegralVSplit
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
lemma RectanglePullToNhdOfPole' [CompleteSpace E] {z₀ z₁ z₂ z₃ p : ℂ}
(h_orientation : z₀.re ≤ z₃.re ∧ z₀.im ≤ z₃.im ∧ z₁.re ≤ z₂.re ∧ z₁.im ≤ z₂.im)
(hp : Rectangle z₁ z₂ ∈ 𝓝 p) (hz : Rectangle z₁ z₂ ⊆ Rectangle z₀ z₃)
(fHolo : HolomorphicOn f (Rectangle z₀ z₃ \ {p})) :
RectangleIntegral f z₀ z₃ = RectangleIntegral f z₁ z₂ := by
obtain ⟨hz₀_re, hz₀_im, hz₁_re, hz₁_im⟩ := h_orientation
have := rect_subset_iff.mp hz
rw [Rectangle, uIcc_of_le hz₀_re, uIcc_of_le hz₀_im] at this
obtain ⟨⟨⟨_, _⟩, ⟨_, _⟩⟩, ⟨_, _⟩, ⟨_, _⟩⟩ := this
obtain ⟨⟨_, _⟩, ⟨_, _⟩⟩ := (uIoo_of_le hz₁_re) ▸ (uIoo_of_le hz₁_im) ▸ rectangle_mem_nhds_iff.mp hp
obtain ⟨_, _, _, _⟩ := show p.re < z₂.re ∧ p.re < z₃.re ∧ p.im < z₂.im ∧ p.im < z₃.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
obtain ⟨_, _, _, _⟩ := show z₀.re < p.re ∧ z₁.re < p.re ∧ z₀.im < p.im ∧ z₁.im < p.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
have fCont := fHolo.continuousOn
have hbot : RectangleBorderIntegrable f (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have htop : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have hleft : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
have hright : RectangleBorderIntegrable f (↑z₁.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
all_goals try {
refine (fCont.mono (rectangleBorder_subset_punctured_rect ?_ ?_)).rectangleBorder_integrable
· simp_all
· simpa using ⟨by linarith, by linarith, by linarith, by linarith⟩
}
have hbot' : z₁.im ∈ [[z₀.im, z₃.im]] := ?_
have htop' : z₂.im ∈ [[z₁.im, z₃.im]] := ?_
have hleft' : z₁.re ∈ [[z₀.re, z₃.re]] := ?_
have hright' : z₂.re ∈ [[z₁.re, z₃.re]] := ?_
all_goals try { rw [Set.uIcc_of_le]; constructor; all_goals assumption }
have hbot'' : Rectangle (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₁.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have htop'' : Rectangle (↑z₀.re + ↑z₂.im * I) (↑z₃.re + ↑z₃.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hleft'' : Rectangle (↑z₀.re + ↑z₁.im * I) (↑z₁.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hright'' : Rectangle (↑z₂.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
all_goals try { apply rectangle_subset_punctured_rect <;> simp_all }
rw [← re_add_im z₀, ← re_add_im z₃,
RectangleIntegralVSplit' hbot' hbot, fHolo.vanishesOnRectangle hbot'', zero_add,
RectangleIntegralVSplit' htop' htop, fHolo.vanishesOnRectangle htop'', add_zero,
RectangleIntegralHSplit' hleft' hleft, fHolo.vanishesOnRectangle hleft'', zero_add,
RectangleIntegralHSplit' hright' hright, fHolo.vanishesOnRectangle hright'', add_zero,
re_add_im, re_add_im]
/-%%
The next lemma allows to zoom a big rectangle down to a small square, centered at a pole.
\begin{lemma}[RectanglePullToNhdOfPole]\label{RectanglePullToNhdOfPole}\lean{RectanglePullToNhdOfPole}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$ except at a point $p$, then the integral of $f$
over the rectangle with corners $z$ and $w$ is the same as the integral of $f$ over a small square
centered at $p$.
\end{lemma}
%%-/
/-- Given `f` holomorphic on a rectangle `z` and `w` except at a point `p`, the integral of `f` over
the rectangle with corners `z` and `w` is the same as the integral of `f` over a small square
centered at `p`. -/
lemma RectanglePullToNhdOfPole [CompleteSpace E] {z w p : ℂ} (zRe_lt_wRe : z.re ≤ w.re)
(zIm_lt_wIm : z.im ≤ w.im) (hp : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral f z w = RectangleIntegral f (-c - I * c + p) (c + I * c + p) := by
/-%%
\begin{proof}\uses{HolomorphicOn.vanishesOnRectangle}\leanok
Chop the big rectangle with two vertical cuts and two horizontal cuts into smaller rectangles,
the middle one being the desired square. The integral over each of the outer rectangles
vanishes, since $f$ is holomorphic there. (The constant $c$ being ``small enough'' here just means
that the inner square is strictly contained in the big rectangle.)
%%-/
filter_upwards [Ioo_mem_nhdsWithin_Ioi' zero_lt_one, SmallSquareInRectangle hp]
intro c ⟨cpos, _⟩ hc
simp_rw [mul_comm I]
exact RectanglePullToNhdOfPole' (by simp_all [cpos.le])
(square_mem_nhds p (ne_of_gt cpos)) hc fHolo
--%%\end{proof}
lemma RectanglePullToNhdOfPole'' [CompleteSpace E] {z w p : ℂ} (zRe_le_wRe : z.re ≤ w.re)
(zIm_le_wIm : z.im ≤ w.im) (pInRectInterior : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral' f z w = RectangleIntegral' f (-c - I * c + p) (c + I * c + p) := by
filter_upwards [RectanglePullToNhdOfPole zRe_le_wRe zIm_le_wIm pInRectInterior fHolo] with c h
simp_rw [RectangleIntegral', h]
theorem ResidueTheoremAtOrigin_aux1c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y + I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux1c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y - I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (-1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem RectangleIntegral.const_smul (f : ℂ → E) (z w c : ℂ) :
RectangleIntegral (fun s => c • f s) z w = c • RectangleIntegral f z w := by
simp [RectangleIntegral, HIntegral, VIntegral, smul_add, smul_sub, smul_smul, mul_comm]
theorem RectangleIntegral.const_mul' (f : ℂ → E) (z w c : ℂ) :
RectangleIntegral' (fun s => c • f s) z w = c • RectangleIntegral' f z w := by
simp [RectangleIntegral', RectangleIntegral.const_smul, smul_smul] ; ring_nf
theorem RectangleIntegral.translate (f : ℂ → E) (z w p : ℂ) :
RectangleIntegral (fun s => f (s - p)) z w = RectangleIntegral f (z - p) (w - p) := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, sub_re, sub_im, ← intervalIntegral.integral_comp_sub_right]
congr <;> ext <;> congr 1 <;> simp [Complex.ext_iff]
theorem RectangleIntegral.translate' (f : ℂ → E) (z w p : ℂ) :
RectangleIntegral' (fun s => f (s - p)) z w = RectangleIntegral' f (z - p) (w - p) := by
simp_rw [RectangleIntegral', RectangleIntegral.translate]
lemma Complex.inv_re_add_im : (x + y * I)⁻¹ = (x - I * y) / (x ^ 2 + y ^ 2) := by
rw [Complex.inv_def, div_eq_mul_inv] ; congr <;> simp [conj_ofReal, normSq] <;> ring
lemma sq_add_sq_ne_zero (hy : y ≠ 0) : x ^ 2 + y ^ 2 ≠ 0 := by linarith [sq_nonneg x, (sq_pos_iff y).mpr hy]
lemma continuous_self_div_sq_add_sq (hy : y ≠ 0) : Continuous fun x => x / (x ^ 2 + y ^ 2) :=
continuous_id.div (continuous_id.pow 2 |>.add continuous_const) (λ _ => sq_add_sq_ne_zero hy)
lemma integral_self_div_sq_add_sq (hy : y ≠ 0) : ∫ x in x₁..x₂, x / (x ^ 2 + y ^ 2) =
Real.log (x₂ ^ 2 + y ^ 2) / 2 - Real.log (x₁ ^ 2 + y ^ 2) / 2 := by
let f (x : ℝ) : ℝ := Real.log (x ^ 2 + y ^ 2) / 2
have e1 {x} := HasDerivAt.add_const (by simpa using hasDerivAt_pow 2 x) (y ^ 2)
have e2 {x} : HasDerivAt f (x / (x ^ 2 + y ^ 2)) x := by
convert (e1.log (sq_add_sq_ne_zero hy)).div_const 2 using 1 ; field_simp ; ring
have e3 : deriv f = λ x => x / (x ^ 2 + y ^ 2) := funext (λ _ => e2.deriv)
have e4 : Continuous (deriv f) := by simpa only [e3] using continuous_self_div_sq_add_sq hy
simp_rw [← e2.deriv]
exact integral_deriv_eq_sub (λ _ _ => e2.differentiableAt) <| e4.intervalIntegrable _ _
lemma integral_const_div_sq_add_sq (hy : y ≠ 0) : ∫ x in x₁..x₂, y / (x ^ 2 + y ^ 2) =
arctan (x₂ / y) - arctan (x₁ / y) := by
nth_rewrite 1 [← div_mul_cancel₀ x₁ hy, ← div_mul_cancel₀ x₂ hy]
simp_rw [← mul_integral_comp_mul_right, ← integral_const_mul, ← integral_one_div_one_add_sq]
exact integral_congr <| λ x _ => by field_simp; ring
lemma integral_const_div_self_add_im (hy : y ≠ 0) : ∫ x : ℝ in x₁..x₂, A / (x + y * I) =
A * (Real.log (x₂ ^ 2 + y ^ 2) / 2 - Real.log (x₁ ^ 2 + y ^ 2) / 2) -
A * I * (arctan (x₂ / y) - arctan (x₁ / y)) := by
have e1 {x : ℝ} : A / (x + y * I) = A * x / (x ^ 2 + y ^ 2) - A * I * y / (x ^ 2 + y ^ 2) := by
ring_nf ; simp_rw [inv_re_add_im] ; ring
have e2 : IntervalIntegrable (fun x ↦ A * x / (x ^ 2 + y ^ 2)) volume x₁ x₂ := by
apply Continuous.intervalIntegrable
simp_rw [mul_div_assoc] ; norm_cast
exact continuous_const.mul <| continuous_ofReal.comp <| continuous_self_div_sq_add_sq hy
have e3 : IntervalIntegrable (fun x ↦ A * I * y / (x ^ 2 + y ^ 2)) volume x₁ x₂ := by
apply Continuous.intervalIntegrable
refine continuous_const.div (by continuity) (λ x => ?_)
norm_cast ; exact sq_add_sq_ne_zero hy
simp_rw [integral_congr (λ _ _ => e1), integral_sub e2 e3, mul_div_assoc]
norm_cast
simp_rw [integral_const_mul, intervalIntegral.integral_ofReal, integral_self_div_sq_add_sq hy,
integral_const_div_sq_add_sq hy]
lemma integral_const_div_re_add_self (hx : x ≠ 0) : ∫ y : ℝ in y₁..y₂, A / (x + y * I) =
A / I * (Real.log (y₂ ^ 2 + (-x) ^ 2) / 2 - Real.log (y₁ ^ 2 + (-x) ^ 2) / 2) -
A / I * I * (arctan (y₂ / -x) - arctan (y₁ / -x)) := by
have l1 {y : ℝ} : A / (x + y * I) = A / I / (y + ↑(-x) * I) := by
have e1 : x + y * I ≠ 0 := by contrapose! hx ; simpa using congr_arg re hx
have e2 : y + -(x * I) ≠ 0 := by contrapose! hx ; simpa using congr_arg im hx
field_simp ; ring_nf ; simp
have l2 : -x ≠ 0 := by rwa [neg_ne_zero]
simp_rw [l1, integral_const_div_self_add_im l2]
lemma ResidueTheoremAtOrigin' {z w c : ℂ} (h1 : z.re < 0) (h2 : z.im < 0) (h3 : 0 < w.re) (h4 : 0 < w.im) :
RectangleIntegral (λ s => c / s) z w = 2 * I * π * c := by
simp only [RectangleIntegral, HIntegral, VIntegral, smul_eq_mul]
rw [integral_const_div_re_add_self h1.ne, integral_const_div_re_add_self h3.ne.symm]
rw [integral_const_div_self_add_im h2.ne, integral_const_div_self_add_im h4.ne.symm]
have l1 : z.im * w.re⁻¹ = (w.re * z.im⁻¹)⁻¹ := by group
have l3 := arctan_inv_of_neg <| mul_neg_of_pos_of_neg h3 <| inv_lt_zero.mpr h2
have l4 : w.im * z.re⁻¹ = (z.re * w.im⁻¹)⁻¹ := by group
have l6 := arctan_inv_of_neg <| mul_neg_of_neg_of_pos h1 <| inv_pos.mpr h4
have r1 : z.im * z.re⁻¹ = (z.re * z.im⁻¹)⁻¹ := by group
have r3 := arctan_inv_of_pos <| mul_pos_of_neg_of_neg h1 <| inv_lt_zero.mpr h2
have r4 : w.im * w.re⁻¹ = (w.re * w.im⁻¹)⁻¹ := by group
have r6 := arctan_inv_of_pos <| mul_pos h3 <| inv_pos.mpr h4
ring_nf
simp only [one_div, inv_I, mul_neg, neg_mul, I_sq, one_mul, neg_neg, arctan_neg, ofReal_neg, sub_neg_eq_add]
rw [l1, l3, l4, l6, r1, r3, r4, r6]
ring_nf
simp only [I_sq, ofReal_sub, ofReal_mul, ofReal_ofNat, ofReal_div, ofReal_neg, ofReal_one]
ring_nf
| theorem ResidueTheoremInRectangle (zRe_le_wRe : z.re ≤ w.re) (zIm_le_wIm : z.im ≤ w.im)
(pInRectInterior : Rectangle z w ∈ 𝓝 p) : RectangleIntegral' (λ s => c / (s - p)) z w = c | ResidueTheoremInRectangle | f36a520 20240122 | 1909a40 20240209 | PrimeNumberTheoremAnd/PrimeNumberTheoremAnd/ResidueCalcOnRectangles.lean | {
"lineInFile": 456,
"tokenPositionInFile": 25344,
"theoremPositionInFile": 51
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": ":= by\n simp [rectangle_mem_nhds_iff, mem_reProdIm, uIoo_of_le zRe_le_wRe, uIoo_of_le zIm_le_wIm]\n at pInRectInterior\n rw [RectangleIntegral.translate', RectangleIntegral']\n have : 1 / (2 * ↑π * I) * (2 * I * ↑π * c) = c := by field_simp [two_pi_I_ne_zero] ; ring\n rwa [ResidueTheoremAtOrigin'] ; all_goals { simp [*] }",
"proofType": "tactic",
"proofLengthLines": 5,
"proofLengthTokens": 325
} | prime |
import Mathlib.Analysis.Complex.CauchyIntegral
import Mathlib.Analysis.Complex.Convex
import Mathlib.Analysis.Complex.RemovableSingularity
import Mathlib.Analysis.Analytic.Meromorphic
import Mathlib.Analysis.SpecialFunctions.Integrals
import Mathlib.MeasureTheory.Measure.Lebesgue.Integral
import PrimeNumberTheoremAnd.Rectangle
open Complex BigOperators Nat Classical Real Topology Filter Set MeasureTheory intervalIntegral
open scoped Interval
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f g : ℂ → E}
{z w p c A : ℂ} {x x₁ x₂ y y₁ y₂ σ : ℝ}
noncomputable def HIntegral (f : ℂ → E) (x₁ x₂ y : ℝ) : E := ∫ x in x₁..x₂, f (x + y * I)
noncomputable def VIntegral (f : ℂ → E) (x y₁ y₂ : ℝ) : E := I • ∫ y in y₁..y₂, f (x + y * I)
noncomputable def HIntegral' (f : ℂ → E) (x₁ x₂ y : ℝ) : E := (1 / (2 * π * I)) • HIntegral f x₁ x₂ y
noncomputable def VIntegral' (f : ℂ → E) (x y₁ y₂ : ℝ) : E := (1 / (2 * π * I)) • VIntegral f x y₁ y₂
lemma HIntegral_symm : HIntegral f x₁ x₂ y = - HIntegral f x₂ x₁ y := integral_symm _ _
lemma VIntegral_symm : VIntegral f x y₁ y₂ = - VIntegral f x y₂ y₁ := by
simp_rw [VIntegral, integral_symm y₁ y₂, smul_neg, neg_neg]
/-%%
\begin{definition}[RectangleIntegral]\label{RectangleIntegral}\lean{RectangleIntegral}\leanok
A RectangleIntegral of a function $f$ is one over a rectangle determined by $z$ and $w$ in $\C$.
We will sometimes denote it by $\int_{z}^{w} f$. (There is also a primed version, which is $1/(2\pi i)$ times the original.)
\end{definition}
%%-/
/-- A `RectangleIntegral` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`. -/
noncomputable def RectangleIntegral (f : ℂ → E) (z w : ℂ) : E := HIntegral f z.re w.re z.im -
HIntegral f z.re w.re w.im + VIntegral f w.re z.im w.im - VIntegral f z.re z.im w.im
/-- A `RectangleIntegral'` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`, divided by `2 * π * I`. -/
noncomputable abbrev RectangleIntegral' (f : ℂ → E) (z w : ℂ) : E :=
(1 / (2 * π * I)) • RectangleIntegral f z w
/-% ** Wrong delimiter on purpose **
An UpperUIntegral is the integral of a function over a |\_| shape.
\begin{definition}\label{UpperUIntegral}\lean{UpperUIntegral}\leanok
An UpperUIntegral of a function $f$ comes from $\sigma+i\infty$ down to $\sigma+iT$, over to $\sigma'+iT$, and back up to $\sigma'+i\infty$.
\end{definition}
%-/
noncomputable def UpperUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' T +
I • (∫ y : ℝ in Ici T, f (σ' + y * I)) - I • (∫ y : ℝ in Ici T, f (σ + y * I))
/-% ** Wrong delimiter on purpose **
A LowerUIntegral is the integral of a function over a |-| shape.
\begin{definition}[LowerUIntegral]\label{LowerUIntegral}\lean{LowerUIntegral}\leanok
A LowerUIntegral of a function $f$ comes from $\sigma-i\infty$ up to $\sigma-iT$, over to $\sigma'-iT$, and back down to $\sigma'-i\infty$.
\end{definition}
%-/
noncomputable def LowerUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' (-T) -
I • (∫ y : ℝ in Iic (-T), f (σ' + y * I)) + I • (∫ y : ℝ in Iic (-T), f (σ + y * I))
/-%%
It is very convenient to define integrals along vertical lines in the complex plane, as follows.
\begin{definition}[VerticalIntegral]\label{VerticalIntegral}\lean{VerticalIntegral}\leanok
Let $f$ be a function from $\mathbb{C}$ to $\mathbb{C}$, and let $\sigma$ be a real number. Then we define
$$\int_{(\sigma)}f(s)ds = \int_{\sigma-i\infty}^{\sigma+i\infty}f(s)ds.$$
\end{definition}
%%-/
noncomputable def VerticalIntegral (f : ℂ → E) (σ : ℝ) : E := I • ∫ t : ℝ, f (σ + t * I)
--%% We also have a version with a factor of $1/(2\pi i)$.
noncomputable abbrev VerticalIntegral' (f : ℂ → E) (σ : ℝ) : E :=
(1 / (2 * π * I)) • VerticalIntegral f σ
lemma verticalIntegral_split_three (a b : ℝ) (hf : Integrable (fun t : ℝ ↦ f (σ + t * I))) :
VerticalIntegral f σ = I • (∫ t in Iic a, f (σ + t * I)) + VIntegral f σ a b
+ I • ∫ t in Ici b, f (σ + t * I) := by
simp_rw [VerticalIntegral, VIntegral, ← smul_add]
congr
rw [← intervalIntegral.integral_Iic_sub_Iic hf.restrict hf.restrict, add_sub_cancel,
integral_Iic_eq_integral_Iio, intervalIntegral.integral_Iio_add_Ici hf.restrict hf.restrict]
/-% ** Wrong delimiter on purpose **
\begin{lemma}[DiffVertRect_eq_UpperLowerUs]\label{DiffVertRect_eq_UpperLowerUs}\lean{DiffVertRect_eq_UpperLowerUs}\leanok
The difference of two vertical integrals and a rectangle is the difference of an upper and a lower U integrals.
\end{lemma}
%-/
lemma DiffVertRect_eq_UpperLowerUs {σ σ' T : ℝ}
(f_int_σ : Integrable (fun (t : ℝ) ↦ f (σ + t * I)))
(f_int_σ' : Integrable (fun (t : ℝ) ↦ f (σ' + t * I))) :
(VerticalIntegral f σ') - (VerticalIntegral f σ) - (RectangleIntegral f (σ - I * T) (σ' + I * T)) =
(UpperUIntegral f σ σ' T) - (LowerUIntegral f σ σ' T) := by
rw [verticalIntegral_split_three (-T) T f_int_σ, verticalIntegral_split_three (-T) T f_int_σ']
simp only [smul_eq_mul, RectangleIntegral, sub_re, ofReal_re, mul_re, I_re, zero_mul, I_im,
ofReal_im, mul_zero, sub_self, sub_zero, add_re, add_zero, sub_im, mul_im, one_mul, zero_add,
zero_sub, add_im, UpperUIntegral, LowerUIntegral]
abel
/-%
\begin{proof}\uses{UpperUIntegral, LowerUIntegral}\leanok
Follows directly from the definitions.
\end{proof}
%-/
/-- A function is `HolomorphicOn` a set if it is complex differentiable on that set. -/
abbrev HolomorphicOn (f : ℂ → E) (s : Set ℂ) : Prop := DifferentiableOn ℂ f s
/-%%
\begin{theorem}[existsDifferentiableOn_of_bddAbove]\label{existsDifferentiableOn_of_bddAbove}\lean{existsDifferentiableOn_of_bddAbove}\leanok
If $f$ is differentiable on a set $s$ except at $c\in s$, and $f$ is bounded above on $s\setminus\{c\}$, then there exists a differentiable function $g$ on $s$ such that $f$ and $g$ agree on $s\setminus\{c\}$.
\end{theorem}
%%-/
theorem existsDifferentiableOn_of_bddAbove [CompleteSpace E] {s : Set ℂ} {c : ℂ} (hc : s ∈ nhds c)
(hd : HolomorphicOn f (s \ {c})) (hb : BddAbove (norm ∘ f '' (s \ {c}))) :
∃ (g : ℂ → E), HolomorphicOn g s ∧ (Set.EqOn f g (s \ {c})) :=
⟨Function.update f c (limUnder (𝓝[{c}ᶜ] c) f),
differentiableOn_update_limUnder_of_bddAbove hc hd hb,
fun z hz ↦ if h : z = c then (hz.2 h).elim else by simp [h]⟩
/-%%
\begin{proof}\leanok
This is the Riemann Removable Singularity Theorem, slightly rephrased from what's in Mathlib. (We don't care what the function $g$ is, just that it's holomorphic.)
\end{proof}
%%-/
/-%%
\begin{theorem}[HolomorphicOn.vanishesOnRectangle]\label{HolomorphicOn.vanishesOnRectangle}\lean{HolomorphicOn.vanishesOnRectangle}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$, then the integral of $f$ over the rectangle with corners $z$ and $w$ is $0$.
\end{theorem}
%%-/
theorem HolomorphicOn.vanishesOnRectangle [CompleteSpace E] {U : Set ℂ}
(f_holo : HolomorphicOn f U) (hU : Rectangle z w ⊆ U) :
RectangleIntegral f z w = 0 :=
integral_boundary_rect_eq_zero_of_differentiableOn f z w (f_holo.mono hU)
/-%%
\begin{proof}\leanok
This is in a Mathlib PR.
\end{proof}
%%-/
theorem RectangleIntegral_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral f z w = RectangleIntegral g z w := by
unfold RectangleIntegral VIntegral
congr 2; swap; congr 1; swap; congr 1
all_goals refine intervalIntegral.integral_congr fun _ _ ↦ h ?_
· exact Or.inl <| Or.inl <| Or.inl ⟨by simpa, by simp⟩
· exact Or.inl <| Or.inr ⟨by simpa, by simp⟩
· exact Or.inr ⟨by simp, by simpa⟩
· exact Or.inl <| Or.inl <| Or.inr ⟨by simp, by simpa⟩
theorem RectangleIntegral'_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral' f z w = RectangleIntegral' g z w := by
rw [RectangleIntegral', RectangleIntegral_congr h]
theorem rectangleIntegral_symm (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f z w = RectangleIntegral f w z := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, intervalIntegral.integral_symm w.re,
intervalIntegral.integral_symm w.im, sub_neg_eq_add, smul_neg, sub_neg_eq_add, ← sub_eq_add_neg,
neg_add_eq_sub, sub_add_eq_add_sub]
theorem rectangleIntegral_symm_re (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f (w.re + z.im * I) (z.re + w.im * I) = - RectangleIntegral f z w := by
simp [RectangleIntegral, ← sub_eq_zero]
rw [HIntegral_symm (y := z.im), HIntegral_symm (y := w.im)]
abel
def RectangleBorderIntegrable (f : ℂ → E) (z w : ℂ) : Prop :=
IntervalIntegrable (fun x => f (x + z.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun x => f (x + w.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun y => f (w.re + y * I)) volume z.im w.im ∧
IntervalIntegrable (fun y => f (z.re + y * I)) volume z.im w.im
theorem RectangleBorderIntegrable.add {f g : ℂ → E} (hf : RectangleBorderIntegrable f z w)
(hg : RectangleBorderIntegrable g z w) :
RectangleIntegral (f + g) z w = RectangleIntegral f z w + RectangleIntegral g z w := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
rw [intervalIntegral.integral_add hf.1 hg.1, intervalIntegral.integral_add hf.2.1 hg.2.1,
intervalIntegral.integral_add hf.2.2.1 hg.2.2.1, intervalIntegral.integral_add hf.2.2.2 hg.2.2.2]
rw [← sub_eq_zero]
simp only [smul_add]; abel
theorem ContinuousOn.rectangleBorder_integrable (hf : ContinuousOn f (RectangleBorder z w)) :
RectangleBorderIntegrable f z w :=
⟨(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_re z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_re z w)).intervalIntegrable⟩
theorem ContinuousOn.rectangleBorderIntegrable (hf : ContinuousOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
(hf.mono (rectangleBorder_subset_rectangle z w)).rectangleBorder_integrable
theorem ContinuousOn.rectangleBorderNoPIntegrable (hf : ContinuousOn f (Rectangle z w \ {p}))
(pNotOnBorder : p ∉ RectangleBorder z w) : RectangleBorderIntegrable f z w := by
refine (hf.mono (Set.subset_diff.mpr ?_)).rectangleBorder_integrable
exact ⟨rectangleBorder_subset_rectangle z w, disjoint_singleton_right.mpr pNotOnBorder⟩
theorem HolomorphicOn.rectangleBorderIntegrable' (hf : HolomorphicOn f (Rectangle z w \ {p}))
(hp : Rectangle z w ∈ nhds p) : RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderNoPIntegrable (not_mem_rectangleBorder_of_rectangle_mem_nhds hp)
theorem HolomorphicOn.rectangleBorderIntegrable (hf : HolomorphicOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderIntegrable
/--
Given `x₀ a x₁ : ℝ`, and `y₀ y₁ : ℝ` and a function `f : ℂ → ℂ` so that
both `(t : ℝ) ↦ f(t + y₀ * I)` and `(t : ℝ) ↦ f(t + y₁ * I)` are integrable over both
`t ∈ Icc x₀ a` and `t ∈ Icc a x₁`, we have that
`RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I)` is the sum of
`RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I)` and
`RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I)`.
-/
lemma RectangleIntegralHSplit {a x₀ x₁ y₀ y₁ : ℝ}
(f_int_x₀_a_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume x₀ a)
(f_int_a_x₁_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume a x₁)
(f_int_x₀_a_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume x₀ a)
(f_int_a_x₁_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume a x₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_bot f_int_a_x₁_bot,
← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_top f_int_a_x₁_top]
abel
lemma RectangleIntegralHSplit' {a x₀ x₁ y₀ y₁ : ℝ} (ha : a ∈ [[x₀, x₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) :=
RectangleIntegralHSplit
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
lemma RectangleIntegralVSplit {b x₀ x₁ y₀ y₁ : ℝ}
(f_int_y₀_b_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume y₀ b)
(f_int_b_y₁_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume b y₁)
(f_int_y₀_b_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume y₀ b)
(f_int_b_y₁_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume b y₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_left f_int_b_y₁_left,
← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_right f_int_b_y₁_right, ← sub_eq_zero]
simp only [smul_add]; abel
lemma RectangleIntegralVSplit' {b x₀ x₁ y₀ y₁ : ℝ} (hb : b ∈ [[y₀, y₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) :=
RectangleIntegralVSplit
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
lemma RectanglePullToNhdOfPole' [CompleteSpace E] {z₀ z₁ z₂ z₃ p : ℂ}
(h_orientation : z₀.re ≤ z₃.re ∧ z₀.im ≤ z₃.im ∧ z₁.re ≤ z₂.re ∧ z₁.im ≤ z₂.im)
(hp : Rectangle z₁ z₂ ∈ 𝓝 p) (hz : Rectangle z₁ z₂ ⊆ Rectangle z₀ z₃)
(fHolo : HolomorphicOn f (Rectangle z₀ z₃ \ {p})) :
RectangleIntegral f z₀ z₃ = RectangleIntegral f z₁ z₂ := by
obtain ⟨hz₀_re, hz₀_im, hz₁_re, hz₁_im⟩ := h_orientation
have := rect_subset_iff.mp hz
rw [Rectangle, uIcc_of_le hz₀_re, uIcc_of_le hz₀_im] at this
obtain ⟨⟨⟨_, _⟩, ⟨_, _⟩⟩, ⟨_, _⟩, ⟨_, _⟩⟩ := this
obtain ⟨⟨_, _⟩, ⟨_, _⟩⟩ := (uIoo_of_le hz₁_re) ▸ (uIoo_of_le hz₁_im) ▸ rectangle_mem_nhds_iff.mp hp
obtain ⟨_, _, _, _⟩ := show p.re < z₂.re ∧ p.re < z₃.re ∧ p.im < z₂.im ∧ p.im < z₃.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
obtain ⟨_, _, _, _⟩ := show z₀.re < p.re ∧ z₁.re < p.re ∧ z₀.im < p.im ∧ z₁.im < p.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
have fCont := fHolo.continuousOn
have hbot : RectangleBorderIntegrable f (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have htop : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have hleft : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
have hright : RectangleBorderIntegrable f (↑z₁.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
all_goals try {
refine (fCont.mono (rectangleBorder_subset_punctured_rect ?_ ?_)).rectangleBorder_integrable
· simp_all
· simpa using ⟨by linarith, by linarith, by linarith, by linarith⟩
}
have hbot' : z₁.im ∈ [[z₀.im, z₃.im]] := ?_
have htop' : z₂.im ∈ [[z₁.im, z₃.im]] := ?_
have hleft' : z₁.re ∈ [[z₀.re, z₃.re]] := ?_
have hright' : z₂.re ∈ [[z₁.re, z₃.re]] := ?_
all_goals try { rw [Set.uIcc_of_le]; constructor; all_goals assumption }
have hbot'' : Rectangle (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₁.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have htop'' : Rectangle (↑z₀.re + ↑z₂.im * I) (↑z₃.re + ↑z₃.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hleft'' : Rectangle (↑z₀.re + ↑z₁.im * I) (↑z₁.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hright'' : Rectangle (↑z₂.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
all_goals try { apply rectangle_subset_punctured_rect <;> simp_all }
rw [← re_add_im z₀, ← re_add_im z₃,
RectangleIntegralVSplit' hbot' hbot, fHolo.vanishesOnRectangle hbot'', zero_add,
RectangleIntegralVSplit' htop' htop, fHolo.vanishesOnRectangle htop'', add_zero,
RectangleIntegralHSplit' hleft' hleft, fHolo.vanishesOnRectangle hleft'', zero_add,
RectangleIntegralHSplit' hright' hright, fHolo.vanishesOnRectangle hright'', add_zero,
re_add_im, re_add_im]
/-%%
The next lemma allows to zoom a big rectangle down to a small square, centered at a pole.
\begin{lemma}[RectanglePullToNhdOfPole]\label{RectanglePullToNhdOfPole}\lean{RectanglePullToNhdOfPole}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$ except at a point $p$, then the integral of $f$
over the rectangle with corners $z$ and $w$ is the same as the integral of $f$ over a small square
centered at $p$.
\end{lemma}
%%-/
/-- Given `f` holomorphic on a rectangle `z` and `w` except at a point `p`, the integral of `f` over
the rectangle with corners `z` and `w` is the same as the integral of `f` over a small square
centered at `p`. -/
lemma RectanglePullToNhdOfPole [CompleteSpace E] {z w p : ℂ} (zRe_lt_wRe : z.re ≤ w.re)
(zIm_lt_wIm : z.im ≤ w.im) (hp : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral f z w = RectangleIntegral f (-c - I * c + p) (c + I * c + p) := by
/-%%
\begin{proof}\uses{HolomorphicOn.vanishesOnRectangle}\leanok
Chop the big rectangle with two vertical cuts and two horizontal cuts into smaller rectangles,
the middle one being the desired square. The integral over each of the outer rectangles
vanishes, since $f$ is holomorphic there. (The constant $c$ being ``small enough'' here just means
that the inner square is strictly contained in the big rectangle.)
%%-/
filter_upwards [Ioo_mem_nhdsWithin_Ioi' zero_lt_one, SmallSquareInRectangle hp]
intro c ⟨cpos, _⟩ hc
simp_rw [mul_comm I]
exact RectanglePullToNhdOfPole' (by simp_all [cpos.le])
(square_mem_nhds p (ne_of_gt cpos)) hc fHolo
--%%\end{proof}
lemma RectanglePullToNhdOfPole'' [CompleteSpace E] {z w p : ℂ} (zRe_le_wRe : z.re ≤ w.re)
(zIm_le_wIm : z.im ≤ w.im) (pInRectInterior : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral' f z w = RectangleIntegral' f (-c - I * c + p) (c + I * c + p) := by
filter_upwards [RectanglePullToNhdOfPole zRe_le_wRe zIm_le_wIm pInRectInterior fHolo] with c h
simp_rw [RectangleIntegral', h]
theorem ResidueTheoremAtOrigin_aux1c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y + I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux1c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y - I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (-1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem RectangleIntegral.const_smul (f : ℂ → E) (z w c : ℂ) :
RectangleIntegral (fun s => c • f s) z w = c • RectangleIntegral f z w := by
simp [RectangleIntegral, HIntegral, VIntegral, smul_add, smul_sub, smul_smul, mul_comm]
theorem RectangleIntegral.const_mul' (f : ℂ → E) (z w c : ℂ) :
RectangleIntegral' (fun s => c • f s) z w = c • RectangleIntegral' f z w := by
simp [RectangleIntegral', RectangleIntegral.const_smul, smul_smul] ; ring_nf
theorem RectangleIntegral.translate (f : ℂ → E) (z w p : ℂ) :
RectangleIntegral (fun s => f (s - p)) z w = RectangleIntegral f (z - p) (w - p) := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, sub_re, sub_im, ← intervalIntegral.integral_comp_sub_right]
congr <;> ext <;> congr 1 <;> simp [Complex.ext_iff]
theorem RectangleIntegral.translate' (f : ℂ → E) (z w p : ℂ) :
RectangleIntegral' (fun s => f (s - p)) z w = RectangleIntegral' f (z - p) (w - p) := by
simp_rw [RectangleIntegral', RectangleIntegral.translate]
lemma Complex.inv_re_add_im : (x + y * I)⁻¹ = (x - I * y) / (x ^ 2 + y ^ 2) := by
rw [Complex.inv_def, div_eq_mul_inv] ; congr <;> simp [conj_ofReal, normSq] <;> ring
lemma sq_add_sq_ne_zero (hy : y ≠ 0) : x ^ 2 + y ^ 2 ≠ 0 := by linarith [sq_nonneg x, (sq_pos_iff y).mpr hy]
lemma continuous_self_div_sq_add_sq (hy : y ≠ 0) : Continuous fun x => x / (x ^ 2 + y ^ 2) :=
continuous_id.div (continuous_id.pow 2 |>.add continuous_const) (λ _ => sq_add_sq_ne_zero hy)
lemma integral_self_div_sq_add_sq (hy : y ≠ 0) : ∫ x in x₁..x₂, x / (x ^ 2 + y ^ 2) =
Real.log (x₂ ^ 2 + y ^ 2) / 2 - Real.log (x₁ ^ 2 + y ^ 2) / 2 := by
let f (x : ℝ) : ℝ := Real.log (x ^ 2 + y ^ 2) / 2
have e1 {x} := HasDerivAt.add_const (by simpa using hasDerivAt_pow 2 x) (y ^ 2)
have e2 {x} : HasDerivAt f (x / (x ^ 2 + y ^ 2)) x := by
convert (e1.log (sq_add_sq_ne_zero hy)).div_const 2 using 1 ; field_simp ; ring
have e3 : deriv f = λ x => x / (x ^ 2 + y ^ 2) := funext (λ _ => e2.deriv)
have e4 : Continuous (deriv f) := by simpa only [e3] using continuous_self_div_sq_add_sq hy
simp_rw [← e2.deriv]
exact integral_deriv_eq_sub (λ _ _ => e2.differentiableAt) <| e4.intervalIntegrable _ _
lemma integral_const_div_sq_add_sq (hy : y ≠ 0) : ∫ x in x₁..x₂, y / (x ^ 2 + y ^ 2) =
arctan (x₂ / y) - arctan (x₁ / y) := by
nth_rewrite 1 [← div_mul_cancel₀ x₁ hy, ← div_mul_cancel₀ x₂ hy]
simp_rw [← mul_integral_comp_mul_right, ← integral_const_mul, ← integral_one_div_one_add_sq]
exact integral_congr <| λ x _ => by field_simp; ring
lemma integral_const_div_self_add_im (hy : y ≠ 0) : ∫ x : ℝ in x₁..x₂, A / (x + y * I) =
A * (Real.log (x₂ ^ 2 + y ^ 2) / 2 - Real.log (x₁ ^ 2 + y ^ 2) / 2) -
A * I * (arctan (x₂ / y) - arctan (x₁ / y)) := by
have e1 {x : ℝ} : A / (x + y * I) = A * x / (x ^ 2 + y ^ 2) - A * I * y / (x ^ 2 + y ^ 2) := by
ring_nf ; simp_rw [inv_re_add_im] ; ring
have e2 : IntervalIntegrable (fun x ↦ A * x / (x ^ 2 + y ^ 2)) volume x₁ x₂ := by
apply Continuous.intervalIntegrable
simp_rw [mul_div_assoc] ; norm_cast
exact continuous_const.mul <| continuous_ofReal.comp <| continuous_self_div_sq_add_sq hy
have e3 : IntervalIntegrable (fun x ↦ A * I * y / (x ^ 2 + y ^ 2)) volume x₁ x₂ := by
apply Continuous.intervalIntegrable
refine continuous_const.div (by continuity) (λ x => ?_)
norm_cast ; exact sq_add_sq_ne_zero hy
simp_rw [integral_congr (λ _ _ => e1), integral_sub e2 e3, mul_div_assoc]
norm_cast
simp_rw [integral_const_mul, intervalIntegral.integral_ofReal, integral_self_div_sq_add_sq hy,
integral_const_div_sq_add_sq hy]
lemma integral_const_div_re_add_self (hx : x ≠ 0) : ∫ y : ℝ in y₁..y₂, A / (x + y * I) =
A / I * (Real.log (y₂ ^ 2 + (-x) ^ 2) / 2 - Real.log (y₁ ^ 2 + (-x) ^ 2) / 2) -
A / I * I * (arctan (y₂ / -x) - arctan (y₁ / -x)) := by
have l1 {y : ℝ} : A / (x + y * I) = A / I / (y + ↑(-x) * I) := by
have e1 : x + y * I ≠ 0 := by contrapose! hx ; simpa using congr_arg re hx
have e2 : y + -(x * I) ≠ 0 := by contrapose! hx ; simpa using congr_arg im hx
field_simp ; ring_nf ; simp
have l2 : -x ≠ 0 := by rwa [neg_ne_zero]
simp_rw [l1, integral_const_div_self_add_im l2]
lemma ResidueTheoremAtOrigin' {z w c : ℂ} (h1 : z.re < 0) (h2 : z.im < 0) (h3 : 0 < w.re) (h4 : 0 < w.im) :
RectangleIntegral (λ s => c / s) z w = 2 * I * π * c := by
simp only [RectangleIntegral, HIntegral, VIntegral, smul_eq_mul]
rw [integral_const_div_re_add_self h1.ne, integral_const_div_re_add_self h3.ne.symm]
rw [integral_const_div_self_add_im h2.ne, integral_const_div_self_add_im h4.ne.symm]
have l1 : z.im * w.re⁻¹ = (w.re * z.im⁻¹)⁻¹ := by group
have l3 := arctan_inv_of_neg <| mul_neg_of_pos_of_neg h3 <| inv_lt_zero.mpr h2
have l4 : w.im * z.re⁻¹ = (z.re * w.im⁻¹)⁻¹ := by group
have l6 := arctan_inv_of_neg <| mul_neg_of_neg_of_pos h1 <| inv_pos.mpr h4
have r1 : z.im * z.re⁻¹ = (z.re * z.im⁻¹)⁻¹ := by group
have r3 := arctan_inv_of_pos <| mul_pos_of_neg_of_neg h1 <| inv_lt_zero.mpr h2
have r4 : w.im * w.re⁻¹ = (w.re * w.im⁻¹)⁻¹ := by group
have r6 := arctan_inv_of_pos <| mul_pos h3 <| inv_pos.mpr h4
ring_nf
simp only [one_div, inv_I, mul_neg, neg_mul, I_sq, one_mul, neg_neg, arctan_neg, ofReal_neg, sub_neg_eq_add]
rw [l1, l3, l4, l6, r1, r3, r4, r6]
ring_nf
simp only [I_sq, ofReal_sub, ofReal_mul, ofReal_ofNat, ofReal_div, ofReal_neg, ofReal_one]
ring_nf
theorem ResidueTheoremInRectangle (zRe_le_wRe : z.re ≤ w.re) (zIm_le_wIm : z.im ≤ w.im)
(pInRectInterior : Rectangle z w ∈ 𝓝 p) : RectangleIntegral' (λ s => c / (s - p)) z w = c := by
simp [rectangle_mem_nhds_iff, mem_reProdIm, uIoo_of_le zRe_le_wRe, uIoo_of_le zIm_le_wIm]
at pInRectInterior
rw [RectangleIntegral.translate', RectangleIntegral']
have : 1 / (2 * ↑π * I) * (2 * I * ↑π * c) = c := by field_simp [two_pi_I_ne_zero] ; ring
rwa [ResidueTheoremAtOrigin'] ; all_goals { simp [*] }
/-%%
\begin{lemma}[ResidueTheoremAtOrigin]\label{ResidueTheoremAtOrigin}
\lean{ResidueTheoremAtOrigin}\leanok
The rectangle (square) integral of $f(s) = 1/s$ with corners $-1-i$ and $1+i$ is equal to $2\pi i$.
\end{lemma}
%%-/
| lemma ResidueTheoremAtOrigin : RectangleIntegral' (fun s ↦ 1 / s) (-1 - I) (1 + I) = 1 | ResidueTheoremAtOrigin | f36a520 20240122 | 1909a40 20240209 | PrimeNumberTheoremAnd/PrimeNumberTheoremAnd/ResidueCalcOnRectangles.lean | {
"lineInFile": 470,
"tokenPositionInFile": 26080,
"theoremPositionInFile": 52
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": ":= by\n rw [RectangleIntegral', ResidueTheoremAtOrigin']\n all_goals { field_simp [pi_ne_zero] <;> ring }",
"proofType": "tactic",
"proofLengthLines": 2,
"proofLengthTokens": 105
} | prime |
import Mathlib.Analysis.Complex.CauchyIntegral
import Mathlib.Analysis.Complex.Convex
import Mathlib.Analysis.Complex.RemovableSingularity
import Mathlib.Analysis.Analytic.Meromorphic
import Mathlib.Analysis.SpecialFunctions.Integrals
import Mathlib.MeasureTheory.Measure.Lebesgue.Integral
import PrimeNumberTheoremAnd.Rectangle
open Complex BigOperators Nat Classical Real Topology Filter Set MeasureTheory intervalIntegral
open scoped Interval
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f g : ℂ → E}
{z w p c A : ℂ} {x x₁ x₂ y y₁ y₂ σ : ℝ}
noncomputable def HIntegral (f : ℂ → E) (x₁ x₂ y : ℝ) : E := ∫ x in x₁..x₂, f (x + y * I)
noncomputable def VIntegral (f : ℂ → E) (x y₁ y₂ : ℝ) : E := I • ∫ y in y₁..y₂, f (x + y * I)
noncomputable def HIntegral' (f : ℂ → E) (x₁ x₂ y : ℝ) : E := (1 / (2 * π * I)) • HIntegral f x₁ x₂ y
noncomputable def VIntegral' (f : ℂ → E) (x y₁ y₂ : ℝ) : E := (1 / (2 * π * I)) • VIntegral f x y₁ y₂
lemma HIntegral_symm : HIntegral f x₁ x₂ y = - HIntegral f x₂ x₁ y := integral_symm _ _
lemma VIntegral_symm : VIntegral f x y₁ y₂ = - VIntegral f x y₂ y₁ := by
simp_rw [VIntegral, integral_symm y₁ y₂, smul_neg, neg_neg]
/-%%
\begin{definition}[RectangleIntegral]\label{RectangleIntegral}\lean{RectangleIntegral}\leanok
A RectangleIntegral of a function $f$ is one over a rectangle determined by $z$ and $w$ in $\C$.
We will sometimes denote it by $\int_{z}^{w} f$. (There is also a primed version, which is $1/(2\pi i)$ times the original.)
\end{definition}
%%-/
/-- A `RectangleIntegral` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`. -/
noncomputable def RectangleIntegral (f : ℂ → E) (z w : ℂ) : E := HIntegral f z.re w.re z.im -
HIntegral f z.re w.re w.im + VIntegral f w.re z.im w.im - VIntegral f z.re z.im w.im
/-- A `RectangleIntegral'` of a function `f` is one over a rectangle determined by
`z` and `w` in `ℂ`, divided by `2 * π * I`. -/
noncomputable abbrev RectangleIntegral' (f : ℂ → E) (z w : ℂ) : E :=
(1 / (2 * π * I)) • RectangleIntegral f z w
/-% ** Wrong delimiter on purpose **
An UpperUIntegral is the integral of a function over a |\_| shape.
\begin{definition}\label{UpperUIntegral}\lean{UpperUIntegral}\leanok
An UpperUIntegral of a function $f$ comes from $\sigma+i\infty$ down to $\sigma+iT$, over to $\sigma'+iT$, and back up to $\sigma'+i\infty$.
\end{definition}
%-/
noncomputable def UpperUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' T +
I • (∫ y : ℝ in Ici T, f (σ' + y * I)) - I • (∫ y : ℝ in Ici T, f (σ + y * I))
/-% ** Wrong delimiter on purpose **
A LowerUIntegral is the integral of a function over a |-| shape.
\begin{definition}[LowerUIntegral]\label{LowerUIntegral}\lean{LowerUIntegral}\leanok
A LowerUIntegral of a function $f$ comes from $\sigma-i\infty$ up to $\sigma-iT$, over to $\sigma'-iT$, and back down to $\sigma'-i\infty$.
\end{definition}
%-/
noncomputable def LowerUIntegral (f : ℂ → E) (σ σ' T : ℝ) : E := HIntegral f σ σ' (-T) -
I • (∫ y : ℝ in Iic (-T), f (σ' + y * I)) + I • (∫ y : ℝ in Iic (-T), f (σ + y * I))
/-%%
It is very convenient to define integrals along vertical lines in the complex plane, as follows.
\begin{definition}[VerticalIntegral]\label{VerticalIntegral}\lean{VerticalIntegral}\leanok
Let $f$ be a function from $\mathbb{C}$ to $\mathbb{C}$, and let $\sigma$ be a real number. Then we define
$$\int_{(\sigma)}f(s)ds = \int_{\sigma-i\infty}^{\sigma+i\infty}f(s)ds.$$
\end{definition}
%%-/
noncomputable def VerticalIntegral (f : ℂ → E) (σ : ℝ) : E := I • ∫ t : ℝ, f (σ + t * I)
--%% We also have a version with a factor of $1/(2\pi i)$.
noncomputable abbrev VerticalIntegral' (f : ℂ → E) (σ : ℝ) : E :=
(1 / (2 * π * I)) • VerticalIntegral f σ
lemma verticalIntegral_split_three (a b : ℝ) (hf : Integrable (fun t : ℝ ↦ f (σ + t * I))) :
VerticalIntegral f σ = I • (∫ t in Iic a, f (σ + t * I)) + VIntegral f σ a b
+ I • ∫ t in Ici b, f (σ + t * I) := by
simp_rw [VerticalIntegral, VIntegral, ← smul_add]
congr
rw [← intervalIntegral.integral_Iic_sub_Iic hf.restrict hf.restrict, add_sub_cancel,
integral_Iic_eq_integral_Iio, intervalIntegral.integral_Iio_add_Ici hf.restrict hf.restrict]
/-% ** Wrong delimiter on purpose **
\begin{lemma}[DiffVertRect_eq_UpperLowerUs]\label{DiffVertRect_eq_UpperLowerUs}\lean{DiffVertRect_eq_UpperLowerUs}\leanok
The difference of two vertical integrals and a rectangle is the difference of an upper and a lower U integrals.
\end{lemma}
%-/
lemma DiffVertRect_eq_UpperLowerUs {σ σ' T : ℝ}
(f_int_σ : Integrable (fun (t : ℝ) ↦ f (σ + t * I)))
(f_int_σ' : Integrable (fun (t : ℝ) ↦ f (σ' + t * I))) :
(VerticalIntegral f σ') - (VerticalIntegral f σ) - (RectangleIntegral f (σ - I * T) (σ' + I * T)) =
(UpperUIntegral f σ σ' T) - (LowerUIntegral f σ σ' T) := by
rw [verticalIntegral_split_three (-T) T f_int_σ, verticalIntegral_split_three (-T) T f_int_σ']
simp only [smul_eq_mul, RectangleIntegral, sub_re, ofReal_re, mul_re, I_re, zero_mul, I_im,
ofReal_im, mul_zero, sub_self, sub_zero, add_re, add_zero, sub_im, mul_im, one_mul, zero_add,
zero_sub, add_im, UpperUIntegral, LowerUIntegral]
abel
/-%
\begin{proof}\uses{UpperUIntegral, LowerUIntegral}\leanok
Follows directly from the definitions.
\end{proof}
%-/
/-- A function is `HolomorphicOn` a set if it is complex differentiable on that set. -/
abbrev HolomorphicOn (f : ℂ → E) (s : Set ℂ) : Prop := DifferentiableOn ℂ f s
/-%%
\begin{theorem}[existsDifferentiableOn_of_bddAbove]\label{existsDifferentiableOn_of_bddAbove}\lean{existsDifferentiableOn_of_bddAbove}\leanok
If $f$ is differentiable on a set $s$ except at $c\in s$, and $f$ is bounded above on $s\setminus\{c\}$, then there exists a differentiable function $g$ on $s$ such that $f$ and $g$ agree on $s\setminus\{c\}$.
\end{theorem}
%%-/
theorem existsDifferentiableOn_of_bddAbove [CompleteSpace E] {s : Set ℂ} {c : ℂ} (hc : s ∈ nhds c)
(hd : HolomorphicOn f (s \ {c})) (hb : BddAbove (norm ∘ f '' (s \ {c}))) :
∃ (g : ℂ → E), HolomorphicOn g s ∧ (Set.EqOn f g (s \ {c})) :=
⟨Function.update f c (limUnder (𝓝[{c}ᶜ] c) f),
differentiableOn_update_limUnder_of_bddAbove hc hd hb,
fun z hz ↦ if h : z = c then (hz.2 h).elim else by simp [h]⟩
/-%%
\begin{proof}\leanok
This is the Riemann Removable Singularity Theorem, slightly rephrased from what's in Mathlib. (We don't care what the function $g$ is, just that it's holomorphic.)
\end{proof}
%%-/
/-%%
\begin{theorem}[HolomorphicOn.vanishesOnRectangle]\label{HolomorphicOn.vanishesOnRectangle}\lean{HolomorphicOn.vanishesOnRectangle}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$, then the integral of $f$ over the rectangle with corners $z$ and $w$ is $0$.
\end{theorem}
%%-/
theorem HolomorphicOn.vanishesOnRectangle [CompleteSpace E] {U : Set ℂ}
(f_holo : HolomorphicOn f U) (hU : Rectangle z w ⊆ U) :
RectangleIntegral f z w = 0 :=
integral_boundary_rect_eq_zero_of_differentiableOn f z w (f_holo.mono hU)
/-%%
\begin{proof}\leanok
This is in a Mathlib PR.
\end{proof}
%%-/
theorem RectangleIntegral_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral f z w = RectangleIntegral g z w := by
unfold RectangleIntegral VIntegral
congr 2; swap; congr 1; swap; congr 1
all_goals refine intervalIntegral.integral_congr fun _ _ ↦ h ?_
· exact Or.inl <| Or.inl <| Or.inl ⟨by simpa, by simp⟩
· exact Or.inl <| Or.inr ⟨by simpa, by simp⟩
· exact Or.inr ⟨by simp, by simpa⟩
· exact Or.inl <| Or.inl <| Or.inr ⟨by simp, by simpa⟩
theorem RectangleIntegral'_congr (h : Set.EqOn f g (RectangleBorder z w)) :
RectangleIntegral' f z w = RectangleIntegral' g z w := by
rw [RectangleIntegral', RectangleIntegral_congr h]
theorem rectangleIntegral_symm (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f z w = RectangleIntegral f w z := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, intervalIntegral.integral_symm w.re,
intervalIntegral.integral_symm w.im, sub_neg_eq_add, smul_neg, sub_neg_eq_add, ← sub_eq_add_neg,
neg_add_eq_sub, sub_add_eq_add_sub]
theorem rectangleIntegral_symm_re (f : ℂ → E) (z w : ℂ) :
RectangleIntegral f (w.re + z.im * I) (z.re + w.im * I) = - RectangleIntegral f z w := by
simp [RectangleIntegral, ← sub_eq_zero]
rw [HIntegral_symm (y := z.im), HIntegral_symm (y := w.im)]
abel
def RectangleBorderIntegrable (f : ℂ → E) (z w : ℂ) : Prop :=
IntervalIntegrable (fun x => f (x + z.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun x => f (x + w.im * I)) volume z.re w.re ∧
IntervalIntegrable (fun y => f (w.re + y * I)) volume z.im w.im ∧
IntervalIntegrable (fun y => f (z.re + y * I)) volume z.im w.im
theorem RectangleBorderIntegrable.add {f g : ℂ → E} (hf : RectangleBorderIntegrable f z w)
(hg : RectangleBorderIntegrable g z w) :
RectangleIntegral (f + g) z w = RectangleIntegral f z w + RectangleIntegral g z w := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
rw [intervalIntegral.integral_add hf.1 hg.1, intervalIntegral.integral_add hf.2.1 hg.2.1,
intervalIntegral.integral_add hf.2.2.1 hg.2.2.1, intervalIntegral.integral_add hf.2.2.2 hg.2.2.2]
rw [← sub_eq_zero]
simp only [smul_add]; abel
theorem ContinuousOn.rectangleBorder_integrable (hf : ContinuousOn f (RectangleBorder z w)) :
RectangleBorderIntegrable f z w :=
⟨(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_im z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_right_re z w)).intervalIntegrable,
(hf.comp (by fun_prop) (mapsTo_rectangleBorder_left_re z w)).intervalIntegrable⟩
theorem ContinuousOn.rectangleBorderIntegrable (hf : ContinuousOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
(hf.mono (rectangleBorder_subset_rectangle z w)).rectangleBorder_integrable
theorem ContinuousOn.rectangleBorderNoPIntegrable (hf : ContinuousOn f (Rectangle z w \ {p}))
(pNotOnBorder : p ∉ RectangleBorder z w) : RectangleBorderIntegrable f z w := by
refine (hf.mono (Set.subset_diff.mpr ?_)).rectangleBorder_integrable
exact ⟨rectangleBorder_subset_rectangle z w, disjoint_singleton_right.mpr pNotOnBorder⟩
theorem HolomorphicOn.rectangleBorderIntegrable' (hf : HolomorphicOn f (Rectangle z w \ {p}))
(hp : Rectangle z w ∈ nhds p) : RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderNoPIntegrable (not_mem_rectangleBorder_of_rectangle_mem_nhds hp)
theorem HolomorphicOn.rectangleBorderIntegrable (hf : HolomorphicOn f (Rectangle z w)) :
RectangleBorderIntegrable f z w :=
hf.continuousOn.rectangleBorderIntegrable
/--
Given `x₀ a x₁ : ℝ`, and `y₀ y₁ : ℝ` and a function `f : ℂ → ℂ` so that
both `(t : ℝ) ↦ f(t + y₀ * I)` and `(t : ℝ) ↦ f(t + y₁ * I)` are integrable over both
`t ∈ Icc x₀ a` and `t ∈ Icc a x₁`, we have that
`RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I)` is the sum of
`RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I)` and
`RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I)`.
-/
lemma RectangleIntegralHSplit {a x₀ x₁ y₀ y₁ : ℝ}
(f_int_x₀_a_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume x₀ a)
(f_int_a_x₁_bot : IntervalIntegrable (fun x => f (↑x + ↑y₀ * I)) volume a x₁)
(f_int_x₀_a_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume x₀ a)
(f_int_a_x₁_top : IntervalIntegrable (fun x => f (↑x + ↑y₁ * I)) volume a x₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_bot f_int_a_x₁_bot,
← intervalIntegral.integral_add_adjacent_intervals f_int_x₀_a_top f_int_a_x₁_top]
abel
lemma RectangleIntegralHSplit' {a x₀ x₁ y₀ y₁ : ℝ} (ha : a ∈ [[x₀, x₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (a + y₁ * I) +
RectangleIntegral f (a + y₀ * I) (x₁ + y₁ * I) :=
RectangleIntegralHSplit
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc left_mem_uIcc ha) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.1) (uIcc_subset_uIcc ha right_mem_uIcc) le_rfl)
lemma RectangleIntegralVSplit {b x₀ x₁ y₀ y₁ : ℝ}
(f_int_y₀_b_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume y₀ b)
(f_int_b_y₁_left : IntervalIntegrable (fun y => f (x₀ + y * I)) volume b y₁)
(f_int_y₀_b_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume y₀ b)
(f_int_b_y₁_right : IntervalIntegrable (fun y => f (x₁ + y * I)) volume b y₁) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) := by
dsimp [RectangleIntegral, HIntegral, VIntegral]
simp only [mul_one, mul_zero, add_zero, zero_add, sub_self]
rw [← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_left f_int_b_y₁_left,
← intervalIntegral.integral_add_adjacent_intervals f_int_y₀_b_right f_int_b_y₁_right, ← sub_eq_zero]
simp only [smul_add]; abel
lemma RectangleIntegralVSplit' {b x₀ x₁ y₀ y₁ : ℝ} (hb : b ∈ [[y₀, y₁]])
(hf : RectangleBorderIntegrable f (↑x₀ + ↑y₀ * I) (↑x₁ + ↑y₁ * I)) :
RectangleIntegral f (x₀ + y₀ * I) (x₁ + y₁ * I) =
RectangleIntegral f (x₀ + y₀ * I) (x₁ + b * I) +
RectangleIntegral f (x₀ + b * I) (x₁ + y₁ * I) :=
RectangleIntegralVSplit
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.2) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc left_mem_uIcc hb) le_rfl)
(IntervalIntegrable.mono (by simpa using hf.2.2.1) (uIcc_subset_uIcc hb right_mem_uIcc) le_rfl)
lemma RectanglePullToNhdOfPole' [CompleteSpace E] {z₀ z₁ z₂ z₃ p : ℂ}
(h_orientation : z₀.re ≤ z₃.re ∧ z₀.im ≤ z₃.im ∧ z₁.re ≤ z₂.re ∧ z₁.im ≤ z₂.im)
(hp : Rectangle z₁ z₂ ∈ 𝓝 p) (hz : Rectangle z₁ z₂ ⊆ Rectangle z₀ z₃)
(fHolo : HolomorphicOn f (Rectangle z₀ z₃ \ {p})) :
RectangleIntegral f z₀ z₃ = RectangleIntegral f z₁ z₂ := by
obtain ⟨hz₀_re, hz₀_im, hz₁_re, hz₁_im⟩ := h_orientation
have := rect_subset_iff.mp hz
rw [Rectangle, uIcc_of_le hz₀_re, uIcc_of_le hz₀_im] at this
obtain ⟨⟨⟨_, _⟩, ⟨_, _⟩⟩, ⟨_, _⟩, ⟨_, _⟩⟩ := this
obtain ⟨⟨_, _⟩, ⟨_, _⟩⟩ := (uIoo_of_le hz₁_re) ▸ (uIoo_of_le hz₁_im) ▸ rectangle_mem_nhds_iff.mp hp
obtain ⟨_, _, _, _⟩ := show p.re < z₂.re ∧ p.re < z₃.re ∧ p.im < z₂.im ∧ p.im < z₃.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
obtain ⟨_, _, _, _⟩ := show z₀.re < p.re ∧ z₁.re < p.re ∧ z₀.im < p.im ∧ z₁.im < p.im from
⟨by linarith, by linarith, by linarith, by linarith⟩
have fCont := fHolo.continuousOn
have hbot : RectangleBorderIntegrable f (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have htop : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₃.im * I) := ?_
have hleft : RectangleBorderIntegrable f (↑z₀.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
have hright : RectangleBorderIntegrable f (↑z₁.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) := ?_
all_goals try {
refine (fCont.mono (rectangleBorder_subset_punctured_rect ?_ ?_)).rectangleBorder_integrable
· simp_all
· simpa using ⟨by linarith, by linarith, by linarith, by linarith⟩
}
have hbot' : z₁.im ∈ [[z₀.im, z₃.im]] := ?_
have htop' : z₂.im ∈ [[z₁.im, z₃.im]] := ?_
have hleft' : z₁.re ∈ [[z₀.re, z₃.re]] := ?_
have hright' : z₂.re ∈ [[z₁.re, z₃.re]] := ?_
all_goals try { rw [Set.uIcc_of_le]; constructor; all_goals assumption }
have hbot'' : Rectangle (↑z₀.re + ↑z₀.im * I) (↑z₃.re + ↑z₁.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have htop'' : Rectangle (↑z₀.re + ↑z₂.im * I) (↑z₃.re + ↑z₃.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hleft'' : Rectangle (↑z₀.re + ↑z₁.im * I) (↑z₁.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
have hright'' : Rectangle (↑z₂.re + ↑z₁.im * I) (↑z₃.re + ↑z₂.im * I) ⊆ Rectangle z₀ z₃ \ {p} := ?_
all_goals try { apply rectangle_subset_punctured_rect <;> simp_all }
rw [← re_add_im z₀, ← re_add_im z₃,
RectangleIntegralVSplit' hbot' hbot, fHolo.vanishesOnRectangle hbot'', zero_add,
RectangleIntegralVSplit' htop' htop, fHolo.vanishesOnRectangle htop'', add_zero,
RectangleIntegralHSplit' hleft' hleft, fHolo.vanishesOnRectangle hleft'', zero_add,
RectangleIntegralHSplit' hright' hright, fHolo.vanishesOnRectangle hright'', add_zero,
re_add_im, re_add_im]
/-%%
The next lemma allows to zoom a big rectangle down to a small square, centered at a pole.
\begin{lemma}[RectanglePullToNhdOfPole]\label{RectanglePullToNhdOfPole}\lean{RectanglePullToNhdOfPole}\leanok
If $f$ is holomorphic on a rectangle $z$ and $w$ except at a point $p$, then the integral of $f$
over the rectangle with corners $z$ and $w$ is the same as the integral of $f$ over a small square
centered at $p$.
\end{lemma}
%%-/
/-- Given `f` holomorphic on a rectangle `z` and `w` except at a point `p`, the integral of `f` over
the rectangle with corners `z` and `w` is the same as the integral of `f` over a small square
centered at `p`. -/
lemma RectanglePullToNhdOfPole [CompleteSpace E] {z w p : ℂ} (zRe_lt_wRe : z.re ≤ w.re)
(zIm_lt_wIm : z.im ≤ w.im) (hp : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral f z w = RectangleIntegral f (-c - I * c + p) (c + I * c + p) := by
/-%%
\begin{proof}\uses{HolomorphicOn.vanishesOnRectangle}\leanok
Chop the big rectangle with two vertical cuts and two horizontal cuts into smaller rectangles,
the middle one being the desired square. The integral over each of the outer rectangles
vanishes, since $f$ is holomorphic there. (The constant $c$ being ``small enough'' here just means
that the inner square is strictly contained in the big rectangle.)
%%-/
filter_upwards [Ioo_mem_nhdsWithin_Ioi' zero_lt_one, SmallSquareInRectangle hp]
intro c ⟨cpos, _⟩ hc
simp_rw [mul_comm I]
exact RectanglePullToNhdOfPole' (by simp_all [cpos.le])
(square_mem_nhds p (ne_of_gt cpos)) hc fHolo
--%%\end{proof}
lemma RectanglePullToNhdOfPole'' [CompleteSpace E] {z w p : ℂ} (zRe_le_wRe : z.re ≤ w.re)
(zIm_le_wIm : z.im ≤ w.im) (pInRectInterior : Rectangle z w ∈ 𝓝 p)
(fHolo : HolomorphicOn f (Rectangle z w \ {p})) :
∀ᶠ (c : ℝ) in 𝓝[>]0,
RectangleIntegral' f z w = RectangleIntegral' f (-c - I * c + p) (c + I * c + p) := by
filter_upwards [RectanglePullToNhdOfPole zRe_le_wRe zIm_le_wIm pInRectInterior fHolo] with c h
simp_rw [RectangleIntegral', h]
theorem ResidueTheoremAtOrigin_aux1c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y + I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux1c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (y - I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c (a b : ℝ) :
let f : ℝ → ℂ := fun y => (1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem ResidueTheoremAtOrigin_aux2c' (a b : ℝ) :
let f : ℝ → ℂ := fun y => (-1 + y * I)⁻¹
IntervalIntegrable f volume a b :=
(ContinuousOn.inv₀ (by fun_prop) (by simp [Complex.ext_iff])).intervalIntegrable
theorem RectangleIntegral.const_smul (f : ℂ → E) (z w c : ℂ) :
RectangleIntegral (fun s => c • f s) z w = c • RectangleIntegral f z w := by
simp [RectangleIntegral, HIntegral, VIntegral, smul_add, smul_sub, smul_smul, mul_comm]
theorem RectangleIntegral.const_mul' (f : ℂ → E) (z w c : ℂ) :
RectangleIntegral' (fun s => c • f s) z w = c • RectangleIntegral' f z w := by
simp [RectangleIntegral', RectangleIntegral.const_smul, smul_smul] ; ring_nf
theorem RectangleIntegral.translate (f : ℂ → E) (z w p : ℂ) :
RectangleIntegral (fun s => f (s - p)) z w = RectangleIntegral f (z - p) (w - p) := by
simp_rw [RectangleIntegral, HIntegral, VIntegral, sub_re, sub_im, ← intervalIntegral.integral_comp_sub_right]
congr <;> ext <;> congr 1 <;> simp [Complex.ext_iff]
theorem RectangleIntegral.translate' (f : ℂ → E) (z w p : ℂ) :
RectangleIntegral' (fun s => f (s - p)) z w = RectangleIntegral' f (z - p) (w - p) := by
simp_rw [RectangleIntegral', RectangleIntegral.translate]
lemma Complex.inv_re_add_im : (x + y * I)⁻¹ = (x - I * y) / (x ^ 2 + y ^ 2) := by
rw [Complex.inv_def, div_eq_mul_inv] ; congr <;> simp [conj_ofReal, normSq] <;> ring
lemma sq_add_sq_ne_zero (hy : y ≠ 0) : x ^ 2 + y ^ 2 ≠ 0 := by linarith [sq_nonneg x, (sq_pos_iff y).mpr hy]
lemma continuous_self_div_sq_add_sq (hy : y ≠ 0) : Continuous fun x => x / (x ^ 2 + y ^ 2) :=
continuous_id.div (continuous_id.pow 2 |>.add continuous_const) (λ _ => sq_add_sq_ne_zero hy)
lemma integral_self_div_sq_add_sq (hy : y ≠ 0) : ∫ x in x₁..x₂, x / (x ^ 2 + y ^ 2) =
Real.log (x₂ ^ 2 + y ^ 2) / 2 - Real.log (x₁ ^ 2 + y ^ 2) / 2 := by
let f (x : ℝ) : ℝ := Real.log (x ^ 2 + y ^ 2) / 2
have e1 {x} := HasDerivAt.add_const (by simpa using hasDerivAt_pow 2 x) (y ^ 2)
have e2 {x} : HasDerivAt f (x / (x ^ 2 + y ^ 2)) x := by
convert (e1.log (sq_add_sq_ne_zero hy)).div_const 2 using 1 ; field_simp ; ring
have e3 : deriv f = λ x => x / (x ^ 2 + y ^ 2) := funext (λ _ => e2.deriv)
have e4 : Continuous (deriv f) := by simpa only [e3] using continuous_self_div_sq_add_sq hy
simp_rw [← e2.deriv]
exact integral_deriv_eq_sub (λ _ _ => e2.differentiableAt) <| e4.intervalIntegrable _ _
lemma integral_const_div_sq_add_sq (hy : y ≠ 0) : ∫ x in x₁..x₂, y / (x ^ 2 + y ^ 2) =
arctan (x₂ / y) - arctan (x₁ / y) := by
nth_rewrite 1 [← div_mul_cancel₀ x₁ hy, ← div_mul_cancel₀ x₂ hy]
simp_rw [← mul_integral_comp_mul_right, ← integral_const_mul, ← integral_one_div_one_add_sq]
exact integral_congr <| λ x _ => by field_simp; ring
lemma integral_const_div_self_add_im (hy : y ≠ 0) : ∫ x : ℝ in x₁..x₂, A / (x + y * I) =
A * (Real.log (x₂ ^ 2 + y ^ 2) / 2 - Real.log (x₁ ^ 2 + y ^ 2) / 2) -
A * I * (arctan (x₂ / y) - arctan (x₁ / y)) := by
have e1 {x : ℝ} : A / (x + y * I) = A * x / (x ^ 2 + y ^ 2) - A * I * y / (x ^ 2 + y ^ 2) := by
ring_nf ; simp_rw [inv_re_add_im] ; ring
have e2 : IntervalIntegrable (fun x ↦ A * x / (x ^ 2 + y ^ 2)) volume x₁ x₂ := by
apply Continuous.intervalIntegrable
simp_rw [mul_div_assoc] ; norm_cast
exact continuous_const.mul <| continuous_ofReal.comp <| continuous_self_div_sq_add_sq hy
have e3 : IntervalIntegrable (fun x ↦ A * I * y / (x ^ 2 + y ^ 2)) volume x₁ x₂ := by
apply Continuous.intervalIntegrable
refine continuous_const.div (by continuity) (λ x => ?_)
norm_cast ; exact sq_add_sq_ne_zero hy
simp_rw [integral_congr (λ _ _ => e1), integral_sub e2 e3, mul_div_assoc]
norm_cast
simp_rw [integral_const_mul, intervalIntegral.integral_ofReal, integral_self_div_sq_add_sq hy,
integral_const_div_sq_add_sq hy]
lemma integral_const_div_re_add_self (hx : x ≠ 0) : ∫ y : ℝ in y₁..y₂, A / (x + y * I) =
A / I * (Real.log (y₂ ^ 2 + (-x) ^ 2) / 2 - Real.log (y₁ ^ 2 + (-x) ^ 2) / 2) -
A / I * I * (arctan (y₂ / -x) - arctan (y₁ / -x)) := by
have l1 {y : ℝ} : A / (x + y * I) = A / I / (y + ↑(-x) * I) := by
have e1 : x + y * I ≠ 0 := by contrapose! hx ; simpa using congr_arg re hx
have e2 : y + -(x * I) ≠ 0 := by contrapose! hx ; simpa using congr_arg im hx
field_simp ; ring_nf ; simp
have l2 : -x ≠ 0 := by rwa [neg_ne_zero]
simp_rw [l1, integral_const_div_self_add_im l2]
lemma ResidueTheoremAtOrigin' {z w c : ℂ} (h1 : z.re < 0) (h2 : z.im < 0) (h3 : 0 < w.re) (h4 : 0 < w.im) :
RectangleIntegral (λ s => c / s) z w = 2 * I * π * c := by
simp only [RectangleIntegral, HIntegral, VIntegral, smul_eq_mul]
rw [integral_const_div_re_add_self h1.ne, integral_const_div_re_add_self h3.ne.symm]
rw [integral_const_div_self_add_im h2.ne, integral_const_div_self_add_im h4.ne.symm]
have l1 : z.im * w.re⁻¹ = (w.re * z.im⁻¹)⁻¹ := by group
have l3 := arctan_inv_of_neg <| mul_neg_of_pos_of_neg h3 <| inv_lt_zero.mpr h2
have l4 : w.im * z.re⁻¹ = (z.re * w.im⁻¹)⁻¹ := by group
have l6 := arctan_inv_of_neg <| mul_neg_of_neg_of_pos h1 <| inv_pos.mpr h4
have r1 : z.im * z.re⁻¹ = (z.re * z.im⁻¹)⁻¹ := by group
have r3 := arctan_inv_of_pos <| mul_pos_of_neg_of_neg h1 <| inv_lt_zero.mpr h2
have r4 : w.im * w.re⁻¹ = (w.re * w.im⁻¹)⁻¹ := by group
have r6 := arctan_inv_of_pos <| mul_pos h3 <| inv_pos.mpr h4
ring_nf
simp only [one_div, inv_I, mul_neg, neg_mul, I_sq, one_mul, neg_neg, arctan_neg, ofReal_neg, sub_neg_eq_add]
rw [l1, l3, l4, l6, r1, r3, r4, r6]
ring_nf
simp only [I_sq, ofReal_sub, ofReal_mul, ofReal_ofNat, ofReal_div, ofReal_neg, ofReal_one]
ring_nf
theorem ResidueTheoremInRectangle (zRe_le_wRe : z.re ≤ w.re) (zIm_le_wIm : z.im ≤ w.im)
(pInRectInterior : Rectangle z w ∈ 𝓝 p) : RectangleIntegral' (λ s => c / (s - p)) z w = c := by
simp [rectangle_mem_nhds_iff, mem_reProdIm, uIoo_of_le zRe_le_wRe, uIoo_of_le zIm_le_wIm]
at pInRectInterior
rw [RectangleIntegral.translate', RectangleIntegral']
have : 1 / (2 * ↑π * I) * (2 * I * ↑π * c) = c := by field_simp [two_pi_I_ne_zero] ; ring
rwa [ResidueTheoremAtOrigin'] ; all_goals { simp [*] }
/-%%
\begin{lemma}[ResidueTheoremAtOrigin]\label{ResidueTheoremAtOrigin}
\lean{ResidueTheoremAtOrigin}\leanok
The rectangle (square) integral of $f(s) = 1/s$ with corners $-1-i$ and $1+i$ is equal to $2\pi i$.
\end{lemma}
%%-/
lemma ResidueTheoremAtOrigin : RectangleIntegral' (fun s ↦ 1 / s) (-1 - I) (1 + I) = 1 := by
rw [RectangleIntegral', ResidueTheoremAtOrigin']
all_goals { field_simp [pi_ne_zero] <;> ring }
/-%%
\begin{proof}\leanok
This is a special case of the more general result above.
\end{proof}
%%-/
/-%%
\begin{lemma}[ResidueTheoremOnRectangleWithSimplePole]\label{ResidueTheoremOnRectangleWithSimplePole}
\lean{ResidueTheoremOnRectangleWithSimplePole}\leanok
Suppose that $f$ is a holomorphic function on a rectangle, except for a simple pole
at $p$. By the latter, we mean that there is a function $g$ holomorphic on the rectangle such that, $f = g + A/(s-p)$ for some $A\in\C$. Then the integral of $f$ over the
rectangle is $A$.
\end{lemma}
%%-/
-- TODO: generalize to `f g : ℂ → E`
| lemma ResidueTheoremOnRectangleWithSimplePole {f g : ℂ → ℂ} {z w p A : ℂ}
(zRe_le_wRe : z.re ≤ w.re) (zIm_le_wIm : z.im ≤ w.im)
(pInRectInterior : Rectangle z w ∈ 𝓝 p)
(gHolo : HolomorphicOn g (Rectangle z w))
(principalPart : Set.EqOn (f - fun s ↦ A / (s - p)) (g) (Rectangle z w \ {p})) :
RectangleIntegral' f z w = A | ResidueTheoremOnRectangleWithSimplePole | f36a520 20240122 | 1909a40 20240209 | PrimeNumberTheoremAnd/PrimeNumberTheoremAnd/ResidueCalcOnRectangles.lean | {
"lineInFile": 488,
"tokenPositionInFile": 26862,
"theoremPositionInFile": 53
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": ":= by\n\n have principalPart' : Set.EqOn f (g + (fun s ↦ A / (s - p))) (Rectangle z w \\ {p}) :=\n fun s hs => by rw [Pi.add_apply, ← principalPart hs, Pi.sub_apply, sub_add_cancel]\n\n have : Set.EqOn f (g + (fun s ↦ A / (s - p))) (RectangleBorder z w) :=\n principalPart'.mono <| Set.subset_diff.mpr ⟨rectangleBorder_subset_rectangle z w,\n disjoint_singleton_right.mpr (not_mem_rectangleBorder_of_rectangle_mem_nhds pInRectInterior)⟩\n rw [RectangleIntegral'_congr this]\n\n have t1 : RectangleBorderIntegrable g z w := gHolo.rectangleBorderIntegrable\n have t2 : HolomorphicOn (fun s ↦ A / (s - p)) (Rectangle z w \\ {p}) := by\n apply DifferentiableOn.mono (t := {p}ᶜ)\n · apply DifferentiableOn.div\n · exact differentiableOn_const _\n · exact DifferentiableOn.sub differentiableOn_id (differentiableOn_const _)\n · exact fun x hx => by rw [sub_ne_zero]; exact hx\n · rintro s ⟨_, hs⟩ ; exact hs\n have t3 : RectangleBorderIntegrable (fun s ↦ A / (s - p)) z w :=\n HolomorphicOn.rectangleBorderIntegrable' t2 pInRectInterior\n\n rw [RectangleIntegral', RectangleBorderIntegrable.add t1 t3, smul_add]\n rw [gHolo.vanishesOnRectangle (by rfl), smul_zero, zero_add]\n\n exact ResidueTheoremInRectangle zRe_le_wRe zIm_le_wIm pInRectInterior",
"proofType": "tactic",
"proofLengthLines": 24,
"proofLengthTokens": 1263
} | prime |
import PFR.ForMathlib.CompactProb
import PFR.ForMathlib.Entropy.RuzsaDist
/-!
# The tau functional
Definition of the tau functional and basic facts
## Main definitions:
* `η`: $1/9$
* `τ`: The tau functional $\tau[X_1; X_2] = d[X_1; X_2] + \eta d[X^0_1; X_1] + \eta d[X^0_2; X_2].$
## Main results
* `tau_minimizer_exists`: A pair of random variables minimizing $\tau$ exists.
* `condRuzsaDistance_ge_of_min`: If $X_1,X_2$ is a tau-minimizer with $k = d[X_1;X_2]$, then $d[X'_1|Z, X'_2|W]$ is at least
$$k - \eta (d[X^0_1;X'_1|Z] - d[X^0_1;X_1] ) - \eta (d[X^0_2;X'_2|W] - d[X^0_2;X_2] )$$
for any $X'_1, Z, X'_2, W$.
-/
open MeasureTheory ProbabilityTheory
universe uG
variable (Ω₀₁ Ω₀₂ : Type*) [MeasureSpace Ω₀₁] [MeasureSpace Ω₀₂]
[IsProbabilityMeasure (ℙ : Measure Ω₀₁)] [IsProbabilityMeasure (ℙ : Measure Ω₀₂)]
variable (G : Type uG) [AddCommGroup G] [ElementaryAddCommGroup G 2] [Fintype G] [MeasurableSpace G]
/-- A structure that packages all the fixed information in the main argument. In this way, when
defining the τ functional, we will only only need to refer to the package once in the notation
instead of stating the reference spaces, the reference measures and the reference random
variables.
The η parameter has now been incorporated into the package, in preparation for being able to
manipulate the package. -/
structure refPackage :=
/-- The first variable in a package. -/
X₀₁ : Ω₀₁ → G
/-- The second variable in a package. -/
X₀₂ : Ω₀₂ → G
hmeas1 : Measurable X₀₁
hmeas2 : Measurable X₀₂
η : ℝ
hη : 0 < η
hη' : 8 * η ≤ 1
variable (p : refPackage Ω₀₁ Ω₀₂ G)
variable {Ω₀₁ Ω₀₂ G}
variable {Ω₁ Ω₂ Ω'₁ Ω'₂ : Type*}
/-- If $X_1,X_2$ are two $G$-valued random variables, then
$$ \tau[X_1; X_2] := d[X_1; X_2] + \eta d[X^0_1; X_1] + \eta d[X^0_2; X_2].$$
Here, $X^0_1$ and $X^0_2$ are two random variables fixed once and for all in most of the argument.
To lighten notation, We package `X^0_1` and `X^0_2` in a single object named `p`.
We denote it as `τ[X₁ ; μ₁ # X₂ ; μ₂ | p]` where `p` is a fixed package containing the information
of the reference random variables. When the measurable spaces have a canonical measure `ℙ`, we
can use `τ[X₁ # X₂ | p]`
-/
@[pp_dot] noncomputable def tau {Ω₁ Ω₂ : Type*} [MeasurableSpace Ω₁] [MeasurableSpace Ω₂]
(X₁ : Ω₁ → G) (X₂ : Ω₂ → G) (μ₁ : Measure Ω₁) (μ₂ : Measure Ω₂) : ℝ :=
d[X₁ ; μ₁ # X₂ ; μ₂] + p.η * d[p.X₀₁ ; ℙ # X₁ ; μ₁] + p.η * d[p.X₀₂ ; ℙ # X₂ ; μ₂]
@[inherit_doc tau]
notation3:max "τ[" X₁ " ; " μ₁ " # " X₂ " ; " μ₂ " | " p"]" => tau p X₁ X₂ μ₁ μ₂
@[inherit_doc tau]
notation3:max "τ[" X₁ " # " X₂ " | " p"]" => tau p X₁ X₂ MeasureTheory.MeasureSpace.volume MeasureTheory.MeasureSpace.volume
| lemma continuous_tau_restrict_probabilityMeasure
[TopologicalSpace G] [DiscreteTopology G] [BorelSpace G] :
Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ τ[id ; μ.1 # id ; μ.2 | p]) | continuous_tau_restrict_probabilityMeasure | 623ad58 20231116 | 6854e2a 20231120 | pfr/PFR/TauFunctional.lean | {
"lineInFile": 72,
"tokenPositionInFile": 2703,
"theoremPositionInFile": 4
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n have obs₁ : Continuous\n (fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ d[p.X₀₂ ; ℙ # id ; μ.2]) :=\n Continuous.comp (continuous_rdist_restrict_probabilityMeasure₁' _ _ p.hmeas2) continuous_snd\n have obs₂ : Continuous\n (fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ d[id ; μ.1.toMeasure # id ; μ.2]) :=\n continuous_rdist_restrict_probabilityMeasure\n have obs₃ : Continuous\n (fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ d[p.X₀₁ ; ℙ # id ; μ.1]) :=\n Continuous.comp (continuous_rdist_restrict_probabilityMeasure₁' _ _ p.hmeas1) continuous_fst\n continuity",
"proofType": "tactic",
"proofLengthLines": 11,
"proofLengthTokens": 615
} | pfr |
import PFR.ForMathlib.CompactProb
import PFR.ForMathlib.Entropy.RuzsaDist
/-!
# The tau functional
Definition of the tau functional and basic facts
## Main definitions:
* `η`: $1/9$
* `τ`: The tau functional $\tau[X_1; X_2] = d[X_1; X_2] + \eta d[X^0_1; X_1] + \eta d[X^0_2; X_2].$
## Main results
* `tau_minimizer_exists`: A pair of random variables minimizing $\tau$ exists.
* `condRuzsaDistance_ge_of_min`: If $X_1,X_2$ is a tau-minimizer with $k = d[X_1;X_2]$, then $d[X'_1|Z, X'_2|W]$ is at least
$$k - \eta (d[X^0_1;X'_1|Z] - d[X^0_1;X_1] ) - \eta (d[X^0_2;X'_2|W] - d[X^0_2;X_2] )$$
for any $X'_1, Z, X'_2, W$.
-/
open MeasureTheory ProbabilityTheory
universe uG
variable (Ω₀₁ Ω₀₂ : Type*) [MeasureSpace Ω₀₁] [MeasureSpace Ω₀₂]
[IsProbabilityMeasure (ℙ : Measure Ω₀₁)] [IsProbabilityMeasure (ℙ : Measure Ω₀₂)]
variable (G : Type uG) [AddCommGroup G] [ElementaryAddCommGroup G 2] [Fintype G] [MeasurableSpace G]
/-- A structure that packages all the fixed information in the main argument. In this way, when
defining the τ functional, we will only only need to refer to the package once in the notation
instead of stating the reference spaces, the reference measures and the reference random
variables.
The η parameter has now been incorporated into the package, in preparation for being able to
manipulate the package. -/
structure refPackage :=
/-- The first variable in a package. -/
X₀₁ : Ω₀₁ → G
/-- The second variable in a package. -/
X₀₂ : Ω₀₂ → G
hmeas1 : Measurable X₀₁
hmeas2 : Measurable X₀₂
η : ℝ
hη : 0 < η
hη' : 8 * η ≤ 1
variable (p : refPackage Ω₀₁ Ω₀₂ G)
variable {Ω₀₁ Ω₀₂ G}
variable {Ω₁ Ω₂ Ω'₁ Ω'₂ : Type*}
/-- If $X_1,X_2$ are two $G$-valued random variables, then
$$ \tau[X_1; X_2] := d[X_1; X_2] + \eta d[X^0_1; X_1] + \eta d[X^0_2; X_2].$$
Here, $X^0_1$ and $X^0_2$ are two random variables fixed once and for all in most of the argument.
To lighten notation, We package `X^0_1` and `X^0_2` in a single object named `p`.
We denote it as `τ[X₁ ; μ₁ # X₂ ; μ₂ | p]` where `p` is a fixed package containing the information
of the reference random variables. When the measurable spaces have a canonical measure `ℙ`, we
can use `τ[X₁ # X₂ | p]`
-/
@[pp_dot] noncomputable def tau {Ω₁ Ω₂ : Type*} [MeasurableSpace Ω₁] [MeasurableSpace Ω₂]
(X₁ : Ω₁ → G) (X₂ : Ω₂ → G) (μ₁ : Measure Ω₁) (μ₂ : Measure Ω₂) : ℝ :=
d[X₁ ; μ₁ # X₂ ; μ₂] + p.η * d[p.X₀₁ ; ℙ # X₁ ; μ₁] + p.η * d[p.X₀₂ ; ℙ # X₂ ; μ₂]
@[inherit_doc tau]
notation3:max "τ[" X₁ " ; " μ₁ " # " X₂ " ; " μ₂ " | " p"]" => tau p X₁ X₂ μ₁ μ₂
@[inherit_doc tau]
notation3:max "τ[" X₁ " # " X₂ " | " p"]" => tau p X₁ X₂ MeasureTheory.MeasureSpace.volume MeasureTheory.MeasureSpace.volume
lemma continuous_tau_restrict_probabilityMeasure
[TopologicalSpace G] [DiscreteTopology G] [BorelSpace G] :
Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ τ[id ; μ.1 # id ; μ.2 | p]) := by
have obs₁ : Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ d[p.X₀₂ ; ℙ # id ; μ.2]) :=
Continuous.comp (continuous_rdist_restrict_probabilityMeasure₁' _ _ p.hmeas2) continuous_snd
have obs₂ : Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ d[id ; μ.1.toMeasure # id ; μ.2]) :=
continuous_rdist_restrict_probabilityMeasure
have obs₃ : Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ d[p.X₀₁ ; ℙ # id ; μ.1]) :=
Continuous.comp (continuous_rdist_restrict_probabilityMeasure₁' _ _ p.hmeas1) continuous_fst
continuity
/-- If $X'_1, X'_2$ are copies of $X_1,X_2$, then $\tau[X'_1;X'_2] = \tau[X_1;X_2]$. -/
| lemma ProbabilityTheory.IdentDistrib.tau_eq [MeasurableSpace Ω₁] [MeasurableSpace Ω₂]
[MeasurableSpace Ω'₁] [MeasurableSpace Ω'₂]
{μ₁ : Measure Ω₁} {μ₂ : Measure Ω₂} {μ'₁ : Measure Ω'₁} {μ'₂ : Measure Ω'₂}
{X₁ : Ω₁ → G} {X₂ : Ω₂ → G} {X'₁ : Ω'₁ → G} {X'₂ : Ω'₂ → G}
(h₁ : IdentDistrib X₁ X'₁ μ₁ μ'₁) (h₂ : IdentDistrib X₂ X'₂ μ₂ μ'₂) :
τ[X₁ ; μ₁ # X₂ ; μ₂ | p] = τ[X'₁ ; μ'₁ # X'₂ ; μ'₂ | p] | ProbabilityTheory.IdentDistrib.tau_eq | 623ad58 20231116 | 828bcd7 20231120 | pfr/PFR/TauFunctional.lean | {
"lineInFile": 88,
"tokenPositionInFile": 3629,
"theoremPositionInFile": 5
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n simp only [tau]\n rw [(IdentDistrib.refl p.hmeas1.aemeasurable).rdist_eq h₁,\n (IdentDistrib.refl p.hmeas2.aemeasurable).rdist_eq h₂,\n h₁.rdist_eq h₂]",
"proofType": "tactic",
"proofLengthLines": 5,
"proofLengthTokens": 164
} | pfr |
import PFR.ForMathlib.CompactProb
import PFR.ForMathlib.Entropy.RuzsaDist
/-!
# The tau functional
Definition of the tau functional and basic facts
## Main definitions:
* `η`: $1/9$
* `τ`: The tau functional $\tau[X_1; X_2] = d[X_1; X_2] + \eta d[X^0_1; X_1] + \eta d[X^0_2; X_2].$
## Main results
* `tau_minimizer_exists`: A pair of random variables minimizing $\tau$ exists.
* `condRuzsaDistance_ge_of_min`: If $X_1,X_2$ is a tau-minimizer with $k = d[X_1;X_2]$, then $d[X'_1|Z, X'_2|W]$ is at least
$$k - \eta (d[X^0_1;X'_1|Z] - d[X^0_1;X_1] ) - \eta (d[X^0_2;X'_2|W] - d[X^0_2;X_2] )$$
for any $X'_1, Z, X'_2, W$.
-/
open MeasureTheory ProbabilityTheory
universe uG
variable (Ω₀₁ Ω₀₂ : Type*) [MeasureSpace Ω₀₁] [MeasureSpace Ω₀₂]
[IsProbabilityMeasure (ℙ : Measure Ω₀₁)] [IsProbabilityMeasure (ℙ : Measure Ω₀₂)]
variable (G : Type uG) [AddCommGroup G] [ElementaryAddCommGroup G 2] [Fintype G] [MeasurableSpace G]
/-- A structure that packages all the fixed information in the main argument. In this way, when
defining the τ functional, we will only only need to refer to the package once in the notation
instead of stating the reference spaces, the reference measures and the reference random
variables.
The η parameter has now been incorporated into the package, in preparation for being able to
manipulate the package. -/
structure refPackage :=
/-- The first variable in a package. -/
X₀₁ : Ω₀₁ → G
/-- The second variable in a package. -/
X₀₂ : Ω₀₂ → G
hmeas1 : Measurable X₀₁
hmeas2 : Measurable X₀₂
η : ℝ
hη : 0 < η
hη' : 8 * η ≤ 1
variable (p : refPackage Ω₀₁ Ω₀₂ G)
variable {Ω₀₁ Ω₀₂ G}
variable {Ω₁ Ω₂ Ω'₁ Ω'₂ : Type*}
/-- If $X_1,X_2$ are two $G$-valued random variables, then
$$ \tau[X_1; X_2] := d[X_1; X_2] + \eta d[X^0_1; X_1] + \eta d[X^0_2; X_2].$$
Here, $X^0_1$ and $X^0_2$ are two random variables fixed once and for all in most of the argument.
To lighten notation, We package `X^0_1` and `X^0_2` in a single object named `p`.
We denote it as `τ[X₁ ; μ₁ # X₂ ; μ₂ | p]` where `p` is a fixed package containing the information
of the reference random variables. When the measurable spaces have a canonical measure `ℙ`, we
can use `τ[X₁ # X₂ | p]`
-/
@[pp_dot] noncomputable def tau {Ω₁ Ω₂ : Type*} [MeasurableSpace Ω₁] [MeasurableSpace Ω₂]
(X₁ : Ω₁ → G) (X₂ : Ω₂ → G) (μ₁ : Measure Ω₁) (μ₂ : Measure Ω₂) : ℝ :=
d[X₁ ; μ₁ # X₂ ; μ₂] + p.η * d[p.X₀₁ ; ℙ # X₁ ; μ₁] + p.η * d[p.X₀₂ ; ℙ # X₂ ; μ₂]
@[inherit_doc tau]
notation3:max "τ[" X₁ " ; " μ₁ " # " X₂ " ; " μ₂ " | " p"]" => tau p X₁ X₂ μ₁ μ₂
@[inherit_doc tau]
notation3:max "τ[" X₁ " # " X₂ " | " p"]" => tau p X₁ X₂ MeasureTheory.MeasureSpace.volume MeasureTheory.MeasureSpace.volume
lemma continuous_tau_restrict_probabilityMeasure
[TopologicalSpace G] [DiscreteTopology G] [BorelSpace G] :
Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ τ[id ; μ.1 # id ; μ.2 | p]) := by
have obs₁ : Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ d[p.X₀₂ ; ℙ # id ; μ.2]) :=
Continuous.comp (continuous_rdist_restrict_probabilityMeasure₁' _ _ p.hmeas2) continuous_snd
have obs₂ : Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ d[id ; μ.1.toMeasure # id ; μ.2]) :=
continuous_rdist_restrict_probabilityMeasure
have obs₃ : Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ d[p.X₀₁ ; ℙ # id ; μ.1]) :=
Continuous.comp (continuous_rdist_restrict_probabilityMeasure₁' _ _ p.hmeas1) continuous_fst
continuity
/-- If $X'_1, X'_2$ are copies of $X_1,X_2$, then $\tau[X'_1;X'_2] = \tau[X_1;X_2]$. -/
lemma ProbabilityTheory.IdentDistrib.tau_eq [MeasurableSpace Ω₁] [MeasurableSpace Ω₂]
[MeasurableSpace Ω'₁] [MeasurableSpace Ω'₂]
{μ₁ : Measure Ω₁} {μ₂ : Measure Ω₂} {μ'₁ : Measure Ω'₁} {μ'₂ : Measure Ω'₂}
{X₁ : Ω₁ → G} {X₂ : Ω₂ → G} {X'₁ : Ω'₁ → G} {X'₂ : Ω'₂ → G}
(h₁ : IdentDistrib X₁ X'₁ μ₁ μ'₁) (h₂ : IdentDistrib X₂ X'₂ μ₂ μ'₂) :
τ[X₁ ; μ₁ # X₂ ; μ₂ | p] = τ[X'₁ ; μ'₁ # X'₂ ; μ'₂ | p] := by
simp only [tau]
rw [(IdentDistrib.refl p.hmeas1.aemeasurable).rdist_eq h₁,
(IdentDistrib.refl p.hmeas2.aemeasurable).rdist_eq h₂,
h₁.rdist_eq h₂]
/-- Property recording the fact that two random variables minimize the tau functional. Expressed
in terms of measures on the group to avoid quantifying over all spaces, but this implies comparison
with any pair of random variables, see Lemma `is_tau_min`. -/
def tau_minimizes {Ω : Type*} [MeasureSpace Ω] (X₁ : Ω → G) (X₂ : Ω → G) : Prop :=
∀ (ν₁ : Measure G) (ν₂ : Measure G), IsProbabilityMeasure ν₁ → IsProbabilityMeasure ν₂ →
τ[X₁ # X₂ | p] ≤ τ[id ; ν₁ # id ; ν₂ | p]
/-- If $X'_1, X'_2$ are copies of $X_1,X_2$, then $X_1, X_2$ minimize $\tau$ iff $X_1', X_2'$ do. -/
| lemma ProbabilityTheory.IdentDistrib.tau_minimizes [MeasureSpace Ω]
[MeasureSpace Ω']
{X₁ X₂ : Ω → G} {X₁' X₂' : Ω' → G}
(h₁ : IdentDistrib X₁ X₁') (h₂ : IdentDistrib X₂ X₂') :
tau_minimizes p X₁ X₂ ↔ tau_minimizes p X₁' X₂' | ProbabilityTheory.IdentDistrib.tau_minimizes | 623ad58 20231116 | 0b960b2 20231128 | pfr/PFR/TauFunctional.lean | {
"lineInFile": 107,
"tokenPositionInFile": 4793,
"theoremPositionInFile": 7
} | {
"inFilePremises": true,
"repositoryPremises": false
} | {
"hasProof": true,
"proof": "by\n simp_rw [_root_.tau_minimizes, h₁.tau_eq p h₂]",
"proofType": "tactic",
"proofLengthLines": 2,
"proofLengthTokens": 51
} | pfr |
import PFR.ForMathlib.CompactProb
import PFR.ForMathlib.Entropy.RuzsaDist
/-!
# The tau functional
Definition of the tau functional and basic facts
## Main definitions:
* `η`: $1/9$
* `τ`: The tau functional $\tau[X_1; X_2] = d[X_1; X_2] + \eta d[X^0_1; X_1] + \eta d[X^0_2; X_2].$
## Main results
* `tau_minimizer_exists`: A pair of random variables minimizing $\tau$ exists.
* `condRuzsaDistance_ge_of_min`: If $X_1,X_2$ is a tau-minimizer with $k = d[X_1;X_2]$, then $d[X'_1|Z, X'_2|W]$ is at least
$$k - \eta (d[X^0_1;X'_1|Z] - d[X^0_1;X_1] ) - \eta (d[X^0_2;X'_2|W] - d[X^0_2;X_2] )$$
for any $X'_1, Z, X'_2, W$.
-/
open MeasureTheory ProbabilityTheory
universe uG
variable (Ω₀₁ Ω₀₂ : Type*) [MeasureSpace Ω₀₁] [MeasureSpace Ω₀₂]
[IsProbabilityMeasure (ℙ : Measure Ω₀₁)] [IsProbabilityMeasure (ℙ : Measure Ω₀₂)]
variable (G : Type uG) [AddCommGroup G] [ElementaryAddCommGroup G 2] [Fintype G] [MeasurableSpace G]
/-- A structure that packages all the fixed information in the main argument. In this way, when
defining the τ functional, we will only only need to refer to the package once in the notation
instead of stating the reference spaces, the reference measures and the reference random
variables.
The η parameter has now been incorporated into the package, in preparation for being able to
manipulate the package. -/
structure refPackage :=
/-- The first variable in a package. -/
X₀₁ : Ω₀₁ → G
/-- The second variable in a package. -/
X₀₂ : Ω₀₂ → G
hmeas1 : Measurable X₀₁
hmeas2 : Measurable X₀₂
η : ℝ
hη : 0 < η
hη' : 8 * η ≤ 1
variable (p : refPackage Ω₀₁ Ω₀₂ G)
variable {Ω₀₁ Ω₀₂ G}
variable {Ω₁ Ω₂ Ω'₁ Ω'₂ : Type*}
/-- If $X_1,X_2$ are two $G$-valued random variables, then
$$ \tau[X_1; X_2] := d[X_1; X_2] + \eta d[X^0_1; X_1] + \eta d[X^0_2; X_2].$$
Here, $X^0_1$ and $X^0_2$ are two random variables fixed once and for all in most of the argument.
To lighten notation, We package `X^0_1` and `X^0_2` in a single object named `p`.
We denote it as `τ[X₁ ; μ₁ # X₂ ; μ₂ | p]` where `p` is a fixed package containing the information
of the reference random variables. When the measurable spaces have a canonical measure `ℙ`, we
can use `τ[X₁ # X₂ | p]`
-/
@[pp_dot] noncomputable def tau {Ω₁ Ω₂ : Type*} [MeasurableSpace Ω₁] [MeasurableSpace Ω₂]
(X₁ : Ω₁ → G) (X₂ : Ω₂ → G) (μ₁ : Measure Ω₁) (μ₂ : Measure Ω₂) : ℝ :=
d[X₁ ; μ₁ # X₂ ; μ₂] + p.η * d[p.X₀₁ ; ℙ # X₁ ; μ₁] + p.η * d[p.X₀₂ ; ℙ # X₂ ; μ₂]
@[inherit_doc tau]
notation3:max "τ[" X₁ " ; " μ₁ " # " X₂ " ; " μ₂ " | " p"]" => tau p X₁ X₂ μ₁ μ₂
@[inherit_doc tau]
notation3:max "τ[" X₁ " # " X₂ " | " p"]" => tau p X₁ X₂ MeasureTheory.MeasureSpace.volume MeasureTheory.MeasureSpace.volume
lemma continuous_tau_restrict_probabilityMeasure
[TopologicalSpace G] [DiscreteTopology G] [BorelSpace G] :
Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ τ[id ; μ.1 # id ; μ.2 | p]) := by
have obs₁ : Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ d[p.X₀₂ ; ℙ # id ; μ.2]) :=
Continuous.comp (continuous_rdist_restrict_probabilityMeasure₁' _ _ p.hmeas2) continuous_snd
have obs₂ : Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ d[id ; μ.1.toMeasure # id ; μ.2]) :=
continuous_rdist_restrict_probabilityMeasure
have obs₃ : Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ d[p.X₀₁ ; ℙ # id ; μ.1]) :=
Continuous.comp (continuous_rdist_restrict_probabilityMeasure₁' _ _ p.hmeas1) continuous_fst
continuity
/-- If $X'_1, X'_2$ are copies of $X_1,X_2$, then $\tau[X'_1;X'_2] = \tau[X_1;X_2]$. -/
lemma ProbabilityTheory.IdentDistrib.tau_eq [MeasurableSpace Ω₁] [MeasurableSpace Ω₂]
[MeasurableSpace Ω'₁] [MeasurableSpace Ω'₂]
{μ₁ : Measure Ω₁} {μ₂ : Measure Ω₂} {μ'₁ : Measure Ω'₁} {μ'₂ : Measure Ω'₂}
{X₁ : Ω₁ → G} {X₂ : Ω₂ → G} {X'₁ : Ω'₁ → G} {X'₂ : Ω'₂ → G}
(h₁ : IdentDistrib X₁ X'₁ μ₁ μ'₁) (h₂ : IdentDistrib X₂ X'₂ μ₂ μ'₂) :
τ[X₁ ; μ₁ # X₂ ; μ₂ | p] = τ[X'₁ ; μ'₁ # X'₂ ; μ'₂ | p] := by
simp only [tau]
rw [(IdentDistrib.refl p.hmeas1.aemeasurable).rdist_eq h₁,
(IdentDistrib.refl p.hmeas2.aemeasurable).rdist_eq h₂,
h₁.rdist_eq h₂]
/-- Property recording the fact that two random variables minimize the tau functional. Expressed
in terms of measures on the group to avoid quantifying over all spaces, but this implies comparison
with any pair of random variables, see Lemma `is_tau_min`. -/
def tau_minimizes {Ω : Type*} [MeasureSpace Ω] (X₁ : Ω → G) (X₂ : Ω → G) : Prop :=
∀ (ν₁ : Measure G) (ν₂ : Measure G), IsProbabilityMeasure ν₁ → IsProbabilityMeasure ν₂ →
τ[X₁ # X₂ | p] ≤ τ[id ; ν₁ # id ; ν₂ | p]
/-- If $X'_1, X'_2$ are copies of $X_1,X_2$, then $X_1, X_2$ minimize $\tau$ iff $X_1', X_2'$ do. -/
lemma ProbabilityTheory.IdentDistrib.tau_minimizes [MeasureSpace Ω]
[MeasureSpace Ω']
{X₁ X₂ : Ω → G} {X₁' X₂' : Ω' → G}
(h₁ : IdentDistrib X₁ X₁') (h₂ : IdentDistrib X₂ X₂') :
tau_minimizes p X₁ X₂ ↔ tau_minimizes p X₁' X₂' := by
simp_rw [_root_.tau_minimizes, h₁.tau_eq p h₂]
/-- A pair of measures minimizing $\tau$ exists. -/
| lemma tau_min_exists_measure [MeasurableSingletonClass G] :
∃ (μ : Measure G × Measure G),
IsProbabilityMeasure μ.1 ∧ IsProbabilityMeasure μ.2 ∧
∀ (ν₁ : Measure G) (ν₂ : Measure G), IsProbabilityMeasure ν₁ → IsProbabilityMeasure ν₂ →
τ[id ; μ.1 # id ; μ.2 | p] ≤ τ[id ; ν₁ # id ; ν₂ | p] | tau_min_exists_measure | 623ad58 20231116 | 3c88319 20231123 | pfr/PFR/TauFunctional.lean | {
"lineInFile": 115,
"tokenPositionInFile": 5142,
"theoremPositionInFile": 8
} | {
"inFilePremises": true,
"repositoryPremises": false
} | {
"hasProof": true,
"proof": "by\n let _i : TopologicalSpace G := (⊥ : TopologicalSpace G) -- Equip G with the discrete topology.\n have : DiscreteTopology G := ⟨rfl⟩\n have GG_cpt : CompactSpace (ProbabilityMeasure G × ProbabilityMeasure G) := inferInstance\n let T : ProbabilityMeasure G × ProbabilityMeasure G → ℝ := -- restrict τ to the compact subspace\n fun ⟨μ₁, μ₂⟩ ↦ τ[id ; μ₁ # id ; μ₂ | p]\n have T_cont : Continuous T := by apply continuous_tau_restrict_probabilityMeasure\n haveI : Inhabited G := ⟨0⟩ -- Need to record this for Lean to know that proba measures exist.\n obtain ⟨μ, _, hμ⟩ := @IsCompact.exists_isMinOn ℝ (ProbabilityMeasure G × ProbabilityMeasure G)\n _ _ _ _ Set.univ isCompact_univ ⟨default, trivial⟩ T T_cont.continuousOn\n use ⟨μ.1.toMeasure, μ.2.toMeasure⟩\n refine ⟨μ.1.prop, μ.2.prop, ?_⟩\n intro ν₁ ν₂ Pν₁ Pν₂\n rw [isMinOn_univ_iff] at hμ\n let ν : ProbabilityMeasure G × ProbabilityMeasure G := ⟨⟨ν₁, Pν₁⟩, ν₂, Pν₂⟩\n exact hμ ν",
"proofType": "tactic",
"proofLengthLines": 16,
"proofLengthTokens": 961
} | pfr |
import PFR.ForMathlib.CompactProb
import PFR.ForMathlib.Entropy.RuzsaDist
/-!
# The tau functional
Definition of the tau functional and basic facts
## Main definitions:
* `η`: $1/9$
* `τ`: The tau functional $\tau[X_1; X_2] = d[X_1; X_2] + \eta d[X^0_1; X_1] + \eta d[X^0_2; X_2].$
## Main results
* `tau_minimizer_exists`: A pair of random variables minimizing $\tau$ exists.
* `condRuzsaDistance_ge_of_min`: If $X_1,X_2$ is a tau-minimizer with $k = d[X_1;X_2]$, then $d[X'_1|Z, X'_2|W]$ is at least
$$k - \eta (d[X^0_1;X'_1|Z] - d[X^0_1;X_1] ) - \eta (d[X^0_2;X'_2|W] - d[X^0_2;X_2] )$$
for any $X'_1, Z, X'_2, W$.
-/
open MeasureTheory ProbabilityTheory
universe uG
variable (Ω₀₁ Ω₀₂ : Type*) [MeasureSpace Ω₀₁] [MeasureSpace Ω₀₂]
[IsProbabilityMeasure (ℙ : Measure Ω₀₁)] [IsProbabilityMeasure (ℙ : Measure Ω₀₂)]
variable (G : Type uG) [AddCommGroup G] [ElementaryAddCommGroup G 2] [Fintype G] [MeasurableSpace G]
/-- A structure that packages all the fixed information in the main argument. In this way, when
defining the τ functional, we will only only need to refer to the package once in the notation
instead of stating the reference spaces, the reference measures and the reference random
variables.
The η parameter has now been incorporated into the package, in preparation for being able to
manipulate the package. -/
structure refPackage :=
/-- The first variable in a package. -/
X₀₁ : Ω₀₁ → G
/-- The second variable in a package. -/
X₀₂ : Ω₀₂ → G
hmeas1 : Measurable X₀₁
hmeas2 : Measurable X₀₂
η : ℝ
hη : 0 < η
hη' : 8 * η ≤ 1
variable (p : refPackage Ω₀₁ Ω₀₂ G)
variable {Ω₀₁ Ω₀₂ G}
variable {Ω₁ Ω₂ Ω'₁ Ω'₂ : Type*}
/-- If $X_1,X_2$ are two $G$-valued random variables, then
$$ \tau[X_1; X_2] := d[X_1; X_2] + \eta d[X^0_1; X_1] + \eta d[X^0_2; X_2].$$
Here, $X^0_1$ and $X^0_2$ are two random variables fixed once and for all in most of the argument.
To lighten notation, We package `X^0_1` and `X^0_2` in a single object named `p`.
We denote it as `τ[X₁ ; μ₁ # X₂ ; μ₂ | p]` where `p` is a fixed package containing the information
of the reference random variables. When the measurable spaces have a canonical measure `ℙ`, we
can use `τ[X₁ # X₂ | p]`
-/
@[pp_dot] noncomputable def tau {Ω₁ Ω₂ : Type*} [MeasurableSpace Ω₁] [MeasurableSpace Ω₂]
(X₁ : Ω₁ → G) (X₂ : Ω₂ → G) (μ₁ : Measure Ω₁) (μ₂ : Measure Ω₂) : ℝ :=
d[X₁ ; μ₁ # X₂ ; μ₂] + p.η * d[p.X₀₁ ; ℙ # X₁ ; μ₁] + p.η * d[p.X₀₂ ; ℙ # X₂ ; μ₂]
@[inherit_doc tau]
notation3:max "τ[" X₁ " ; " μ₁ " # " X₂ " ; " μ₂ " | " p"]" => tau p X₁ X₂ μ₁ μ₂
@[inherit_doc tau]
notation3:max "τ[" X₁ " # " X₂ " | " p"]" => tau p X₁ X₂ MeasureTheory.MeasureSpace.volume MeasureTheory.MeasureSpace.volume
lemma continuous_tau_restrict_probabilityMeasure
[TopologicalSpace G] [DiscreteTopology G] [BorelSpace G] :
Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ τ[id ; μ.1 # id ; μ.2 | p]) := by
have obs₁ : Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ d[p.X₀₂ ; ℙ # id ; μ.2]) :=
Continuous.comp (continuous_rdist_restrict_probabilityMeasure₁' _ _ p.hmeas2) continuous_snd
have obs₂ : Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ d[id ; μ.1.toMeasure # id ; μ.2]) :=
continuous_rdist_restrict_probabilityMeasure
have obs₃ : Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ d[p.X₀₁ ; ℙ # id ; μ.1]) :=
Continuous.comp (continuous_rdist_restrict_probabilityMeasure₁' _ _ p.hmeas1) continuous_fst
continuity
/-- If $X'_1, X'_2$ are copies of $X_1,X_2$, then $\tau[X'_1;X'_2] = \tau[X_1;X_2]$. -/
lemma ProbabilityTheory.IdentDistrib.tau_eq [MeasurableSpace Ω₁] [MeasurableSpace Ω₂]
[MeasurableSpace Ω'₁] [MeasurableSpace Ω'₂]
{μ₁ : Measure Ω₁} {μ₂ : Measure Ω₂} {μ'₁ : Measure Ω'₁} {μ'₂ : Measure Ω'₂}
{X₁ : Ω₁ → G} {X₂ : Ω₂ → G} {X'₁ : Ω'₁ → G} {X'₂ : Ω'₂ → G}
(h₁ : IdentDistrib X₁ X'₁ μ₁ μ'₁) (h₂ : IdentDistrib X₂ X'₂ μ₂ μ'₂) :
τ[X₁ ; μ₁ # X₂ ; μ₂ | p] = τ[X'₁ ; μ'₁ # X'₂ ; μ'₂ | p] := by
simp only [tau]
rw [(IdentDistrib.refl p.hmeas1.aemeasurable).rdist_eq h₁,
(IdentDistrib.refl p.hmeas2.aemeasurable).rdist_eq h₂,
h₁.rdist_eq h₂]
/-- Property recording the fact that two random variables minimize the tau functional. Expressed
in terms of measures on the group to avoid quantifying over all spaces, but this implies comparison
with any pair of random variables, see Lemma `is_tau_min`. -/
def tau_minimizes {Ω : Type*} [MeasureSpace Ω] (X₁ : Ω → G) (X₂ : Ω → G) : Prop :=
∀ (ν₁ : Measure G) (ν₂ : Measure G), IsProbabilityMeasure ν₁ → IsProbabilityMeasure ν₂ →
τ[X₁ # X₂ | p] ≤ τ[id ; ν₁ # id ; ν₂ | p]
/-- If $X'_1, X'_2$ are copies of $X_1,X_2$, then $X_1, X_2$ minimize $\tau$ iff $X_1', X_2'$ do. -/
lemma ProbabilityTheory.IdentDistrib.tau_minimizes [MeasureSpace Ω]
[MeasureSpace Ω']
{X₁ X₂ : Ω → G} {X₁' X₂' : Ω' → G}
(h₁ : IdentDistrib X₁ X₁') (h₂ : IdentDistrib X₂ X₂') :
tau_minimizes p X₁ X₂ ↔ tau_minimizes p X₁' X₂' := by
simp_rw [_root_.tau_minimizes, h₁.tau_eq p h₂]
/-- A pair of measures minimizing $\tau$ exists. -/
lemma tau_min_exists_measure [MeasurableSingletonClass G] :
∃ (μ : Measure G × Measure G),
IsProbabilityMeasure μ.1 ∧ IsProbabilityMeasure μ.2 ∧
∀ (ν₁ : Measure G) (ν₂ : Measure G), IsProbabilityMeasure ν₁ → IsProbabilityMeasure ν₂ →
τ[id ; μ.1 # id ; μ.2 | p] ≤ τ[id ; ν₁ # id ; ν₂ | p] := by
let _i : TopologicalSpace G := (⊥ : TopologicalSpace G) -- Equip G with the discrete topology.
have : DiscreteTopology G := ⟨rfl⟩
have GG_cpt : CompactSpace (ProbabilityMeasure G × ProbabilityMeasure G) := inferInstance
let T : ProbabilityMeasure G × ProbabilityMeasure G → ℝ := -- restrict τ to the compact subspace
fun ⟨μ₁, μ₂⟩ ↦ τ[id ; μ₁ # id ; μ₂ | p]
have T_cont : Continuous T := by apply continuous_tau_restrict_probabilityMeasure
haveI : Inhabited G := ⟨0⟩ -- Need to record this for Lean to know that proba measures exist.
obtain ⟨μ, _, hμ⟩ := @IsCompact.exists_isMinOn ℝ (ProbabilityMeasure G × ProbabilityMeasure G)
_ _ _ _ Set.univ isCompact_univ ⟨default, trivial⟩ T T_cont.continuousOn
use ⟨μ.1.toMeasure, μ.2.toMeasure⟩
refine ⟨μ.1.prop, μ.2.prop, ?_⟩
intro ν₁ ν₂ Pν₁ Pν₂
rw [isMinOn_univ_iff] at hμ
let ν : ProbabilityMeasure G × ProbabilityMeasure G := ⟨⟨ν₁, Pν₁⟩, ν₂, Pν₂⟩
exact hμ ν
/-- A pair of random variables minimizing $τ$ exists. -/
| lemma tau_minimizer_exists [MeasurableSingletonClass G] :
∃ (Ω : Type uG) (mΩ : MeasureSpace Ω) (X₁ : Ω → G) (X₂ : Ω → G),
Measurable X₁ ∧ Measurable X₂ ∧ IsProbabilityMeasure (ℙ : Measure Ω) ∧
tau_minimizes p X₁ X₂ | tau_minimizer_exists | 623ad58 20231116 | 3c88319 20231123 | pfr/PFR/TauFunctional.lean | {
"lineInFile": 137,
"tokenPositionInFile": 6471,
"theoremPositionInFile": 9
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n let μ := (tau_min_exists_measure p).choose\n have : IsProbabilityMeasure μ.1 := (tau_min_exists_measure p).choose_spec.1\n have : IsProbabilityMeasure μ.2 := (tau_min_exists_measure p).choose_spec.2.1\n have P : IsProbabilityMeasure (μ.1.prod μ.2) := by infer_instance\n let M : MeasureSpace (G × G) := ⟨μ.1.prod μ.2⟩\n refine ⟨G × G, M, Prod.fst, Prod.snd, measurable_fst, measurable_snd, P, ?_⟩\n intro ν₁ ν₂ h₁ h₂\n have A : τ[@Prod.fst G G # @Prod.snd G G | p] = τ[id ; μ.1 # id ; μ.2 | p] :=\n ProbabilityTheory.IdentDistrib.tau_eq p IdentDistrib.fst_id IdentDistrib.snd_id\n convert (tau_min_exists_measure p).choose_spec.2.2 ν₁ ν₂ h₁ h₂",
"proofType": "tactic",
"proofLengthLines": 11,
"proofLengthTokens": 650
} | pfr |
import PFR.ForMathlib.CompactProb
import PFR.ForMathlib.Entropy.RuzsaDist
/-!
# The tau functional
Definition of the tau functional and basic facts
## Main definitions:
* `η`: $1/9$
* `τ`: The tau functional $\tau[X_1; X_2] = d[X_1; X_2] + \eta d[X^0_1; X_1] + \eta d[X^0_2; X_2].$
## Main results
* `tau_minimizer_exists`: A pair of random variables minimizing $\tau$ exists.
* `condRuzsaDistance_ge_of_min`: If $X_1,X_2$ is a tau-minimizer with $k = d[X_1;X_2]$, then $d[X'_1|Z, X'_2|W]$ is at least
$$k - \eta (d[X^0_1;X'_1|Z] - d[X^0_1;X_1] ) - \eta (d[X^0_2;X'_2|W] - d[X^0_2;X_2] )$$
for any $X'_1, Z, X'_2, W$.
-/
open MeasureTheory ProbabilityTheory
universe uG
variable (Ω₀₁ Ω₀₂ : Type*) [MeasureSpace Ω₀₁] [MeasureSpace Ω₀₂]
[IsProbabilityMeasure (ℙ : Measure Ω₀₁)] [IsProbabilityMeasure (ℙ : Measure Ω₀₂)]
variable (G : Type uG) [AddCommGroup G] [ElementaryAddCommGroup G 2] [Fintype G] [MeasurableSpace G]
/-- A structure that packages all the fixed information in the main argument. In this way, when
defining the τ functional, we will only only need to refer to the package once in the notation
instead of stating the reference spaces, the reference measures and the reference random
variables.
The η parameter has now been incorporated into the package, in preparation for being able to
manipulate the package. -/
structure refPackage :=
/-- The first variable in a package. -/
X₀₁ : Ω₀₁ → G
/-- The second variable in a package. -/
X₀₂ : Ω₀₂ → G
hmeas1 : Measurable X₀₁
hmeas2 : Measurable X₀₂
η : ℝ
hη : 0 < η
hη' : 8 * η ≤ 1
variable (p : refPackage Ω₀₁ Ω₀₂ G)
variable {Ω₀₁ Ω₀₂ G}
variable {Ω₁ Ω₂ Ω'₁ Ω'₂ : Type*}
/-- If $X_1,X_2$ are two $G$-valued random variables, then
$$ \tau[X_1; X_2] := d[X_1; X_2] + \eta d[X^0_1; X_1] + \eta d[X^0_2; X_2].$$
Here, $X^0_1$ and $X^0_2$ are two random variables fixed once and for all in most of the argument.
To lighten notation, We package `X^0_1` and `X^0_2` in a single object named `p`.
We denote it as `τ[X₁ ; μ₁ # X₂ ; μ₂ | p]` where `p` is a fixed package containing the information
of the reference random variables. When the measurable spaces have a canonical measure `ℙ`, we
can use `τ[X₁ # X₂ | p]`
-/
@[pp_dot] noncomputable def tau {Ω₁ Ω₂ : Type*} [MeasurableSpace Ω₁] [MeasurableSpace Ω₂]
(X₁ : Ω₁ → G) (X₂ : Ω₂ → G) (μ₁ : Measure Ω₁) (μ₂ : Measure Ω₂) : ℝ :=
d[X₁ ; μ₁ # X₂ ; μ₂] + p.η * d[p.X₀₁ ; ℙ # X₁ ; μ₁] + p.η * d[p.X₀₂ ; ℙ # X₂ ; μ₂]
@[inherit_doc tau]
notation3:max "τ[" X₁ " ; " μ₁ " # " X₂ " ; " μ₂ " | " p"]" => tau p X₁ X₂ μ₁ μ₂
@[inherit_doc tau]
notation3:max "τ[" X₁ " # " X₂ " | " p"]" => tau p X₁ X₂ MeasureTheory.MeasureSpace.volume MeasureTheory.MeasureSpace.volume
lemma continuous_tau_restrict_probabilityMeasure
[TopologicalSpace G] [DiscreteTopology G] [BorelSpace G] :
Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ τ[id ; μ.1 # id ; μ.2 | p]) := by
have obs₁ : Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ d[p.X₀₂ ; ℙ # id ; μ.2]) :=
Continuous.comp (continuous_rdist_restrict_probabilityMeasure₁' _ _ p.hmeas2) continuous_snd
have obs₂ : Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ d[id ; μ.1.toMeasure # id ; μ.2]) :=
continuous_rdist_restrict_probabilityMeasure
have obs₃ : Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ d[p.X₀₁ ; ℙ # id ; μ.1]) :=
Continuous.comp (continuous_rdist_restrict_probabilityMeasure₁' _ _ p.hmeas1) continuous_fst
continuity
/-- If $X'_1, X'_2$ are copies of $X_1,X_2$, then $\tau[X'_1;X'_2] = \tau[X_1;X_2]$. -/
lemma ProbabilityTheory.IdentDistrib.tau_eq [MeasurableSpace Ω₁] [MeasurableSpace Ω₂]
[MeasurableSpace Ω'₁] [MeasurableSpace Ω'₂]
{μ₁ : Measure Ω₁} {μ₂ : Measure Ω₂} {μ'₁ : Measure Ω'₁} {μ'₂ : Measure Ω'₂}
{X₁ : Ω₁ → G} {X₂ : Ω₂ → G} {X'₁ : Ω'₁ → G} {X'₂ : Ω'₂ → G}
(h₁ : IdentDistrib X₁ X'₁ μ₁ μ'₁) (h₂ : IdentDistrib X₂ X'₂ μ₂ μ'₂) :
τ[X₁ ; μ₁ # X₂ ; μ₂ | p] = τ[X'₁ ; μ'₁ # X'₂ ; μ'₂ | p] := by
simp only [tau]
rw [(IdentDistrib.refl p.hmeas1.aemeasurable).rdist_eq h₁,
(IdentDistrib.refl p.hmeas2.aemeasurable).rdist_eq h₂,
h₁.rdist_eq h₂]
/-- Property recording the fact that two random variables minimize the tau functional. Expressed
in terms of measures on the group to avoid quantifying over all spaces, but this implies comparison
with any pair of random variables, see Lemma `is_tau_min`. -/
def tau_minimizes {Ω : Type*} [MeasureSpace Ω] (X₁ : Ω → G) (X₂ : Ω → G) : Prop :=
∀ (ν₁ : Measure G) (ν₂ : Measure G), IsProbabilityMeasure ν₁ → IsProbabilityMeasure ν₂ →
τ[X₁ # X₂ | p] ≤ τ[id ; ν₁ # id ; ν₂ | p]
/-- If $X'_1, X'_2$ are copies of $X_1,X_2$, then $X_1, X_2$ minimize $\tau$ iff $X_1', X_2'$ do. -/
lemma ProbabilityTheory.IdentDistrib.tau_minimizes [MeasureSpace Ω]
[MeasureSpace Ω']
{X₁ X₂ : Ω → G} {X₁' X₂' : Ω' → G}
(h₁ : IdentDistrib X₁ X₁') (h₂ : IdentDistrib X₂ X₂') :
tau_minimizes p X₁ X₂ ↔ tau_minimizes p X₁' X₂' := by
simp_rw [_root_.tau_minimizes, h₁.tau_eq p h₂]
/-- A pair of measures minimizing $\tau$ exists. -/
lemma tau_min_exists_measure [MeasurableSingletonClass G] :
∃ (μ : Measure G × Measure G),
IsProbabilityMeasure μ.1 ∧ IsProbabilityMeasure μ.2 ∧
∀ (ν₁ : Measure G) (ν₂ : Measure G), IsProbabilityMeasure ν₁ → IsProbabilityMeasure ν₂ →
τ[id ; μ.1 # id ; μ.2 | p] ≤ τ[id ; ν₁ # id ; ν₂ | p] := by
let _i : TopologicalSpace G := (⊥ : TopologicalSpace G) -- Equip G with the discrete topology.
have : DiscreteTopology G := ⟨rfl⟩
have GG_cpt : CompactSpace (ProbabilityMeasure G × ProbabilityMeasure G) := inferInstance
let T : ProbabilityMeasure G × ProbabilityMeasure G → ℝ := -- restrict τ to the compact subspace
fun ⟨μ₁, μ₂⟩ ↦ τ[id ; μ₁ # id ; μ₂ | p]
have T_cont : Continuous T := by apply continuous_tau_restrict_probabilityMeasure
haveI : Inhabited G := ⟨0⟩ -- Need to record this for Lean to know that proba measures exist.
obtain ⟨μ, _, hμ⟩ := @IsCompact.exists_isMinOn ℝ (ProbabilityMeasure G × ProbabilityMeasure G)
_ _ _ _ Set.univ isCompact_univ ⟨default, trivial⟩ T T_cont.continuousOn
use ⟨μ.1.toMeasure, μ.2.toMeasure⟩
refine ⟨μ.1.prop, μ.2.prop, ?_⟩
intro ν₁ ν₂ Pν₁ Pν₂
rw [isMinOn_univ_iff] at hμ
let ν : ProbabilityMeasure G × ProbabilityMeasure G := ⟨⟨ν₁, Pν₁⟩, ν₂, Pν₂⟩
exact hμ ν
/-- A pair of random variables minimizing $τ$ exists. -/
lemma tau_minimizer_exists [MeasurableSingletonClass G] :
∃ (Ω : Type uG) (mΩ : MeasureSpace Ω) (X₁ : Ω → G) (X₂ : Ω → G),
Measurable X₁ ∧ Measurable X₂ ∧ IsProbabilityMeasure (ℙ : Measure Ω) ∧
tau_minimizes p X₁ X₂ := by
let μ := (tau_min_exists_measure p).choose
have : IsProbabilityMeasure μ.1 := (tau_min_exists_measure p).choose_spec.1
have : IsProbabilityMeasure μ.2 := (tau_min_exists_measure p).choose_spec.2.1
have P : IsProbabilityMeasure (μ.1.prod μ.2) := by infer_instance
let M : MeasureSpace (G × G) := ⟨μ.1.prod μ.2⟩
refine ⟨G × G, M, Prod.fst, Prod.snd, measurable_fst, measurable_snd, P, ?_⟩
intro ν₁ ν₂ h₁ h₂
have A : τ[@Prod.fst G G # @Prod.snd G G | p] = τ[id ; μ.1 # id ; μ.2 | p] :=
ProbabilityTheory.IdentDistrib.tau_eq p IdentDistrib.fst_id IdentDistrib.snd_id
convert (tau_min_exists_measure p).choose_spec.2.2 ν₁ ν₂ h₁ h₂
variable [MeasureSpace Ω] [hΩ₁ : MeasureSpace Ω'₁] [hΩ₂ : MeasureSpace Ω'₂]
[IsProbabilityMeasure (ℙ : Measure Ω)]
[IsProbabilityMeasure (ℙ : Measure Ω'₁)] [IsProbabilityMeasure (ℙ : Measure Ω'₂)]
{X₁ : Ω → G} {X₂ : Ω → G} {X'₁ : Ω'₁ → G} {X'₂ : Ω'₂ → G}
| lemma is_tau_min (h : tau_minimizes p X₁ X₂) (h1 : Measurable X'₁) (h2 : Measurable X'₂) :
τ[X₁ # X₂ | p] ≤ τ[X'₁ # X'₂ | p] | is_tau_min | 623ad58 20231116 | 828bcd7 20231120 | pfr/PFR/TauFunctional.lean | {
"lineInFile": 158,
"tokenPositionInFile": 7617,
"theoremPositionInFile": 10
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n let ν₁ := (ℙ : Measure Ω'₁).map X'₁\n let ν₂ := (ℙ : Measure Ω'₂).map X'₂\n have B : τ[X'₁ # X'₂ | p] = τ[id ; ν₁ # id ; ν₂ | p] :=\n (identDistrib_id_right h1.aemeasurable).tau_eq p (identDistrib_id_right h2.aemeasurable)\n convert h ν₁ ν₂ (isProbabilityMeasure_map h1.aemeasurable)\n (isProbabilityMeasure_map h2.aemeasurable)",
"proofType": "tactic",
"proofLengthLines": 7,
"proofLengthTokens": 337
} | pfr |
import PFR.ForMathlib.CompactProb
import PFR.ForMathlib.Entropy.RuzsaDist
/-!
# The tau functional
Definition of the tau functional and basic facts
## Main definitions:
* `η`: $1/9$
* `τ`: The tau functional $\tau[X_1; X_2] = d[X_1; X_2] + \eta d[X^0_1; X_1] + \eta d[X^0_2; X_2].$
## Main results
* `tau_minimizer_exists`: A pair of random variables minimizing $\tau$ exists.
* `condRuzsaDistance_ge_of_min`: If $X_1,X_2$ is a tau-minimizer with $k = d[X_1;X_2]$, then $d[X'_1|Z, X'_2|W]$ is at least
$$k - \eta (d[X^0_1;X'_1|Z] - d[X^0_1;X_1] ) - \eta (d[X^0_2;X'_2|W] - d[X^0_2;X_2] )$$
for any $X'_1, Z, X'_2, W$.
-/
open MeasureTheory ProbabilityTheory
universe uG
variable (Ω₀₁ Ω₀₂ : Type*) [MeasureSpace Ω₀₁] [MeasureSpace Ω₀₂]
[IsProbabilityMeasure (ℙ : Measure Ω₀₁)] [IsProbabilityMeasure (ℙ : Measure Ω₀₂)]
variable (G : Type uG) [AddCommGroup G] [ElementaryAddCommGroup G 2] [Fintype G] [MeasurableSpace G]
/-- A structure that packages all the fixed information in the main argument. In this way, when
defining the τ functional, we will only only need to refer to the package once in the notation
instead of stating the reference spaces, the reference measures and the reference random
variables.
The η parameter has now been incorporated into the package, in preparation for being able to
manipulate the package. -/
structure refPackage :=
/-- The first variable in a package. -/
X₀₁ : Ω₀₁ → G
/-- The second variable in a package. -/
X₀₂ : Ω₀₂ → G
hmeas1 : Measurable X₀₁
hmeas2 : Measurable X₀₂
η : ℝ
hη : 0 < η
hη' : 8 * η ≤ 1
variable (p : refPackage Ω₀₁ Ω₀₂ G)
variable {Ω₀₁ Ω₀₂ G}
variable {Ω₁ Ω₂ Ω'₁ Ω'₂ : Type*}
/-- If $X_1,X_2$ are two $G$-valued random variables, then
$$ \tau[X_1; X_2] := d[X_1; X_2] + \eta d[X^0_1; X_1] + \eta d[X^0_2; X_2].$$
Here, $X^0_1$ and $X^0_2$ are two random variables fixed once and for all in most of the argument.
To lighten notation, We package `X^0_1` and `X^0_2` in a single object named `p`.
We denote it as `τ[X₁ ; μ₁ # X₂ ; μ₂ | p]` where `p` is a fixed package containing the information
of the reference random variables. When the measurable spaces have a canonical measure `ℙ`, we
can use `τ[X₁ # X₂ | p]`
-/
@[pp_dot] noncomputable def tau {Ω₁ Ω₂ : Type*} [MeasurableSpace Ω₁] [MeasurableSpace Ω₂]
(X₁ : Ω₁ → G) (X₂ : Ω₂ → G) (μ₁ : Measure Ω₁) (μ₂ : Measure Ω₂) : ℝ :=
d[X₁ ; μ₁ # X₂ ; μ₂] + p.η * d[p.X₀₁ ; ℙ # X₁ ; μ₁] + p.η * d[p.X₀₂ ; ℙ # X₂ ; μ₂]
@[inherit_doc tau]
notation3:max "τ[" X₁ " ; " μ₁ " # " X₂ " ; " μ₂ " | " p"]" => tau p X₁ X₂ μ₁ μ₂
@[inherit_doc tau]
notation3:max "τ[" X₁ " # " X₂ " | " p"]" => tau p X₁ X₂ MeasureTheory.MeasureSpace.volume MeasureTheory.MeasureSpace.volume
lemma continuous_tau_restrict_probabilityMeasure
[TopologicalSpace G] [DiscreteTopology G] [BorelSpace G] :
Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ τ[id ; μ.1 # id ; μ.2 | p]) := by
have obs₁ : Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ d[p.X₀₂ ; ℙ # id ; μ.2]) :=
Continuous.comp (continuous_rdist_restrict_probabilityMeasure₁' _ _ p.hmeas2) continuous_snd
have obs₂ : Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ d[id ; μ.1.toMeasure # id ; μ.2]) :=
continuous_rdist_restrict_probabilityMeasure
have obs₃ : Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ d[p.X₀₁ ; ℙ # id ; μ.1]) :=
Continuous.comp (continuous_rdist_restrict_probabilityMeasure₁' _ _ p.hmeas1) continuous_fst
continuity
/-- If $X'_1, X'_2$ are copies of $X_1,X_2$, then $\tau[X'_1;X'_2] = \tau[X_1;X_2]$. -/
lemma ProbabilityTheory.IdentDistrib.tau_eq [MeasurableSpace Ω₁] [MeasurableSpace Ω₂]
[MeasurableSpace Ω'₁] [MeasurableSpace Ω'₂]
{μ₁ : Measure Ω₁} {μ₂ : Measure Ω₂} {μ'₁ : Measure Ω'₁} {μ'₂ : Measure Ω'₂}
{X₁ : Ω₁ → G} {X₂ : Ω₂ → G} {X'₁ : Ω'₁ → G} {X'₂ : Ω'₂ → G}
(h₁ : IdentDistrib X₁ X'₁ μ₁ μ'₁) (h₂ : IdentDistrib X₂ X'₂ μ₂ μ'₂) :
τ[X₁ ; μ₁ # X₂ ; μ₂ | p] = τ[X'₁ ; μ'₁ # X'₂ ; μ'₂ | p] := by
simp only [tau]
rw [(IdentDistrib.refl p.hmeas1.aemeasurable).rdist_eq h₁,
(IdentDistrib.refl p.hmeas2.aemeasurable).rdist_eq h₂,
h₁.rdist_eq h₂]
/-- Property recording the fact that two random variables minimize the tau functional. Expressed
in terms of measures on the group to avoid quantifying over all spaces, but this implies comparison
with any pair of random variables, see Lemma `is_tau_min`. -/
def tau_minimizes {Ω : Type*} [MeasureSpace Ω] (X₁ : Ω → G) (X₂ : Ω → G) : Prop :=
∀ (ν₁ : Measure G) (ν₂ : Measure G), IsProbabilityMeasure ν₁ → IsProbabilityMeasure ν₂ →
τ[X₁ # X₂ | p] ≤ τ[id ; ν₁ # id ; ν₂ | p]
/-- If $X'_1, X'_2$ are copies of $X_1,X_2$, then $X_1, X_2$ minimize $\tau$ iff $X_1', X_2'$ do. -/
lemma ProbabilityTheory.IdentDistrib.tau_minimizes [MeasureSpace Ω]
[MeasureSpace Ω']
{X₁ X₂ : Ω → G} {X₁' X₂' : Ω' → G}
(h₁ : IdentDistrib X₁ X₁') (h₂ : IdentDistrib X₂ X₂') :
tau_minimizes p X₁ X₂ ↔ tau_minimizes p X₁' X₂' := by
simp_rw [_root_.tau_minimizes, h₁.tau_eq p h₂]
/-- A pair of measures minimizing $\tau$ exists. -/
lemma tau_min_exists_measure [MeasurableSingletonClass G] :
∃ (μ : Measure G × Measure G),
IsProbabilityMeasure μ.1 ∧ IsProbabilityMeasure μ.2 ∧
∀ (ν₁ : Measure G) (ν₂ : Measure G), IsProbabilityMeasure ν₁ → IsProbabilityMeasure ν₂ →
τ[id ; μ.1 # id ; μ.2 | p] ≤ τ[id ; ν₁ # id ; ν₂ | p] := by
let _i : TopologicalSpace G := (⊥ : TopologicalSpace G) -- Equip G with the discrete topology.
have : DiscreteTopology G := ⟨rfl⟩
have GG_cpt : CompactSpace (ProbabilityMeasure G × ProbabilityMeasure G) := inferInstance
let T : ProbabilityMeasure G × ProbabilityMeasure G → ℝ := -- restrict τ to the compact subspace
fun ⟨μ₁, μ₂⟩ ↦ τ[id ; μ₁ # id ; μ₂ | p]
have T_cont : Continuous T := by apply continuous_tau_restrict_probabilityMeasure
haveI : Inhabited G := ⟨0⟩ -- Need to record this for Lean to know that proba measures exist.
obtain ⟨μ, _, hμ⟩ := @IsCompact.exists_isMinOn ℝ (ProbabilityMeasure G × ProbabilityMeasure G)
_ _ _ _ Set.univ isCompact_univ ⟨default, trivial⟩ T T_cont.continuousOn
use ⟨μ.1.toMeasure, μ.2.toMeasure⟩
refine ⟨μ.1.prop, μ.2.prop, ?_⟩
intro ν₁ ν₂ Pν₁ Pν₂
rw [isMinOn_univ_iff] at hμ
let ν : ProbabilityMeasure G × ProbabilityMeasure G := ⟨⟨ν₁, Pν₁⟩, ν₂, Pν₂⟩
exact hμ ν
/-- A pair of random variables minimizing $τ$ exists. -/
lemma tau_minimizer_exists [MeasurableSingletonClass G] :
∃ (Ω : Type uG) (mΩ : MeasureSpace Ω) (X₁ : Ω → G) (X₂ : Ω → G),
Measurable X₁ ∧ Measurable X₂ ∧ IsProbabilityMeasure (ℙ : Measure Ω) ∧
tau_minimizes p X₁ X₂ := by
let μ := (tau_min_exists_measure p).choose
have : IsProbabilityMeasure μ.1 := (tau_min_exists_measure p).choose_spec.1
have : IsProbabilityMeasure μ.2 := (tau_min_exists_measure p).choose_spec.2.1
have P : IsProbabilityMeasure (μ.1.prod μ.2) := by infer_instance
let M : MeasureSpace (G × G) := ⟨μ.1.prod μ.2⟩
refine ⟨G × G, M, Prod.fst, Prod.snd, measurable_fst, measurable_snd, P, ?_⟩
intro ν₁ ν₂ h₁ h₂
have A : τ[@Prod.fst G G # @Prod.snd G G | p] = τ[id ; μ.1 # id ; μ.2 | p] :=
ProbabilityTheory.IdentDistrib.tau_eq p IdentDistrib.fst_id IdentDistrib.snd_id
convert (tau_min_exists_measure p).choose_spec.2.2 ν₁ ν₂ h₁ h₂
variable [MeasureSpace Ω] [hΩ₁ : MeasureSpace Ω'₁] [hΩ₂ : MeasureSpace Ω'₂]
[IsProbabilityMeasure (ℙ : Measure Ω)]
[IsProbabilityMeasure (ℙ : Measure Ω'₁)] [IsProbabilityMeasure (ℙ : Measure Ω'₂)]
{X₁ : Ω → G} {X₂ : Ω → G} {X'₁ : Ω'₁ → G} {X'₂ : Ω'₂ → G}
lemma is_tau_min (h : tau_minimizes p X₁ X₂) (h1 : Measurable X'₁) (h2 : Measurable X'₂) :
τ[X₁ # X₂ | p] ≤ τ[X'₁ # X'₂ | p] := by
let ν₁ := (ℙ : Measure Ω'₁).map X'₁
let ν₂ := (ℙ : Measure Ω'₂).map X'₂
have B : τ[X'₁ # X'₂ | p] = τ[id ; ν₁ # id ; ν₂ | p] :=
(identDistrib_id_right h1.aemeasurable).tau_eq p (identDistrib_id_right h2.aemeasurable)
convert h ν₁ ν₂ (isProbabilityMeasure_map h1.aemeasurable)
(isProbabilityMeasure_map h2.aemeasurable)
/-- Let `X₁` and `X₂` be tau-minimizers associated to `p`, with $d[X_1,X_2]=k$, then
$$ d[X'_1;X'_2] \geq
k - \eta (d[X^0_1;X'_1] - d[X^0_1;X_1] ) - \eta (d[X^0_2;X'_2] - d[X^0_2;X_2] )$$
for any $G$-valued random variables $X'_1,X'_2$.
-/
| lemma distance_ge_of_min (h : tau_minimizes p X₁ X₂) (h1 : Measurable X'₁) (h2 : Measurable X'₂) :
d[X₁ # X₂] - p.η * (d[p.X₀₁ # X'₁] - d[p.X₀₁ # X₁]) - p.η * (d[p.X₀₂ # X'₂] - d[p.X₀₂ # X₂])
≤ d[X'₁ # X'₂] | distance_ge_of_min | 623ad58 20231116 | 828bcd7 20231120 | pfr/PFR/TauFunctional.lean | {
"lineInFile": 172,
"tokenPositionInFile": 8332,
"theoremPositionInFile": 11
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n have Z := is_tau_min p h h1 h2\n simp [tau] at Z\n linarith",
"proofType": "tactic",
"proofLengthLines": 4,
"proofLengthTokens": 64
} | pfr |
import PFR.ForMathlib.CompactProb
import PFR.ForMathlib.Entropy.RuzsaDist
/-!
# The tau functional
Definition of the tau functional and basic facts
## Main definitions:
* `η`: $1/9$
* `τ`: The tau functional $\tau[X_1; X_2] = d[X_1; X_2] + \eta d[X^0_1; X_1] + \eta d[X^0_2; X_2].$
## Main results
* `tau_minimizer_exists`: A pair of random variables minimizing $\tau$ exists.
* `condRuzsaDistance_ge_of_min`: If $X_1,X_2$ is a tau-minimizer with $k = d[X_1;X_2]$, then $d[X'_1|Z, X'_2|W]$ is at least
$$k - \eta (d[X^0_1;X'_1|Z] - d[X^0_1;X_1] ) - \eta (d[X^0_2;X'_2|W] - d[X^0_2;X_2] )$$
for any $X'_1, Z, X'_2, W$.
-/
open MeasureTheory ProbabilityTheory
universe uG
variable (Ω₀₁ Ω₀₂ : Type*) [MeasureSpace Ω₀₁] [MeasureSpace Ω₀₂]
[IsProbabilityMeasure (ℙ : Measure Ω₀₁)] [IsProbabilityMeasure (ℙ : Measure Ω₀₂)]
variable (G : Type uG) [AddCommGroup G] [ElementaryAddCommGroup G 2] [Fintype G] [MeasurableSpace G]
/-- A structure that packages all the fixed information in the main argument. In this way, when
defining the τ functional, we will only only need to refer to the package once in the notation
instead of stating the reference spaces, the reference measures and the reference random
variables.
The η parameter has now been incorporated into the package, in preparation for being able to
manipulate the package. -/
structure refPackage :=
/-- The first variable in a package. -/
X₀₁ : Ω₀₁ → G
/-- The second variable in a package. -/
X₀₂ : Ω₀₂ → G
hmeas1 : Measurable X₀₁
hmeas2 : Measurable X₀₂
η : ℝ
hη : 0 < η
hη' : 8 * η ≤ 1
variable (p : refPackage Ω₀₁ Ω₀₂ G)
variable {Ω₀₁ Ω₀₂ G}
variable {Ω₁ Ω₂ Ω'₁ Ω'₂ : Type*}
/-- If $X_1,X_2$ are two $G$-valued random variables, then
$$ \tau[X_1; X_2] := d[X_1; X_2] + \eta d[X^0_1; X_1] + \eta d[X^0_2; X_2].$$
Here, $X^0_1$ and $X^0_2$ are two random variables fixed once and for all in most of the argument.
To lighten notation, We package `X^0_1` and `X^0_2` in a single object named `p`.
We denote it as `τ[X₁ ; μ₁ # X₂ ; μ₂ | p]` where `p` is a fixed package containing the information
of the reference random variables. When the measurable spaces have a canonical measure `ℙ`, we
can use `τ[X₁ # X₂ | p]`
-/
@[pp_dot] noncomputable def tau {Ω₁ Ω₂ : Type*} [MeasurableSpace Ω₁] [MeasurableSpace Ω₂]
(X₁ : Ω₁ → G) (X₂ : Ω₂ → G) (μ₁ : Measure Ω₁) (μ₂ : Measure Ω₂) : ℝ :=
d[X₁ ; μ₁ # X₂ ; μ₂] + p.η * d[p.X₀₁ ; ℙ # X₁ ; μ₁] + p.η * d[p.X₀₂ ; ℙ # X₂ ; μ₂]
@[inherit_doc tau]
notation3:max "τ[" X₁ " ; " μ₁ " # " X₂ " ; " μ₂ " | " p"]" => tau p X₁ X₂ μ₁ μ₂
@[inherit_doc tau]
notation3:max "τ[" X₁ " # " X₂ " | " p"]" => tau p X₁ X₂ MeasureTheory.MeasureSpace.volume MeasureTheory.MeasureSpace.volume
lemma continuous_tau_restrict_probabilityMeasure
[TopologicalSpace G] [DiscreteTopology G] [BorelSpace G] :
Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ τ[id ; μ.1 # id ; μ.2 | p]) := by
have obs₁ : Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ d[p.X₀₂ ; ℙ # id ; μ.2]) :=
Continuous.comp (continuous_rdist_restrict_probabilityMeasure₁' _ _ p.hmeas2) continuous_snd
have obs₂ : Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ d[id ; μ.1.toMeasure # id ; μ.2]) :=
continuous_rdist_restrict_probabilityMeasure
have obs₃ : Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ d[p.X₀₁ ; ℙ # id ; μ.1]) :=
Continuous.comp (continuous_rdist_restrict_probabilityMeasure₁' _ _ p.hmeas1) continuous_fst
continuity
/-- If $X'_1, X'_2$ are copies of $X_1,X_2$, then $\tau[X'_1;X'_2] = \tau[X_1;X_2]$. -/
lemma ProbabilityTheory.IdentDistrib.tau_eq [MeasurableSpace Ω₁] [MeasurableSpace Ω₂]
[MeasurableSpace Ω'₁] [MeasurableSpace Ω'₂]
{μ₁ : Measure Ω₁} {μ₂ : Measure Ω₂} {μ'₁ : Measure Ω'₁} {μ'₂ : Measure Ω'₂}
{X₁ : Ω₁ → G} {X₂ : Ω₂ → G} {X'₁ : Ω'₁ → G} {X'₂ : Ω'₂ → G}
(h₁ : IdentDistrib X₁ X'₁ μ₁ μ'₁) (h₂ : IdentDistrib X₂ X'₂ μ₂ μ'₂) :
τ[X₁ ; μ₁ # X₂ ; μ₂ | p] = τ[X'₁ ; μ'₁ # X'₂ ; μ'₂ | p] := by
simp only [tau]
rw [(IdentDistrib.refl p.hmeas1.aemeasurable).rdist_eq h₁,
(IdentDistrib.refl p.hmeas2.aemeasurable).rdist_eq h₂,
h₁.rdist_eq h₂]
/-- Property recording the fact that two random variables minimize the tau functional. Expressed
in terms of measures on the group to avoid quantifying over all spaces, but this implies comparison
with any pair of random variables, see Lemma `is_tau_min`. -/
def tau_minimizes {Ω : Type*} [MeasureSpace Ω] (X₁ : Ω → G) (X₂ : Ω → G) : Prop :=
∀ (ν₁ : Measure G) (ν₂ : Measure G), IsProbabilityMeasure ν₁ → IsProbabilityMeasure ν₂ →
τ[X₁ # X₂ | p] ≤ τ[id ; ν₁ # id ; ν₂ | p]
/-- If $X'_1, X'_2$ are copies of $X_1,X_2$, then $X_1, X_2$ minimize $\tau$ iff $X_1', X_2'$ do. -/
lemma ProbabilityTheory.IdentDistrib.tau_minimizes [MeasureSpace Ω]
[MeasureSpace Ω']
{X₁ X₂ : Ω → G} {X₁' X₂' : Ω' → G}
(h₁ : IdentDistrib X₁ X₁') (h₂ : IdentDistrib X₂ X₂') :
tau_minimizes p X₁ X₂ ↔ tau_minimizes p X₁' X₂' := by
simp_rw [_root_.tau_minimizes, h₁.tau_eq p h₂]
/-- A pair of measures minimizing $\tau$ exists. -/
lemma tau_min_exists_measure [MeasurableSingletonClass G] :
∃ (μ : Measure G × Measure G),
IsProbabilityMeasure μ.1 ∧ IsProbabilityMeasure μ.2 ∧
∀ (ν₁ : Measure G) (ν₂ : Measure G), IsProbabilityMeasure ν₁ → IsProbabilityMeasure ν₂ →
τ[id ; μ.1 # id ; μ.2 | p] ≤ τ[id ; ν₁ # id ; ν₂ | p] := by
let _i : TopologicalSpace G := (⊥ : TopologicalSpace G) -- Equip G with the discrete topology.
have : DiscreteTopology G := ⟨rfl⟩
have GG_cpt : CompactSpace (ProbabilityMeasure G × ProbabilityMeasure G) := inferInstance
let T : ProbabilityMeasure G × ProbabilityMeasure G → ℝ := -- restrict τ to the compact subspace
fun ⟨μ₁, μ₂⟩ ↦ τ[id ; μ₁ # id ; μ₂ | p]
have T_cont : Continuous T := by apply continuous_tau_restrict_probabilityMeasure
haveI : Inhabited G := ⟨0⟩ -- Need to record this for Lean to know that proba measures exist.
obtain ⟨μ, _, hμ⟩ := @IsCompact.exists_isMinOn ℝ (ProbabilityMeasure G × ProbabilityMeasure G)
_ _ _ _ Set.univ isCompact_univ ⟨default, trivial⟩ T T_cont.continuousOn
use ⟨μ.1.toMeasure, μ.2.toMeasure⟩
refine ⟨μ.1.prop, μ.2.prop, ?_⟩
intro ν₁ ν₂ Pν₁ Pν₂
rw [isMinOn_univ_iff] at hμ
let ν : ProbabilityMeasure G × ProbabilityMeasure G := ⟨⟨ν₁, Pν₁⟩, ν₂, Pν₂⟩
exact hμ ν
/-- A pair of random variables minimizing $τ$ exists. -/
lemma tau_minimizer_exists [MeasurableSingletonClass G] :
∃ (Ω : Type uG) (mΩ : MeasureSpace Ω) (X₁ : Ω → G) (X₂ : Ω → G),
Measurable X₁ ∧ Measurable X₂ ∧ IsProbabilityMeasure (ℙ : Measure Ω) ∧
tau_minimizes p X₁ X₂ := by
let μ := (tau_min_exists_measure p).choose
have : IsProbabilityMeasure μ.1 := (tau_min_exists_measure p).choose_spec.1
have : IsProbabilityMeasure μ.2 := (tau_min_exists_measure p).choose_spec.2.1
have P : IsProbabilityMeasure (μ.1.prod μ.2) := by infer_instance
let M : MeasureSpace (G × G) := ⟨μ.1.prod μ.2⟩
refine ⟨G × G, M, Prod.fst, Prod.snd, measurable_fst, measurable_snd, P, ?_⟩
intro ν₁ ν₂ h₁ h₂
have A : τ[@Prod.fst G G # @Prod.snd G G | p] = τ[id ; μ.1 # id ; μ.2 | p] :=
ProbabilityTheory.IdentDistrib.tau_eq p IdentDistrib.fst_id IdentDistrib.snd_id
convert (tau_min_exists_measure p).choose_spec.2.2 ν₁ ν₂ h₁ h₂
variable [MeasureSpace Ω] [hΩ₁ : MeasureSpace Ω'₁] [hΩ₂ : MeasureSpace Ω'₂]
[IsProbabilityMeasure (ℙ : Measure Ω)]
[IsProbabilityMeasure (ℙ : Measure Ω'₁)] [IsProbabilityMeasure (ℙ : Measure Ω'₂)]
{X₁ : Ω → G} {X₂ : Ω → G} {X'₁ : Ω'₁ → G} {X'₂ : Ω'₂ → G}
lemma is_tau_min (h : tau_minimizes p X₁ X₂) (h1 : Measurable X'₁) (h2 : Measurable X'₂) :
τ[X₁ # X₂ | p] ≤ τ[X'₁ # X'₂ | p] := by
let ν₁ := (ℙ : Measure Ω'₁).map X'₁
let ν₂ := (ℙ : Measure Ω'₂).map X'₂
have B : τ[X'₁ # X'₂ | p] = τ[id ; ν₁ # id ; ν₂ | p] :=
(identDistrib_id_right h1.aemeasurable).tau_eq p (identDistrib_id_right h2.aemeasurable)
convert h ν₁ ν₂ (isProbabilityMeasure_map h1.aemeasurable)
(isProbabilityMeasure_map h2.aemeasurable)
/-- Let `X₁` and `X₂` be tau-minimizers associated to `p`, with $d[X_1,X_2]=k$, then
$$ d[X'_1;X'_2] \geq
k - \eta (d[X^0_1;X'_1] - d[X^0_1;X_1] ) - \eta (d[X^0_2;X'_2] - d[X^0_2;X_2] )$$
for any $G$-valued random variables $X'_1,X'_2$.
-/
lemma distance_ge_of_min (h : tau_minimizes p X₁ X₂) (h1 : Measurable X'₁) (h2 : Measurable X'₂) :
d[X₁ # X₂] - p.η * (d[p.X₀₁ # X'₁] - d[p.X₀₁ # X₁]) - p.η * (d[p.X₀₂ # X'₂] - d[p.X₀₂ # X₂])
≤ d[X'₁ # X'₂] := by
have Z := is_tau_min p h h1 h2
simp [tau] at Z
linarith
/-- Version of `distance_ge_of_min` with the measures made explicit. -/
| lemma distance_ge_of_min' {Ω'₁ Ω'₂ : Type*} (h : tau_minimizes p X₁ X₂)
[MeasurableSpace Ω'₁] [MeasurableSpace Ω'₂] {μ : Measure Ω'₁} {μ' : Measure Ω'₂}
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ'] {X'₁: Ω'₁ → G} {X'₂: Ω'₂ → G}
(h1 : Measurable X'₁) (h2 : Measurable X'₂) :
d[X₁ # X₂] - p.η * (d[p.X₀₁; ℙ # X'₁; μ] - d[p.X₀₁ # X₁])
- p.η * (d[p.X₀₂; ℙ # X'₂; μ'] - d[p.X₀₂ # X₂]) ≤ d[X'₁; μ # X'₂; μ'] | distance_ge_of_min' | 623ad58 20231116 | ba82447 20231128 | pfr/PFR/TauFunctional.lean | {
"lineInFile": 180,
"tokenPositionInFile": 8690,
"theoremPositionInFile": 12
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n set M1 : MeasureSpace Ω'₁ := { volume := μ }\n set M2 : MeasureSpace Ω'₂ := { volume := μ' }\n exact distance_ge_of_min p h h1 h2",
"proofType": "tactic",
"proofLengthLines": 4,
"proofLengthTokens": 134
} | pfr |
import PFR.ForMathlib.CompactProb
import PFR.ForMathlib.Entropy.RuzsaDist
/-!
# The tau functional
Definition of the tau functional and basic facts
## Main definitions:
* `η`: $1/9$
* `τ`: The tau functional $\tau[X_1; X_2] = d[X_1; X_2] + \eta d[X^0_1; X_1] + \eta d[X^0_2; X_2].$
## Main results
* `tau_minimizer_exists`: A pair of random variables minimizing $\tau$ exists.
* `condRuzsaDistance_ge_of_min`: If $X_1,X_2$ is a tau-minimizer with $k = d[X_1;X_2]$, then $d[X'_1|Z, X'_2|W]$ is at least
$$k - \eta (d[X^0_1;X'_1|Z] - d[X^0_1;X_1] ) - \eta (d[X^0_2;X'_2|W] - d[X^0_2;X_2] )$$
for any $X'_1, Z, X'_2, W$.
-/
open MeasureTheory ProbabilityTheory
universe uG
variable (Ω₀₁ Ω₀₂ : Type*) [MeasureSpace Ω₀₁] [MeasureSpace Ω₀₂]
[IsProbabilityMeasure (ℙ : Measure Ω₀₁)] [IsProbabilityMeasure (ℙ : Measure Ω₀₂)]
variable (G : Type uG) [AddCommGroup G] [ElementaryAddCommGroup G 2] [Fintype G] [MeasurableSpace G]
/-- A structure that packages all the fixed information in the main argument. In this way, when
defining the τ functional, we will only only need to refer to the package once in the notation
instead of stating the reference spaces, the reference measures and the reference random
variables.
The η parameter has now been incorporated into the package, in preparation for being able to
manipulate the package. -/
structure refPackage :=
/-- The first variable in a package. -/
X₀₁ : Ω₀₁ → G
/-- The second variable in a package. -/
X₀₂ : Ω₀₂ → G
hmeas1 : Measurable X₀₁
hmeas2 : Measurable X₀₂
η : ℝ
hη : 0 < η
hη' : 8 * η ≤ 1
variable (p : refPackage Ω₀₁ Ω₀₂ G)
variable {Ω₀₁ Ω₀₂ G}
variable {Ω₁ Ω₂ Ω'₁ Ω'₂ : Type*}
/-- If $X_1,X_2$ are two $G$-valued random variables, then
$$ \tau[X_1; X_2] := d[X_1; X_2] + \eta d[X^0_1; X_1] + \eta d[X^0_2; X_2].$$
Here, $X^0_1$ and $X^0_2$ are two random variables fixed once and for all in most of the argument.
To lighten notation, We package `X^0_1` and `X^0_2` in a single object named `p`.
We denote it as `τ[X₁ ; μ₁ # X₂ ; μ₂ | p]` where `p` is a fixed package containing the information
of the reference random variables. When the measurable spaces have a canonical measure `ℙ`, we
can use `τ[X₁ # X₂ | p]`
-/
@[pp_dot] noncomputable def tau {Ω₁ Ω₂ : Type*} [MeasurableSpace Ω₁] [MeasurableSpace Ω₂]
(X₁ : Ω₁ → G) (X₂ : Ω₂ → G) (μ₁ : Measure Ω₁) (μ₂ : Measure Ω₂) : ℝ :=
d[X₁ ; μ₁ # X₂ ; μ₂] + p.η * d[p.X₀₁ ; ℙ # X₁ ; μ₁] + p.η * d[p.X₀₂ ; ℙ # X₂ ; μ₂]
@[inherit_doc tau]
notation3:max "τ[" X₁ " ; " μ₁ " # " X₂ " ; " μ₂ " | " p"]" => tau p X₁ X₂ μ₁ μ₂
@[inherit_doc tau]
notation3:max "τ[" X₁ " # " X₂ " | " p"]" => tau p X₁ X₂ MeasureTheory.MeasureSpace.volume MeasureTheory.MeasureSpace.volume
lemma continuous_tau_restrict_probabilityMeasure
[TopologicalSpace G] [DiscreteTopology G] [BorelSpace G] :
Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ τ[id ; μ.1 # id ; μ.2 | p]) := by
have obs₁ : Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ d[p.X₀₂ ; ℙ # id ; μ.2]) :=
Continuous.comp (continuous_rdist_restrict_probabilityMeasure₁' _ _ p.hmeas2) continuous_snd
have obs₂ : Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ d[id ; μ.1.toMeasure # id ; μ.2]) :=
continuous_rdist_restrict_probabilityMeasure
have obs₃ : Continuous
(fun (μ : ProbabilityMeasure G × ProbabilityMeasure G) ↦ d[p.X₀₁ ; ℙ # id ; μ.1]) :=
Continuous.comp (continuous_rdist_restrict_probabilityMeasure₁' _ _ p.hmeas1) continuous_fst
continuity
/-- If $X'_1, X'_2$ are copies of $X_1,X_2$, then $\tau[X'_1;X'_2] = \tau[X_1;X_2]$. -/
lemma ProbabilityTheory.IdentDistrib.tau_eq [MeasurableSpace Ω₁] [MeasurableSpace Ω₂]
[MeasurableSpace Ω'₁] [MeasurableSpace Ω'₂]
{μ₁ : Measure Ω₁} {μ₂ : Measure Ω₂} {μ'₁ : Measure Ω'₁} {μ'₂ : Measure Ω'₂}
{X₁ : Ω₁ → G} {X₂ : Ω₂ → G} {X'₁ : Ω'₁ → G} {X'₂ : Ω'₂ → G}
(h₁ : IdentDistrib X₁ X'₁ μ₁ μ'₁) (h₂ : IdentDistrib X₂ X'₂ μ₂ μ'₂) :
τ[X₁ ; μ₁ # X₂ ; μ₂ | p] = τ[X'₁ ; μ'₁ # X'₂ ; μ'₂ | p] := by
simp only [tau]
rw [(IdentDistrib.refl p.hmeas1.aemeasurable).rdist_eq h₁,
(IdentDistrib.refl p.hmeas2.aemeasurable).rdist_eq h₂,
h₁.rdist_eq h₂]
/-- Property recording the fact that two random variables minimize the tau functional. Expressed
in terms of measures on the group to avoid quantifying over all spaces, but this implies comparison
with any pair of random variables, see Lemma `is_tau_min`. -/
def tau_minimizes {Ω : Type*} [MeasureSpace Ω] (X₁ : Ω → G) (X₂ : Ω → G) : Prop :=
∀ (ν₁ : Measure G) (ν₂ : Measure G), IsProbabilityMeasure ν₁ → IsProbabilityMeasure ν₂ →
τ[X₁ # X₂ | p] ≤ τ[id ; ν₁ # id ; ν₂ | p]
/-- If $X'_1, X'_2$ are copies of $X_1,X_2$, then $X_1, X_2$ minimize $\tau$ iff $X_1', X_2'$ do. -/
lemma ProbabilityTheory.IdentDistrib.tau_minimizes [MeasureSpace Ω]
[MeasureSpace Ω']
{X₁ X₂ : Ω → G} {X₁' X₂' : Ω' → G}
(h₁ : IdentDistrib X₁ X₁') (h₂ : IdentDistrib X₂ X₂') :
tau_minimizes p X₁ X₂ ↔ tau_minimizes p X₁' X₂' := by
simp_rw [_root_.tau_minimizes, h₁.tau_eq p h₂]
/-- A pair of measures minimizing $\tau$ exists. -/
lemma tau_min_exists_measure [MeasurableSingletonClass G] :
∃ (μ : Measure G × Measure G),
IsProbabilityMeasure μ.1 ∧ IsProbabilityMeasure μ.2 ∧
∀ (ν₁ : Measure G) (ν₂ : Measure G), IsProbabilityMeasure ν₁ → IsProbabilityMeasure ν₂ →
τ[id ; μ.1 # id ; μ.2 | p] ≤ τ[id ; ν₁ # id ; ν₂ | p] := by
let _i : TopologicalSpace G := (⊥ : TopologicalSpace G) -- Equip G with the discrete topology.
have : DiscreteTopology G := ⟨rfl⟩
have GG_cpt : CompactSpace (ProbabilityMeasure G × ProbabilityMeasure G) := inferInstance
let T : ProbabilityMeasure G × ProbabilityMeasure G → ℝ := -- restrict τ to the compact subspace
fun ⟨μ₁, μ₂⟩ ↦ τ[id ; μ₁ # id ; μ₂ | p]
have T_cont : Continuous T := by apply continuous_tau_restrict_probabilityMeasure
haveI : Inhabited G := ⟨0⟩ -- Need to record this for Lean to know that proba measures exist.
obtain ⟨μ, _, hμ⟩ := @IsCompact.exists_isMinOn ℝ (ProbabilityMeasure G × ProbabilityMeasure G)
_ _ _ _ Set.univ isCompact_univ ⟨default, trivial⟩ T T_cont.continuousOn
use ⟨μ.1.toMeasure, μ.2.toMeasure⟩
refine ⟨μ.1.prop, μ.2.prop, ?_⟩
intro ν₁ ν₂ Pν₁ Pν₂
rw [isMinOn_univ_iff] at hμ
let ν : ProbabilityMeasure G × ProbabilityMeasure G := ⟨⟨ν₁, Pν₁⟩, ν₂, Pν₂⟩
exact hμ ν
/-- A pair of random variables minimizing $τ$ exists. -/
lemma tau_minimizer_exists [MeasurableSingletonClass G] :
∃ (Ω : Type uG) (mΩ : MeasureSpace Ω) (X₁ : Ω → G) (X₂ : Ω → G),
Measurable X₁ ∧ Measurable X₂ ∧ IsProbabilityMeasure (ℙ : Measure Ω) ∧
tau_minimizes p X₁ X₂ := by
let μ := (tau_min_exists_measure p).choose
have : IsProbabilityMeasure μ.1 := (tau_min_exists_measure p).choose_spec.1
have : IsProbabilityMeasure μ.2 := (tau_min_exists_measure p).choose_spec.2.1
have P : IsProbabilityMeasure (μ.1.prod μ.2) := by infer_instance
let M : MeasureSpace (G × G) := ⟨μ.1.prod μ.2⟩
refine ⟨G × G, M, Prod.fst, Prod.snd, measurable_fst, measurable_snd, P, ?_⟩
intro ν₁ ν₂ h₁ h₂
have A : τ[@Prod.fst G G # @Prod.snd G G | p] = τ[id ; μ.1 # id ; μ.2 | p] :=
ProbabilityTheory.IdentDistrib.tau_eq p IdentDistrib.fst_id IdentDistrib.snd_id
convert (tau_min_exists_measure p).choose_spec.2.2 ν₁ ν₂ h₁ h₂
variable [MeasureSpace Ω] [hΩ₁ : MeasureSpace Ω'₁] [hΩ₂ : MeasureSpace Ω'₂]
[IsProbabilityMeasure (ℙ : Measure Ω)]
[IsProbabilityMeasure (ℙ : Measure Ω'₁)] [IsProbabilityMeasure (ℙ : Measure Ω'₂)]
{X₁ : Ω → G} {X₂ : Ω → G} {X'₁ : Ω'₁ → G} {X'₂ : Ω'₂ → G}
lemma is_tau_min (h : tau_minimizes p X₁ X₂) (h1 : Measurable X'₁) (h2 : Measurable X'₂) :
τ[X₁ # X₂ | p] ≤ τ[X'₁ # X'₂ | p] := by
let ν₁ := (ℙ : Measure Ω'₁).map X'₁
let ν₂ := (ℙ : Measure Ω'₂).map X'₂
have B : τ[X'₁ # X'₂ | p] = τ[id ; ν₁ # id ; ν₂ | p] :=
(identDistrib_id_right h1.aemeasurable).tau_eq p (identDistrib_id_right h2.aemeasurable)
convert h ν₁ ν₂ (isProbabilityMeasure_map h1.aemeasurable)
(isProbabilityMeasure_map h2.aemeasurable)
/-- Let `X₁` and `X₂` be tau-minimizers associated to `p`, with $d[X_1,X_2]=k$, then
$$ d[X'_1;X'_2] \geq
k - \eta (d[X^0_1;X'_1] - d[X^0_1;X_1] ) - \eta (d[X^0_2;X'_2] - d[X^0_2;X_2] )$$
for any $G$-valued random variables $X'_1,X'_2$.
-/
lemma distance_ge_of_min (h : tau_minimizes p X₁ X₂) (h1 : Measurable X'₁) (h2 : Measurable X'₂) :
d[X₁ # X₂] - p.η * (d[p.X₀₁ # X'₁] - d[p.X₀₁ # X₁]) - p.η * (d[p.X₀₂ # X'₂] - d[p.X₀₂ # X₂])
≤ d[X'₁ # X'₂] := by
have Z := is_tau_min p h h1 h2
simp [tau] at Z
linarith
/-- Version of `distance_ge_of_min` with the measures made explicit. -/
lemma distance_ge_of_min' {Ω'₁ Ω'₂ : Type*} (h : tau_minimizes p X₁ X₂)
[MeasurableSpace Ω'₁] [MeasurableSpace Ω'₂] {μ : Measure Ω'₁} {μ' : Measure Ω'₂}
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ'] {X'₁: Ω'₁ → G} {X'₂: Ω'₂ → G}
(h1 : Measurable X'₁) (h2 : Measurable X'₂) :
d[X₁ # X₂] - p.η * (d[p.X₀₁; ℙ # X'₁; μ] - d[p.X₀₁ # X₁])
- p.η * (d[p.X₀₂; ℙ # X'₂; μ'] - d[p.X₀₂ # X₂]) ≤ d[X'₁; μ # X'₂; μ'] := by
set M1 : MeasureSpace Ω'₁ := { volume := μ }
set M2 : MeasureSpace Ω'₂ := { volume := μ' }
exact distance_ge_of_min p h h1 h2
open BigOperators
/-- For any $G$-valued random variables $X'_1,X'_2$ and random variables $Z,W$, one can lower
bound $d[X'_1|Z;X'_2|W]$ by
$$k - \eta (d[X^0_1;X'_1|Z] - d[X^0_1;X_1] ) - \eta (d[X^0_2;X'_2|W] - d[X^0_2;X_2] ).$$
-/
| lemma condRuzsaDistance_ge_of_min [MeasurableSingletonClass G]
[Fintype S] [MeasurableSpace S] [MeasurableSingletonClass S]
[Fintype T] [MeasurableSpace T] [MeasurableSingletonClass T]
(h : tau_minimizes p X₁ X₂) (h1 : Measurable X'₁) (h2 : Measurable X'₂)
(Z : Ω'₁ → S) (W : Ω'₂ → T) (hZ : Measurable Z) (hW : Measurable W) :
d[X₁ # X₂] - p.η * (d[p.X₀₁ # X'₁ | Z] - d[p.X₀₁ # X₁])
- p.η * (d[p.X₀₂ # X'₂ | W] - d[p.X₀₂ # X₂]) ≤ d[X'₁ | Z # X'₂ | W] | condRuzsaDistance_ge_of_min | 623ad58 20231116 | 9087ab7 20231122 | pfr/PFR/TauFunctional.lean | {
"lineInFile": 197,
"tokenPositionInFile": 9493,
"theoremPositionInFile": 13
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n have hz (a : ℝ) : a = ∑ z in FiniteRange.toFinset Z, (ℙ (Z ⁻¹' {z})).toReal * a := by\n simp_rw [← Finset.sum_mul,← Measure.map_apply hZ (MeasurableSet.singleton _), Finset.sum_toReal_measure_singleton]\n rw [FiniteRange.full hZ]\n simp\n have hw (a : ℝ) : a = ∑ w in FiniteRange.toFinset W, (ℙ (W ⁻¹' {w})).toReal * a := by\n simp_rw [← Finset.sum_mul,← Measure.map_apply hW (MeasurableSet.singleton _), Finset.sum_toReal_measure_singleton]\n rw [FiniteRange.full hW]\n simp\n rw [condRuzsaDist_eq_sum h1 hZ h2 hW, condRuzsaDist'_eq_sum h1 hZ, hz d[X₁ # X₂],\n hz d[p.X₀₁ # X₁], hz (p.η * (d[p.X₀₂ # X'₂ | W] - d[p.X₀₂ # X₂])),\n ← Finset.sum_sub_distrib, Finset.mul_sum, ← Finset.sum_sub_distrib, ← Finset.sum_sub_distrib]\n apply Finset.sum_le_sum\n intro z _\n rw [condRuzsaDist'_eq_sum h2 hW, hw d[p.X₀₂ # X₂],\n hw ((ℙ (Z ⁻¹' {z})).toReal * d[X₁ # X₂] - p.η * ((ℙ (Z ⁻¹' {z})).toReal *\n d[p.X₀₁ ; ℙ # X'₁ ; ℙ[|Z ← z]] - (ℙ (Z ⁻¹' {z})).toReal * d[p.X₀₁ # X₁])),\n ← Finset.sum_sub_distrib, Finset.mul_sum, Finset.mul_sum, ← Finset.sum_sub_distrib]\n apply Finset.sum_le_sum\n intro w _\n rcases eq_or_ne (ℙ (Z ⁻¹' {z})) 0 with hpz | hpz\n . simp [hpz]\n rcases eq_or_ne (ℙ (W ⁻¹' {w})) 0 with hpw | hpw\n . simp [hpw]\n set μ := (hΩ₁.volume)[|Z ← z]\n have hμ : IsProbabilityMeasure μ := cond_isProbabilityMeasure ℙ hpz\n set μ' := ℙ[|W ← w]\n have hμ' : IsProbabilityMeasure μ' := cond_isProbabilityMeasure ℙ hpw\n suffices d[X₁ # X₂] - p.η * (d[p.X₀₁; volume # X'₁; μ] - d[p.X₀₁ # X₁]) -\n p.η * (d[p.X₀₂; volume # X'₂; μ'] - d[p.X₀₂ # X₂]) ≤ d[X'₁ ; μ # X'₂; μ'] by\n replace this := mul_le_mul_of_nonneg_left this (show 0 ≤ (ℙ (Z ⁻¹' {z})).toReal * (ℙ (W ⁻¹' {w})).toReal by positivity)\n convert this using 1\n ring\n exact distance_ge_of_min' p h h1 h2",
"proofType": "tactic",
"proofLengthLines": 34,
"proofLengthTokens": 1802
} | pfr |
import Mathlib.Combinatorics.Additive.RuzsaCovering
import Mathlib.GroupTheory.Complement
import Mathlib.GroupTheory.OrderOfElement
import PFR.Mathlib.GroupTheory.Subgroup.Pointwise
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Tactic.RPowSimp
import PFR.TauFunctional
import PFR.EntropyPFR
/- In this file the power notation will always mean the base and exponent are real numbers. -/
local macro_rules | `($x ^ $y) => `(HPow.hPow ($x : ℝ) ($y : ℝ))
/-!
# Polynomial Freiman-Ruzsa conjecture
Here we prove the polynomial Freiman-Ruzsa conjecture.
-/
open ProbabilityTheory MeasureTheory Real Set Fintype Function
open scoped BigOperators Pointwise
universe u
namespace ProbabilityTheory
variable {G Ω : Type*} [AddCommGroup G] [Fintype G]
[MeasurableSpace G] [MeasurableSingletonClass G] {A B : Finset G}
[MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)] {U V : Ω → G}
/-- Given two independent random variables `U` and `V` uniformly distributed respectively on `A`
and `B`, then `U = V` with probability `# (A ∩ B) / #A ⬝ #B`. -/
| lemma IsUniform.measureReal_preimage_sub_zero (Uunif : IsUniform A U) (Umeas : Measurable U)
(Vunif : IsUniform B V) (Vmeas : Measurable V) (hindep : IndepFun U V) :
(ℙ : Measure Ω).real ((U - V) ⁻¹' {0})
= Nat.card (A ∩ B : Set G) / (Nat.card A * Nat.card B) | IsUniform.measureReal_preimage_sub_zero | 516205a 20231114 | b94162e 20231128 | pfr/PFR/Main.lean | {
"lineInFile": 31,
"tokenPositionInFile": 1061,
"theoremPositionInFile": 1
} | {
"inFilePremises": false,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n have : (U - V) ⁻¹' {0} = ⋃ (g : G), (U ⁻¹' {g} ∩ V⁻¹' {g}) := by\n ext ω; simp [sub_eq_zero, eq_comm]\n rw [this, measureReal_iUnion_fintype _\n (fun i ↦ (Umeas $ measurableSet_discrete _).inter $ Vmeas $ measurableSet_discrete _)]; swap\n · intro g g' hgg'\n apply Set.disjoint_iff_inter_eq_empty.2\n ext a\n simp (config := {contextual := True}) [hgg']\n classical\n let W : Finset G := A ∩ B\n calc\n ∑ p, (ℙ : Measure Ω).real (U ⁻¹' {p} ∩ V ⁻¹' {p})\n = ∑ p, (ℙ : Measure Ω).real (U ⁻¹' {p}) * (ℙ : Measure Ω).real (V ⁻¹' {p}) := by\n apply sum_congr _ _ (fun g ↦ ?_)\n rw [hindep.measureReal_inter_preimage_eq_mul (measurableSet_discrete _) $\n measurableSet_discrete _]\n _ = ∑ p in W, (ℙ : Measure Ω).real (U ⁻¹' {p}) * (ℙ : Measure Ω).real (V ⁻¹' {p}) := by\n apply (Finset.sum_subset W.subset_univ _).symm\n intro i _ hi\n replace hi : i ∉ A ∨ i ∉ B := by simp [W] at hi; tauto\n rcases hi with h'i|h'i\n · simp [Uunif.measureReal_preimage_of_nmem h'i]\n · simp [Vunif.measureReal_preimage_of_nmem h'i]\n _ = ∑ p in W, (1 / Nat.card A : ℝ) * (1 / Nat.card B) := by\n apply Finset.sum_congr rfl (fun i hi ↦ ?_)\n replace hi : i ∈ A ∧ i ∈ B := by simpa [W] using hi\n rw [Uunif.measureReal_preimage_of_mem (by trivial) hi.1,\n Vunif.measureReal_preimage_of_mem (by trivial) hi.2]\n _ = (W.card : ℝ) / (Nat.card A * Nat.card B) := by simp [div_eq_inv_mul]; ring\n _ = Nat.card (A ∩ B : Set G) / (Nat.card A * Nat.card B) := by\n congr\n rw [← Finset.coe_inter, Nat.card_eq_fintype_card, Fintype.card_ofFinset]\n simp",
"proofType": "tactic",
"proofLengthLines": 34,
"proofLengthTokens": 1653
} | pfr |
import Mathlib.Combinatorics.Additive.RuzsaCovering
import Mathlib.GroupTheory.Complement
import Mathlib.GroupTheory.OrderOfElement
import PFR.Mathlib.GroupTheory.Subgroup.Pointwise
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Tactic.RPowSimp
import PFR.TauFunctional
import PFR.EntropyPFR
/- In this file the power notation will always mean the base and exponent are real numbers. -/
local macro_rules | `($x ^ $y) => `(HPow.hPow ($x : ℝ) ($y : ℝ))
/-!
# Polynomial Freiman-Ruzsa conjecture
Here we prove the polynomial Freiman-Ruzsa conjecture.
-/
open ProbabilityTheory MeasureTheory Real Set Fintype Function
open scoped BigOperators Pointwise
universe u
namespace ProbabilityTheory
variable {G Ω : Type*} [AddCommGroup G] [Fintype G]
[MeasurableSpace G] [MeasurableSingletonClass G] {A B : Finset G}
[MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)] {U V : Ω → G}
/-- Given two independent random variables `U` and `V` uniformly distributed respectively on `A`
and `B`, then `U = V` with probability `# (A ∩ B) / #A ⬝ #B`. -/
lemma IsUniform.measureReal_preimage_sub_zero (Uunif : IsUniform A U) (Umeas : Measurable U)
(Vunif : IsUniform B V) (Vmeas : Measurable V) (hindep : IndepFun U V) :
(ℙ : Measure Ω).real ((U - V) ⁻¹' {0})
= Nat.card (A ∩ B : Set G) / (Nat.card A * Nat.card B) := by
have : (U - V) ⁻¹' {0} = ⋃ (g : G), (U ⁻¹' {g} ∩ V⁻¹' {g}) := by
ext ω; simp [sub_eq_zero, eq_comm]
rw [this, measureReal_iUnion_fintype _
(fun i ↦ (Umeas $ measurableSet_discrete _).inter $ Vmeas $ measurableSet_discrete _)]; swap
· intro g g' hgg'
apply Set.disjoint_iff_inter_eq_empty.2
ext a
simp (config := {contextual := True}) [hgg']
classical
let W : Finset G := A ∩ B
calc
∑ p, (ℙ : Measure Ω).real (U ⁻¹' {p} ∩ V ⁻¹' {p})
= ∑ p, (ℙ : Measure Ω).real (U ⁻¹' {p}) * (ℙ : Measure Ω).real (V ⁻¹' {p}) := by
apply sum_congr _ _ (fun g ↦ ?_)
rw [hindep.measureReal_inter_preimage_eq_mul (measurableSet_discrete _) $
measurableSet_discrete _]
_ = ∑ p in W, (ℙ : Measure Ω).real (U ⁻¹' {p}) * (ℙ : Measure Ω).real (V ⁻¹' {p}) := by
apply (Finset.sum_subset W.subset_univ _).symm
intro i _ hi
replace hi : i ∉ A ∨ i ∉ B := by simp [W] at hi; tauto
rcases hi with h'i|h'i
· simp [Uunif.measureReal_preimage_of_nmem h'i]
· simp [Vunif.measureReal_preimage_of_nmem h'i]
_ = ∑ p in W, (1 / Nat.card A : ℝ) * (1 / Nat.card B) := by
apply Finset.sum_congr rfl (fun i hi ↦ ?_)
replace hi : i ∈ A ∧ i ∈ B := by simpa [W] using hi
rw [Uunif.measureReal_preimage_of_mem (by trivial) hi.1,
Vunif.measureReal_preimage_of_mem (by trivial) hi.2]
_ = (W.card : ℝ) / (Nat.card A * Nat.card B) := by simp [div_eq_inv_mul]; ring
_ = Nat.card (A ∩ B : Set G) / (Nat.card A * Nat.card B) := by
congr
rw [← Finset.coe_inter, Nat.card_eq_fintype_card, Fintype.card_ofFinset]
simp
/-- Given two independent random variables `U` and `V` uniformly distributed respectively on `A`
and `B`, then `U = V + x` with probability `# (A ∩ (B + x)) / #A ⬝ #B`. -/
| lemma IsUniform.measureReal_preimage_sub (Uunif : IsUniform A U) (Umeas : Measurable U)
(Vunif : IsUniform B V) (Vmeas : Measurable V) (hindep : IndepFun U V) (x : G) :
(ℙ : Measure Ω).real ((U - V) ⁻¹' {x})
= Nat.card (A ∩ (B + {x}) : Set G) / (Nat.card A * Nat.card B) | IsUniform.measureReal_preimage_sub | 516205a 20231114 | b94162e 20231128 | pfr/PFR/Main.lean | {
"lineInFile": 71,
"tokenPositionInFile": 3165,
"theoremPositionInFile": 2
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n classical\n let W := fun ω ↦ V ω + x\n have Wunif : IsUniform (B + {x} : Set G) W := by\n convert Vunif.comp (add_left_injective x)\n simp\n have Wmeas : Measurable W := Vmeas.add_const _\n have UWindep : IndepFun U W := by\n have : Measurable (fun g ↦ g + x) := measurable_add_const x\n exact hindep.comp measurable_id this\n have : (U - V) ⁻¹' {x} = (U - W) ⁻¹' {0} := by\n ext ω\n simp only [W, mem_preimage, Pi.add_apply, mem_singleton_iff, Pi.sub_apply, ← sub_eq_zero (b := x)]\n abel_nf\n have h : (B:Set G)+{x} = (B+{x}:Finset G) := by simp\n rw [h] at Wunif\n rw [this, Uunif.measureReal_preimage_sub_zero Umeas Wunif Wmeas UWindep]\n congr 3\n . rw [add_singleton]; simp\n convert Finset.card_vadd_finset (AddOpposite.op x) B\n . simp\n simp",
"proofType": "tactic",
"proofLengthLines": 22,
"proofLengthTokens": 769
} | pfr |
import Mathlib.Combinatorics.Additive.RuzsaCovering
import Mathlib.GroupTheory.Complement
import Mathlib.GroupTheory.OrderOfElement
import PFR.Mathlib.GroupTheory.Subgroup.Pointwise
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Tactic.RPowSimp
import PFR.TauFunctional
import PFR.EntropyPFR
/- In this file the power notation will always mean the base and exponent are real numbers. -/
local macro_rules | `($x ^ $y) => `(HPow.hPow ($x : ℝ) ($y : ℝ))
/-!
# Polynomial Freiman-Ruzsa conjecture
Here we prove the polynomial Freiman-Ruzsa conjecture.
-/
open ProbabilityTheory MeasureTheory Real Set Fintype Function
open scoped BigOperators Pointwise
universe u
namespace ProbabilityTheory
variable {G Ω : Type*} [AddCommGroup G] [Fintype G]
[MeasurableSpace G] [MeasurableSingletonClass G] {A B : Finset G}
[MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)] {U V : Ω → G}
/-- Given two independent random variables `U` and `V` uniformly distributed respectively on `A`
and `B`, then `U = V` with probability `# (A ∩ B) / #A ⬝ #B`. -/
lemma IsUniform.measureReal_preimage_sub_zero (Uunif : IsUniform A U) (Umeas : Measurable U)
(Vunif : IsUniform B V) (Vmeas : Measurable V) (hindep : IndepFun U V) :
(ℙ : Measure Ω).real ((U - V) ⁻¹' {0})
= Nat.card (A ∩ B : Set G) / (Nat.card A * Nat.card B) := by
have : (U - V) ⁻¹' {0} = ⋃ (g : G), (U ⁻¹' {g} ∩ V⁻¹' {g}) := by
ext ω; simp [sub_eq_zero, eq_comm]
rw [this, measureReal_iUnion_fintype _
(fun i ↦ (Umeas $ measurableSet_discrete _).inter $ Vmeas $ measurableSet_discrete _)]; swap
· intro g g' hgg'
apply Set.disjoint_iff_inter_eq_empty.2
ext a
simp (config := {contextual := True}) [hgg']
classical
let W : Finset G := A ∩ B
calc
∑ p, (ℙ : Measure Ω).real (U ⁻¹' {p} ∩ V ⁻¹' {p})
= ∑ p, (ℙ : Measure Ω).real (U ⁻¹' {p}) * (ℙ : Measure Ω).real (V ⁻¹' {p}) := by
apply sum_congr _ _ (fun g ↦ ?_)
rw [hindep.measureReal_inter_preimage_eq_mul (measurableSet_discrete _) $
measurableSet_discrete _]
_ = ∑ p in W, (ℙ : Measure Ω).real (U ⁻¹' {p}) * (ℙ : Measure Ω).real (V ⁻¹' {p}) := by
apply (Finset.sum_subset W.subset_univ _).symm
intro i _ hi
replace hi : i ∉ A ∨ i ∉ B := by simp [W] at hi; tauto
rcases hi with h'i|h'i
· simp [Uunif.measureReal_preimage_of_nmem h'i]
· simp [Vunif.measureReal_preimage_of_nmem h'i]
_ = ∑ p in W, (1 / Nat.card A : ℝ) * (1 / Nat.card B) := by
apply Finset.sum_congr rfl (fun i hi ↦ ?_)
replace hi : i ∈ A ∧ i ∈ B := by simpa [W] using hi
rw [Uunif.measureReal_preimage_of_mem (by trivial) hi.1,
Vunif.measureReal_preimage_of_mem (by trivial) hi.2]
_ = (W.card : ℝ) / (Nat.card A * Nat.card B) := by simp [div_eq_inv_mul]; ring
_ = Nat.card (A ∩ B : Set G) / (Nat.card A * Nat.card B) := by
congr
rw [← Finset.coe_inter, Nat.card_eq_fintype_card, Fintype.card_ofFinset]
simp
/-- Given two independent random variables `U` and `V` uniformly distributed respectively on `A`
and `B`, then `U = V + x` with probability `# (A ∩ (B + x)) / #A ⬝ #B`. -/
lemma IsUniform.measureReal_preimage_sub (Uunif : IsUniform A U) (Umeas : Measurable U)
(Vunif : IsUniform B V) (Vmeas : Measurable V) (hindep : IndepFun U V) (x : G) :
(ℙ : Measure Ω).real ((U - V) ⁻¹' {x})
= Nat.card (A ∩ (B + {x}) : Set G) / (Nat.card A * Nat.card B) := by
classical
let W := fun ω ↦ V ω + x
have Wunif : IsUniform (B + {x} : Set G) W := by
convert Vunif.comp (add_left_injective x)
simp
have Wmeas : Measurable W := Vmeas.add_const _
have UWindep : IndepFun U W := by
have : Measurable (fun g ↦ g + x) := measurable_add_const x
exact hindep.comp measurable_id this
have : (U - V) ⁻¹' {x} = (U - W) ⁻¹' {0} := by
ext ω
simp only [W, mem_preimage, Pi.add_apply, mem_singleton_iff, Pi.sub_apply, ← sub_eq_zero (b := x)]
abel_nf
have h : (B:Set G)+{x} = (B+{x}:Finset G) := by simp
rw [h] at Wunif
rw [this, Uunif.measureReal_preimage_sub_zero Umeas Wunif Wmeas UWindep]
congr 3
. rw [add_singleton]; simp
convert Finset.card_vadd_finset (AddOpposite.op x) B
. simp
simp
end ProbabilityTheory
/-- Record positivity results that are useful in the proof of PFR. -/
| lemma PFR_conjecture_pos_aux {G : Type*} [AddCommGroup G] {A : Set G} [Finite A] {K : ℝ} (h₀A : A.Nonempty) (hA : Nat.card (A - A) ≤ K * Nat.card A) :
(0 : ℝ) < Nat.card A ∧ (0 : ℝ) < Nat.card (A - A) ∧ 0 < K | PFR_conjecture_pos_aux | 516205a 20231114 | a028962 20231126 | pfr/PFR/Main.lean | {
"lineInFile": 101,
"tokenPositionInFile": 4318,
"theoremPositionInFile": 3
} | {
"inFilePremises": false,
"repositoryPremises": false
} | {
"hasProof": true,
"proof": "by\n have card_AA_pos : (0 : ℝ) < Nat.card (A - A) := by\n have : Nonempty (A - A) := Set.nonempty_coe_sort.mpr (Set.Nonempty.sub h₀A h₀A)\n have : Finite (A - A) := finite_coe_iff.mpr (Finite.image2 _ (Set.toFinite A) (Set.toFinite A))\n simp [Nat.cast_pos, Nat.card_pos_iff]\n have KA_pos : 0 < K ∧ (0 : ℝ) < Nat.card A := by\n have I : ¬ ((Nat.card A : ℝ) < 0) := by simp\n simpa [Nat.cast_pos, I, and_false, or_false] using mul_pos_iff.1 (card_AA_pos.trans_le hA)\n exact ⟨KA_pos.2, card_AA_pos, KA_pos.1⟩",
"proofType": "tactic",
"proofLengthLines": 9,
"proofLengthTokens": 519
} | pfr |
import Mathlib.Combinatorics.Additive.RuzsaCovering
import Mathlib.GroupTheory.Complement
import Mathlib.GroupTheory.OrderOfElement
import PFR.Mathlib.GroupTheory.Subgroup.Pointwise
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Tactic.RPowSimp
import PFR.TauFunctional
import PFR.EntropyPFR
/- In this file the power notation will always mean the base and exponent are real numbers. -/
local macro_rules | `($x ^ $y) => `(HPow.hPow ($x : ℝ) ($y : ℝ))
/-!
# Polynomial Freiman-Ruzsa conjecture
Here we prove the polynomial Freiman-Ruzsa conjecture.
-/
open ProbabilityTheory MeasureTheory Real Set Fintype Function
open scoped BigOperators Pointwise
universe u
namespace ProbabilityTheory
variable {G Ω : Type*} [AddCommGroup G] [Fintype G]
[MeasurableSpace G] [MeasurableSingletonClass G] {A B : Finset G}
[MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)] {U V : Ω → G}
/-- Given two independent random variables `U` and `V` uniformly distributed respectively on `A`
and `B`, then `U = V` with probability `# (A ∩ B) / #A ⬝ #B`. -/
lemma IsUniform.measureReal_preimage_sub_zero (Uunif : IsUniform A U) (Umeas : Measurable U)
(Vunif : IsUniform B V) (Vmeas : Measurable V) (hindep : IndepFun U V) :
(ℙ : Measure Ω).real ((U - V) ⁻¹' {0})
= Nat.card (A ∩ B : Set G) / (Nat.card A * Nat.card B) := by
have : (U - V) ⁻¹' {0} = ⋃ (g : G), (U ⁻¹' {g} ∩ V⁻¹' {g}) := by
ext ω; simp [sub_eq_zero, eq_comm]
rw [this, measureReal_iUnion_fintype _
(fun i ↦ (Umeas $ measurableSet_discrete _).inter $ Vmeas $ measurableSet_discrete _)]; swap
· intro g g' hgg'
apply Set.disjoint_iff_inter_eq_empty.2
ext a
simp (config := {contextual := True}) [hgg']
classical
let W : Finset G := A ∩ B
calc
∑ p, (ℙ : Measure Ω).real (U ⁻¹' {p} ∩ V ⁻¹' {p})
= ∑ p, (ℙ : Measure Ω).real (U ⁻¹' {p}) * (ℙ : Measure Ω).real (V ⁻¹' {p}) := by
apply sum_congr _ _ (fun g ↦ ?_)
rw [hindep.measureReal_inter_preimage_eq_mul (measurableSet_discrete _) $
measurableSet_discrete _]
_ = ∑ p in W, (ℙ : Measure Ω).real (U ⁻¹' {p}) * (ℙ : Measure Ω).real (V ⁻¹' {p}) := by
apply (Finset.sum_subset W.subset_univ _).symm
intro i _ hi
replace hi : i ∉ A ∨ i ∉ B := by simp [W] at hi; tauto
rcases hi with h'i|h'i
· simp [Uunif.measureReal_preimage_of_nmem h'i]
· simp [Vunif.measureReal_preimage_of_nmem h'i]
_ = ∑ p in W, (1 / Nat.card A : ℝ) * (1 / Nat.card B) := by
apply Finset.sum_congr rfl (fun i hi ↦ ?_)
replace hi : i ∈ A ∧ i ∈ B := by simpa [W] using hi
rw [Uunif.measureReal_preimage_of_mem (by trivial) hi.1,
Vunif.measureReal_preimage_of_mem (by trivial) hi.2]
_ = (W.card : ℝ) / (Nat.card A * Nat.card B) := by simp [div_eq_inv_mul]; ring
_ = Nat.card (A ∩ B : Set G) / (Nat.card A * Nat.card B) := by
congr
rw [← Finset.coe_inter, Nat.card_eq_fintype_card, Fintype.card_ofFinset]
simp
/-- Given two independent random variables `U` and `V` uniformly distributed respectively on `A`
and `B`, then `U = V + x` with probability `# (A ∩ (B + x)) / #A ⬝ #B`. -/
lemma IsUniform.measureReal_preimage_sub (Uunif : IsUniform A U) (Umeas : Measurable U)
(Vunif : IsUniform B V) (Vmeas : Measurable V) (hindep : IndepFun U V) (x : G) :
(ℙ : Measure Ω).real ((U - V) ⁻¹' {x})
= Nat.card (A ∩ (B + {x}) : Set G) / (Nat.card A * Nat.card B) := by
classical
let W := fun ω ↦ V ω + x
have Wunif : IsUniform (B + {x} : Set G) W := by
convert Vunif.comp (add_left_injective x)
simp
have Wmeas : Measurable W := Vmeas.add_const _
have UWindep : IndepFun U W := by
have : Measurable (fun g ↦ g + x) := measurable_add_const x
exact hindep.comp measurable_id this
have : (U - V) ⁻¹' {x} = (U - W) ⁻¹' {0} := by
ext ω
simp only [W, mem_preimage, Pi.add_apply, mem_singleton_iff, Pi.sub_apply, ← sub_eq_zero (b := x)]
abel_nf
have h : (B:Set G)+{x} = (B+{x}:Finset G) := by simp
rw [h] at Wunif
rw [this, Uunif.measureReal_preimage_sub_zero Umeas Wunif Wmeas UWindep]
congr 3
. rw [add_singleton]; simp
convert Finset.card_vadd_finset (AddOpposite.op x) B
. simp
simp
end ProbabilityTheory
/-- Record positivity results that are useful in the proof of PFR. -/
lemma PFR_conjecture_pos_aux {G : Type*} [AddCommGroup G] {A : Set G} [Finite A] {K : ℝ} (h₀A : A.Nonempty) (hA : Nat.card (A - A) ≤ K * Nat.card A) :
(0 : ℝ) < Nat.card A ∧ (0 : ℝ) < Nat.card (A - A) ∧ 0 < K := by
have card_AA_pos : (0 : ℝ) < Nat.card (A - A) := by
have : Nonempty (A - A) := Set.nonempty_coe_sort.mpr (Set.Nonempty.sub h₀A h₀A)
have : Finite (A - A) := finite_coe_iff.mpr (Finite.image2 _ (Set.toFinite A) (Set.toFinite A))
simp [Nat.cast_pos, Nat.card_pos_iff]
have KA_pos : 0 < K ∧ (0 : ℝ) < Nat.card A := by
have I : ¬ ((Nat.card A : ℝ) < 0) := by simp
simpa [Nat.cast_pos, I, and_false, or_false] using mul_pos_iff.1 (card_AA_pos.trans_le hA)
exact ⟨KA_pos.2, card_AA_pos, KA_pos.1⟩
| lemma PFR_conjecture_pos_aux' {G : Type*} [AddCommGroup G] {A : Set G} [Finite A] {K : ℝ} (h₀A : A.Nonempty) (hA : Nat.card (A + A) ≤ K * Nat.card A) :
(0 : ℝ) < Nat.card A ∧ (0 : ℝ) < Nat.card (A + A) ∧ 0 < K | PFR_conjecture_pos_aux' | 516205a 20231114 | 2ac9116 20231227 | pfr/PFR/Main.lean | {
"lineInFile": 112,
"tokenPositionInFile": 5055,
"theoremPositionInFile": 4
} | {
"inFilePremises": false,
"repositoryPremises": false
} | {
"hasProof": true,
"proof": "by\n have card_AA_pos : (0 : ℝ) < Nat.card (A + A) := by\n have : Nonempty (A + A) := Set.nonempty_coe_sort.mpr (Set.Nonempty.add h₀A h₀A)\n have : Finite (A + A) := finite_coe_iff.mpr (Finite.image2 _ (Set.toFinite A) (Set.toFinite A))\n simp [Nat.cast_pos, Nat.card_pos_iff]\n have KA_pos : 0 < K ∧ (0 : ℝ) < Nat.card A := by\n have I : ¬ ((Nat.card A : ℝ) < 0) := by simp\n simpa [Nat.cast_pos, I, and_false, or_false] using mul_pos_iff.1 (card_AA_pos.trans_le hA)\n exact ⟨KA_pos.2, card_AA_pos, KA_pos.1⟩",
"proofType": "tactic",
"proofLengthLines": 9,
"proofLengthTokens": 519
} | pfr |
import Mathlib.Combinatorics.Additive.RuzsaCovering
import Mathlib.GroupTheory.Complement
import Mathlib.GroupTheory.OrderOfElement
import PFR.Mathlib.GroupTheory.Subgroup.Pointwise
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Tactic.RPowSimp
import PFR.TauFunctional
import PFR.EntropyPFR
/- In this file the power notation will always mean the base and exponent are real numbers. -/
local macro_rules | `($x ^ $y) => `(HPow.hPow ($x : ℝ) ($y : ℝ))
/-!
# Polynomial Freiman-Ruzsa conjecture
Here we prove the polynomial Freiman-Ruzsa conjecture.
-/
open ProbabilityTheory MeasureTheory Real Set Fintype Function
open scoped BigOperators Pointwise
universe u
namespace ProbabilityTheory
variable {G Ω : Type*} [AddCommGroup G] [Fintype G]
[MeasurableSpace G] [MeasurableSingletonClass G] {A B : Finset G}
[MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)] {U V : Ω → G}
/-- Given two independent random variables `U` and `V` uniformly distributed respectively on `A`
and `B`, then `U = V` with probability `# (A ∩ B) / #A ⬝ #B`. -/
lemma IsUniform.measureReal_preimage_sub_zero (Uunif : IsUniform A U) (Umeas : Measurable U)
(Vunif : IsUniform B V) (Vmeas : Measurable V) (hindep : IndepFun U V) :
(ℙ : Measure Ω).real ((U - V) ⁻¹' {0})
= Nat.card (A ∩ B : Set G) / (Nat.card A * Nat.card B) := by
have : (U - V) ⁻¹' {0} = ⋃ (g : G), (U ⁻¹' {g} ∩ V⁻¹' {g}) := by
ext ω; simp [sub_eq_zero, eq_comm]
rw [this, measureReal_iUnion_fintype _
(fun i ↦ (Umeas $ measurableSet_discrete _).inter $ Vmeas $ measurableSet_discrete _)]; swap
· intro g g' hgg'
apply Set.disjoint_iff_inter_eq_empty.2
ext a
simp (config := {contextual := True}) [hgg']
classical
let W : Finset G := A ∩ B
calc
∑ p, (ℙ : Measure Ω).real (U ⁻¹' {p} ∩ V ⁻¹' {p})
= ∑ p, (ℙ : Measure Ω).real (U ⁻¹' {p}) * (ℙ : Measure Ω).real (V ⁻¹' {p}) := by
apply sum_congr _ _ (fun g ↦ ?_)
rw [hindep.measureReal_inter_preimage_eq_mul (measurableSet_discrete _) $
measurableSet_discrete _]
_ = ∑ p in W, (ℙ : Measure Ω).real (U ⁻¹' {p}) * (ℙ : Measure Ω).real (V ⁻¹' {p}) := by
apply (Finset.sum_subset W.subset_univ _).symm
intro i _ hi
replace hi : i ∉ A ∨ i ∉ B := by simp [W] at hi; tauto
rcases hi with h'i|h'i
· simp [Uunif.measureReal_preimage_of_nmem h'i]
· simp [Vunif.measureReal_preimage_of_nmem h'i]
_ = ∑ p in W, (1 / Nat.card A : ℝ) * (1 / Nat.card B) := by
apply Finset.sum_congr rfl (fun i hi ↦ ?_)
replace hi : i ∈ A ∧ i ∈ B := by simpa [W] using hi
rw [Uunif.measureReal_preimage_of_mem (by trivial) hi.1,
Vunif.measureReal_preimage_of_mem (by trivial) hi.2]
_ = (W.card : ℝ) / (Nat.card A * Nat.card B) := by simp [div_eq_inv_mul]; ring
_ = Nat.card (A ∩ B : Set G) / (Nat.card A * Nat.card B) := by
congr
rw [← Finset.coe_inter, Nat.card_eq_fintype_card, Fintype.card_ofFinset]
simp
/-- Given two independent random variables `U` and `V` uniformly distributed respectively on `A`
and `B`, then `U = V + x` with probability `# (A ∩ (B + x)) / #A ⬝ #B`. -/
lemma IsUniform.measureReal_preimage_sub (Uunif : IsUniform A U) (Umeas : Measurable U)
(Vunif : IsUniform B V) (Vmeas : Measurable V) (hindep : IndepFun U V) (x : G) :
(ℙ : Measure Ω).real ((U - V) ⁻¹' {x})
= Nat.card (A ∩ (B + {x}) : Set G) / (Nat.card A * Nat.card B) := by
classical
let W := fun ω ↦ V ω + x
have Wunif : IsUniform (B + {x} : Set G) W := by
convert Vunif.comp (add_left_injective x)
simp
have Wmeas : Measurable W := Vmeas.add_const _
have UWindep : IndepFun U W := by
have : Measurable (fun g ↦ g + x) := measurable_add_const x
exact hindep.comp measurable_id this
have : (U - V) ⁻¹' {x} = (U - W) ⁻¹' {0} := by
ext ω
simp only [W, mem_preimage, Pi.add_apply, mem_singleton_iff, Pi.sub_apply, ← sub_eq_zero (b := x)]
abel_nf
have h : (B:Set G)+{x} = (B+{x}:Finset G) := by simp
rw [h] at Wunif
rw [this, Uunif.measureReal_preimage_sub_zero Umeas Wunif Wmeas UWindep]
congr 3
. rw [add_singleton]; simp
convert Finset.card_vadd_finset (AddOpposite.op x) B
. simp
simp
end ProbabilityTheory
/-- Record positivity results that are useful in the proof of PFR. -/
lemma PFR_conjecture_pos_aux {G : Type*} [AddCommGroup G] {A : Set G} [Finite A] {K : ℝ} (h₀A : A.Nonempty) (hA : Nat.card (A - A) ≤ K * Nat.card A) :
(0 : ℝ) < Nat.card A ∧ (0 : ℝ) < Nat.card (A - A) ∧ 0 < K := by
have card_AA_pos : (0 : ℝ) < Nat.card (A - A) := by
have : Nonempty (A - A) := Set.nonempty_coe_sort.mpr (Set.Nonempty.sub h₀A h₀A)
have : Finite (A - A) := finite_coe_iff.mpr (Finite.image2 _ (Set.toFinite A) (Set.toFinite A))
simp [Nat.cast_pos, Nat.card_pos_iff]
have KA_pos : 0 < K ∧ (0 : ℝ) < Nat.card A := by
have I : ¬ ((Nat.card A : ℝ) < 0) := by simp
simpa [Nat.cast_pos, I, and_false, or_false] using mul_pos_iff.1 (card_AA_pos.trans_le hA)
exact ⟨KA_pos.2, card_AA_pos, KA_pos.1⟩
lemma PFR_conjecture_pos_aux' {G : Type*} [AddCommGroup G] {A : Set G} [Finite A] {K : ℝ} (h₀A : A.Nonempty) (hA : Nat.card (A + A) ≤ K * Nat.card A) :
(0 : ℝ) < Nat.card A ∧ (0 : ℝ) < Nat.card (A + A) ∧ 0 < K := by
have card_AA_pos : (0 : ℝ) < Nat.card (A + A) := by
have : Nonempty (A + A) := Set.nonempty_coe_sort.mpr (Set.Nonempty.add h₀A h₀A)
have : Finite (A + A) := finite_coe_iff.mpr (Finite.image2 _ (Set.toFinite A) (Set.toFinite A))
simp [Nat.cast_pos, Nat.card_pos_iff]
have KA_pos : 0 < K ∧ (0 : ℝ) < Nat.card A := by
have I : ¬ ((Nat.card A : ℝ) < 0) := by simp
simpa [Nat.cast_pos, I, and_false, or_false] using mul_pos_iff.1 (card_AA_pos.trans_le hA)
exact ⟨KA_pos.2, card_AA_pos, KA_pos.1⟩
variable {G : Type*} [AddCommGroup G] [MeasurableSpace G]
[MeasurableSingletonClass G] {A : Set G} [Finite A] {K : ℝ} [Countable G]
/-- A uniform distribution on a set with doubling constant `K` has self Rusza distance
at most `log K`. -/
| theorem rdist_le_of_isUniform_of_card_add_le (h₀A : A.Nonempty) (hA : Nat.card (A - A) ≤ K * Nat.card A)
{Ω : Type*} [MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)] {U₀ : Ω → G}
(U₀unif : IsUniform A U₀) (U₀meas : Measurable U₀) : d[U₀ # U₀] ≤ log K | rdist_le_of_isUniform_of_card_add_le | 516205a 20231114 | b94162e 20231128 | pfr/PFR/Main.lean | {
"lineInFile": 128,
"tokenPositionInFile": 6035,
"theoremPositionInFile": 5
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n obtain ⟨A_pos, AA_pos, K_pos⟩ : (0 : ℝ) < Nat.card A ∧ (0 : ℝ) < Nat.card (A - A) ∧ 0 < K :=\n PFR_conjecture_pos_aux h₀A hA\n rcases independent_copies_two U₀meas U₀meas with ⟨Ω, mΩ, U, U', hP, hU, hU', UU'_indep, idU, idU'⟩\n have Uunif : IsUniform A U := U₀unif.of_identDistrib idU.symm $ measurableSet_discrete _\n have U'unif : IsUniform A U' := U₀unif.of_identDistrib idU'.symm $ measurableSet_discrete _\n have IU : d[U # U'] ≤ log K := by\n have I : H[U - U'] ≤ log (Nat.card (A - A)) := by\n convert entropy_le_log_card_of_mem (A := (A-A).toFinite.toFinset) ?_ ?_ with x\n . simp\n exact Iff.rfl\n . measurability\n filter_upwards [Uunif.ae_mem, U'unif.ae_mem] with ω h1 h2\n simp\n exact Set.sub_mem_sub h1 h2\n have J : log (Nat.card (A - A)) ≤ log K + log (Nat.card A) := by\n apply (log_le_log AA_pos hA).trans (le_of_eq _)\n rw [log_mul K_pos.ne' A_pos.ne']\n-- have : H[U + U'] = H[U - U'] := by congr; simp\n rw [UU'_indep.rdist_eq hU hU', IsUniform.entropy_eq' Uunif hU, IsUniform.entropy_eq' U'unif hU']\n linarith\n rwa [idU.rdist_eq idU'] at IU",
"proofType": "tactic",
"proofLengthLines": 22,
"proofLengthTokens": 1119
} | pfr |
import Mathlib.Combinatorics.Additive.RuzsaCovering
import Mathlib.GroupTheory.Complement
import Mathlib.GroupTheory.OrderOfElement
import PFR.Mathlib.GroupTheory.Subgroup.Pointwise
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Tactic.RPowSimp
import PFR.TauFunctional
import PFR.EntropyPFR
/- In this file the power notation will always mean the base and exponent are real numbers. -/
local macro_rules | `($x ^ $y) => `(HPow.hPow ($x : ℝ) ($y : ℝ))
/-!
# Polynomial Freiman-Ruzsa conjecture
Here we prove the polynomial Freiman-Ruzsa conjecture.
-/
open ProbabilityTheory MeasureTheory Real Set Fintype Function
open scoped BigOperators Pointwise
universe u
namespace ProbabilityTheory
variable {G Ω : Type*} [AddCommGroup G] [Fintype G]
[MeasurableSpace G] [MeasurableSingletonClass G] {A B : Finset G}
[MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)] {U V : Ω → G}
/-- Given two independent random variables `U` and `V` uniformly distributed respectively on `A`
and `B`, then `U = V` with probability `# (A ∩ B) / #A ⬝ #B`. -/
lemma IsUniform.measureReal_preimage_sub_zero (Uunif : IsUniform A U) (Umeas : Measurable U)
(Vunif : IsUniform B V) (Vmeas : Measurable V) (hindep : IndepFun U V) :
(ℙ : Measure Ω).real ((U - V) ⁻¹' {0})
= Nat.card (A ∩ B : Set G) / (Nat.card A * Nat.card B) := by
have : (U - V) ⁻¹' {0} = ⋃ (g : G), (U ⁻¹' {g} ∩ V⁻¹' {g}) := by
ext ω; simp [sub_eq_zero, eq_comm]
rw [this, measureReal_iUnion_fintype _
(fun i ↦ (Umeas $ measurableSet_discrete _).inter $ Vmeas $ measurableSet_discrete _)]; swap
· intro g g' hgg'
apply Set.disjoint_iff_inter_eq_empty.2
ext a
simp (config := {contextual := True}) [hgg']
classical
let W : Finset G := A ∩ B
calc
∑ p, (ℙ : Measure Ω).real (U ⁻¹' {p} ∩ V ⁻¹' {p})
= ∑ p, (ℙ : Measure Ω).real (U ⁻¹' {p}) * (ℙ : Measure Ω).real (V ⁻¹' {p}) := by
apply sum_congr _ _ (fun g ↦ ?_)
rw [hindep.measureReal_inter_preimage_eq_mul (measurableSet_discrete _) $
measurableSet_discrete _]
_ = ∑ p in W, (ℙ : Measure Ω).real (U ⁻¹' {p}) * (ℙ : Measure Ω).real (V ⁻¹' {p}) := by
apply (Finset.sum_subset W.subset_univ _).symm
intro i _ hi
replace hi : i ∉ A ∨ i ∉ B := by simp [W] at hi; tauto
rcases hi with h'i|h'i
· simp [Uunif.measureReal_preimage_of_nmem h'i]
· simp [Vunif.measureReal_preimage_of_nmem h'i]
_ = ∑ p in W, (1 / Nat.card A : ℝ) * (1 / Nat.card B) := by
apply Finset.sum_congr rfl (fun i hi ↦ ?_)
replace hi : i ∈ A ∧ i ∈ B := by simpa [W] using hi
rw [Uunif.measureReal_preimage_of_mem (by trivial) hi.1,
Vunif.measureReal_preimage_of_mem (by trivial) hi.2]
_ = (W.card : ℝ) / (Nat.card A * Nat.card B) := by simp [div_eq_inv_mul]; ring
_ = Nat.card (A ∩ B : Set G) / (Nat.card A * Nat.card B) := by
congr
rw [← Finset.coe_inter, Nat.card_eq_fintype_card, Fintype.card_ofFinset]
simp
/-- Given two independent random variables `U` and `V` uniformly distributed respectively on `A`
and `B`, then `U = V + x` with probability `# (A ∩ (B + x)) / #A ⬝ #B`. -/
lemma IsUniform.measureReal_preimage_sub (Uunif : IsUniform A U) (Umeas : Measurable U)
(Vunif : IsUniform B V) (Vmeas : Measurable V) (hindep : IndepFun U V) (x : G) :
(ℙ : Measure Ω).real ((U - V) ⁻¹' {x})
= Nat.card (A ∩ (B + {x}) : Set G) / (Nat.card A * Nat.card B) := by
classical
let W := fun ω ↦ V ω + x
have Wunif : IsUniform (B + {x} : Set G) W := by
convert Vunif.comp (add_left_injective x)
simp
have Wmeas : Measurable W := Vmeas.add_const _
have UWindep : IndepFun U W := by
have : Measurable (fun g ↦ g + x) := measurable_add_const x
exact hindep.comp measurable_id this
have : (U - V) ⁻¹' {x} = (U - W) ⁻¹' {0} := by
ext ω
simp only [W, mem_preimage, Pi.add_apply, mem_singleton_iff, Pi.sub_apply, ← sub_eq_zero (b := x)]
abel_nf
have h : (B:Set G)+{x} = (B+{x}:Finset G) := by simp
rw [h] at Wunif
rw [this, Uunif.measureReal_preimage_sub_zero Umeas Wunif Wmeas UWindep]
congr 3
. rw [add_singleton]; simp
convert Finset.card_vadd_finset (AddOpposite.op x) B
. simp
simp
end ProbabilityTheory
/-- Record positivity results that are useful in the proof of PFR. -/
lemma PFR_conjecture_pos_aux {G : Type*} [AddCommGroup G] {A : Set G} [Finite A] {K : ℝ} (h₀A : A.Nonempty) (hA : Nat.card (A - A) ≤ K * Nat.card A) :
(0 : ℝ) < Nat.card A ∧ (0 : ℝ) < Nat.card (A - A) ∧ 0 < K := by
have card_AA_pos : (0 : ℝ) < Nat.card (A - A) := by
have : Nonempty (A - A) := Set.nonempty_coe_sort.mpr (Set.Nonempty.sub h₀A h₀A)
have : Finite (A - A) := finite_coe_iff.mpr (Finite.image2 _ (Set.toFinite A) (Set.toFinite A))
simp [Nat.cast_pos, Nat.card_pos_iff]
have KA_pos : 0 < K ∧ (0 : ℝ) < Nat.card A := by
have I : ¬ ((Nat.card A : ℝ) < 0) := by simp
simpa [Nat.cast_pos, I, and_false, or_false] using mul_pos_iff.1 (card_AA_pos.trans_le hA)
exact ⟨KA_pos.2, card_AA_pos, KA_pos.1⟩
lemma PFR_conjecture_pos_aux' {G : Type*} [AddCommGroup G] {A : Set G} [Finite A] {K : ℝ} (h₀A : A.Nonempty) (hA : Nat.card (A + A) ≤ K * Nat.card A) :
(0 : ℝ) < Nat.card A ∧ (0 : ℝ) < Nat.card (A + A) ∧ 0 < K := by
have card_AA_pos : (0 : ℝ) < Nat.card (A + A) := by
have : Nonempty (A + A) := Set.nonempty_coe_sort.mpr (Set.Nonempty.add h₀A h₀A)
have : Finite (A + A) := finite_coe_iff.mpr (Finite.image2 _ (Set.toFinite A) (Set.toFinite A))
simp [Nat.cast_pos, Nat.card_pos_iff]
have KA_pos : 0 < K ∧ (0 : ℝ) < Nat.card A := by
have I : ¬ ((Nat.card A : ℝ) < 0) := by simp
simpa [Nat.cast_pos, I, and_false, or_false] using mul_pos_iff.1 (card_AA_pos.trans_le hA)
exact ⟨KA_pos.2, card_AA_pos, KA_pos.1⟩
variable {G : Type*} [AddCommGroup G] [MeasurableSpace G]
[MeasurableSingletonClass G] {A : Set G} [Finite A] {K : ℝ} [Countable G]
/-- A uniform distribution on a set with doubling constant `K` has self Rusza distance
at most `log K`. -/
theorem rdist_le_of_isUniform_of_card_add_le (h₀A : A.Nonempty) (hA : Nat.card (A - A) ≤ K * Nat.card A)
{Ω : Type*} [MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)] {U₀ : Ω → G}
(U₀unif : IsUniform A U₀) (U₀meas : Measurable U₀) : d[U₀ # U₀] ≤ log K := by
obtain ⟨A_pos, AA_pos, K_pos⟩ : (0 : ℝ) < Nat.card A ∧ (0 : ℝ) < Nat.card (A - A) ∧ 0 < K :=
PFR_conjecture_pos_aux h₀A hA
rcases independent_copies_two U₀meas U₀meas with ⟨Ω, mΩ, U, U', hP, hU, hU', UU'_indep, idU, idU'⟩
have Uunif : IsUniform A U := U₀unif.of_identDistrib idU.symm $ measurableSet_discrete _
have U'unif : IsUniform A U' := U₀unif.of_identDistrib idU'.symm $ measurableSet_discrete _
have IU : d[U # U'] ≤ log K := by
have I : H[U - U'] ≤ log (Nat.card (A - A)) := by
convert entropy_le_log_card_of_mem (A := (A-A).toFinite.toFinset) ?_ ?_ with x
. simp
exact Iff.rfl
. measurability
filter_upwards [Uunif.ae_mem, U'unif.ae_mem] with ω h1 h2
simp
exact Set.sub_mem_sub h1 h2
have J : log (Nat.card (A - A)) ≤ log K + log (Nat.card A) := by
apply (log_le_log AA_pos hA).trans (le_of_eq _)
rw [log_mul K_pos.ne' A_pos.ne']
-- have : H[U + U'] = H[U - U'] := by congr; simp
rw [UU'_indep.rdist_eq hU hU', IsUniform.entropy_eq' Uunif hU, IsUniform.entropy_eq' U'unif hU']
linarith
rwa [idU.rdist_eq idU'] at IU
variable [ElementaryAddCommGroup G 2] [Fintype G]
| lemma sumset_eq_sub : A + A = A - A | sumset_eq_sub | 516205a 20231114 | 93e5ee0 20240113 | pfr/PFR/Main.lean | {
"lineInFile": 155,
"tokenPositionInFile": 7476,
"theoremPositionInFile": 6
} | {
"inFilePremises": false,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n rw [← Set.image2_add, ← Set.image2_sub]\n congr! 1 with a _ b _\n show a + b = a - b\n simp",
"proofType": "tactic",
"proofLengthLines": 5,
"proofLengthTokens": 96
} | pfr |
import Mathlib.Combinatorics.Additive.RuzsaCovering
import Mathlib.GroupTheory.Complement
import Mathlib.GroupTheory.OrderOfElement
import PFR.Mathlib.GroupTheory.Subgroup.Pointwise
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Tactic.RPowSimp
import PFR.TauFunctional
import PFR.EntropyPFR
/- In this file the power notation will always mean the base and exponent are real numbers. -/
local macro_rules | `($x ^ $y) => `(HPow.hPow ($x : ℝ) ($y : ℝ))
/-!
# Polynomial Freiman-Ruzsa conjecture
Here we prove the polynomial Freiman-Ruzsa conjecture.
-/
open ProbabilityTheory MeasureTheory Real Set Fintype Function
open scoped BigOperators Pointwise
universe u
namespace ProbabilityTheory
variable {G Ω : Type*} [AddCommGroup G] [Fintype G]
[MeasurableSpace G] [MeasurableSingletonClass G] {A B : Finset G}
[MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)] {U V : Ω → G}
/-- Given two independent random variables `U` and `V` uniformly distributed respectively on `A`
and `B`, then `U = V` with probability `# (A ∩ B) / #A ⬝ #B`. -/
lemma IsUniform.measureReal_preimage_sub_zero (Uunif : IsUniform A U) (Umeas : Measurable U)
(Vunif : IsUniform B V) (Vmeas : Measurable V) (hindep : IndepFun U V) :
(ℙ : Measure Ω).real ((U - V) ⁻¹' {0})
= Nat.card (A ∩ B : Set G) / (Nat.card A * Nat.card B) := by
have : (U - V) ⁻¹' {0} = ⋃ (g : G), (U ⁻¹' {g} ∩ V⁻¹' {g}) := by
ext ω; simp [sub_eq_zero, eq_comm]
rw [this, measureReal_iUnion_fintype _
(fun i ↦ (Umeas $ measurableSet_discrete _).inter $ Vmeas $ measurableSet_discrete _)]; swap
· intro g g' hgg'
apply Set.disjoint_iff_inter_eq_empty.2
ext a
simp (config := {contextual := True}) [hgg']
classical
let W : Finset G := A ∩ B
calc
∑ p, (ℙ : Measure Ω).real (U ⁻¹' {p} ∩ V ⁻¹' {p})
= ∑ p, (ℙ : Measure Ω).real (U ⁻¹' {p}) * (ℙ : Measure Ω).real (V ⁻¹' {p}) := by
apply sum_congr _ _ (fun g ↦ ?_)
rw [hindep.measureReal_inter_preimage_eq_mul (measurableSet_discrete _) $
measurableSet_discrete _]
_ = ∑ p in W, (ℙ : Measure Ω).real (U ⁻¹' {p}) * (ℙ : Measure Ω).real (V ⁻¹' {p}) := by
apply (Finset.sum_subset W.subset_univ _).symm
intro i _ hi
replace hi : i ∉ A ∨ i ∉ B := by simp [W] at hi; tauto
rcases hi with h'i|h'i
· simp [Uunif.measureReal_preimage_of_nmem h'i]
· simp [Vunif.measureReal_preimage_of_nmem h'i]
_ = ∑ p in W, (1 / Nat.card A : ℝ) * (1 / Nat.card B) := by
apply Finset.sum_congr rfl (fun i hi ↦ ?_)
replace hi : i ∈ A ∧ i ∈ B := by simpa [W] using hi
rw [Uunif.measureReal_preimage_of_mem (by trivial) hi.1,
Vunif.measureReal_preimage_of_mem (by trivial) hi.2]
_ = (W.card : ℝ) / (Nat.card A * Nat.card B) := by simp [div_eq_inv_mul]; ring
_ = Nat.card (A ∩ B : Set G) / (Nat.card A * Nat.card B) := by
congr
rw [← Finset.coe_inter, Nat.card_eq_fintype_card, Fintype.card_ofFinset]
simp
/-- Given two independent random variables `U` and `V` uniformly distributed respectively on `A`
and `B`, then `U = V + x` with probability `# (A ∩ (B + x)) / #A ⬝ #B`. -/
lemma IsUniform.measureReal_preimage_sub (Uunif : IsUniform A U) (Umeas : Measurable U)
(Vunif : IsUniform B V) (Vmeas : Measurable V) (hindep : IndepFun U V) (x : G) :
(ℙ : Measure Ω).real ((U - V) ⁻¹' {x})
= Nat.card (A ∩ (B + {x}) : Set G) / (Nat.card A * Nat.card B) := by
classical
let W := fun ω ↦ V ω + x
have Wunif : IsUniform (B + {x} : Set G) W := by
convert Vunif.comp (add_left_injective x)
simp
have Wmeas : Measurable W := Vmeas.add_const _
have UWindep : IndepFun U W := by
have : Measurable (fun g ↦ g + x) := measurable_add_const x
exact hindep.comp measurable_id this
have : (U - V) ⁻¹' {x} = (U - W) ⁻¹' {0} := by
ext ω
simp only [W, mem_preimage, Pi.add_apply, mem_singleton_iff, Pi.sub_apply, ← sub_eq_zero (b := x)]
abel_nf
have h : (B:Set G)+{x} = (B+{x}:Finset G) := by simp
rw [h] at Wunif
rw [this, Uunif.measureReal_preimage_sub_zero Umeas Wunif Wmeas UWindep]
congr 3
. rw [add_singleton]; simp
convert Finset.card_vadd_finset (AddOpposite.op x) B
. simp
simp
end ProbabilityTheory
/-- Record positivity results that are useful in the proof of PFR. -/
lemma PFR_conjecture_pos_aux {G : Type*} [AddCommGroup G] {A : Set G} [Finite A] {K : ℝ} (h₀A : A.Nonempty) (hA : Nat.card (A - A) ≤ K * Nat.card A) :
(0 : ℝ) < Nat.card A ∧ (0 : ℝ) < Nat.card (A - A) ∧ 0 < K := by
have card_AA_pos : (0 : ℝ) < Nat.card (A - A) := by
have : Nonempty (A - A) := Set.nonempty_coe_sort.mpr (Set.Nonempty.sub h₀A h₀A)
have : Finite (A - A) := finite_coe_iff.mpr (Finite.image2 _ (Set.toFinite A) (Set.toFinite A))
simp [Nat.cast_pos, Nat.card_pos_iff]
have KA_pos : 0 < K ∧ (0 : ℝ) < Nat.card A := by
have I : ¬ ((Nat.card A : ℝ) < 0) := by simp
simpa [Nat.cast_pos, I, and_false, or_false] using mul_pos_iff.1 (card_AA_pos.trans_le hA)
exact ⟨KA_pos.2, card_AA_pos, KA_pos.1⟩
lemma PFR_conjecture_pos_aux' {G : Type*} [AddCommGroup G] {A : Set G} [Finite A] {K : ℝ} (h₀A : A.Nonempty) (hA : Nat.card (A + A) ≤ K * Nat.card A) :
(0 : ℝ) < Nat.card A ∧ (0 : ℝ) < Nat.card (A + A) ∧ 0 < K := by
have card_AA_pos : (0 : ℝ) < Nat.card (A + A) := by
have : Nonempty (A + A) := Set.nonempty_coe_sort.mpr (Set.Nonempty.add h₀A h₀A)
have : Finite (A + A) := finite_coe_iff.mpr (Finite.image2 _ (Set.toFinite A) (Set.toFinite A))
simp [Nat.cast_pos, Nat.card_pos_iff]
have KA_pos : 0 < K ∧ (0 : ℝ) < Nat.card A := by
have I : ¬ ((Nat.card A : ℝ) < 0) := by simp
simpa [Nat.cast_pos, I, and_false, or_false] using mul_pos_iff.1 (card_AA_pos.trans_le hA)
exact ⟨KA_pos.2, card_AA_pos, KA_pos.1⟩
variable {G : Type*} [AddCommGroup G] [MeasurableSpace G]
[MeasurableSingletonClass G] {A : Set G} [Finite A] {K : ℝ} [Countable G]
/-- A uniform distribution on a set with doubling constant `K` has self Rusza distance
at most `log K`. -/
theorem rdist_le_of_isUniform_of_card_add_le (h₀A : A.Nonempty) (hA : Nat.card (A - A) ≤ K * Nat.card A)
{Ω : Type*} [MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)] {U₀ : Ω → G}
(U₀unif : IsUniform A U₀) (U₀meas : Measurable U₀) : d[U₀ # U₀] ≤ log K := by
obtain ⟨A_pos, AA_pos, K_pos⟩ : (0 : ℝ) < Nat.card A ∧ (0 : ℝ) < Nat.card (A - A) ∧ 0 < K :=
PFR_conjecture_pos_aux h₀A hA
rcases independent_copies_two U₀meas U₀meas with ⟨Ω, mΩ, U, U', hP, hU, hU', UU'_indep, idU, idU'⟩
have Uunif : IsUniform A U := U₀unif.of_identDistrib idU.symm $ measurableSet_discrete _
have U'unif : IsUniform A U' := U₀unif.of_identDistrib idU'.symm $ measurableSet_discrete _
have IU : d[U # U'] ≤ log K := by
have I : H[U - U'] ≤ log (Nat.card (A - A)) := by
convert entropy_le_log_card_of_mem (A := (A-A).toFinite.toFinset) ?_ ?_ with x
. simp
exact Iff.rfl
. measurability
filter_upwards [Uunif.ae_mem, U'unif.ae_mem] with ω h1 h2
simp
exact Set.sub_mem_sub h1 h2
have J : log (Nat.card (A - A)) ≤ log K + log (Nat.card A) := by
apply (log_le_log AA_pos hA).trans (le_of_eq _)
rw [log_mul K_pos.ne' A_pos.ne']
-- have : H[U + U'] = H[U - U'] := by congr; simp
rw [UU'_indep.rdist_eq hU hU', IsUniform.entropy_eq' Uunif hU, IsUniform.entropy_eq' U'unif hU']
linarith
rwa [idU.rdist_eq idU'] at IU
variable [ElementaryAddCommGroup G 2] [Fintype G]
lemma sumset_eq_sub : A + A = A - A := by
rw [← Set.image2_add, ← Set.image2_sub]
congr! 1 with a _ b _
show a + b = a - b
simp
/-- Auxiliary statement towards the polynomial Freiman-Ruzsa (PFR) conjecture: if $A$ is a subset of
an elementary abelian 2-group of doubling constant at most $K$, then there exists a subgroup $H$
such that $A$ can be covered by at most $K^{13/2} |A|^{1/2} / |H|^{1/2}$ cosets of $H$, and $H$ has
the same cardinality as $A$ up to a multiplicative factor $K^11$. -/
| lemma PFR_conjecture_aux (h₀A : A.Nonempty) (hA : Nat.card (A + A) ≤ K * Nat.card A) :
∃ (H : AddSubgroup G) (c : Set G),
Nat.card c ≤ K ^ (13/2) * (Nat.card A) ^ (1/2) * (Nat.card (H : Set G)) ^ (-1/2)
∧ Nat.card H ≤ K ^ 11 * Nat.card A ∧ Nat.card A ≤ K ^ 11 * Nat.card H ∧ A ⊆ c + H | PFR_conjecture_aux | 516205a 20231114 | b94162e 20231128 | pfr/PFR/Main.lean | {
"lineInFile": 165,
"tokenPositionInFile": 7980,
"theoremPositionInFile": 7
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n classical\n let _mG : MeasurableSpace G := ⊤\n rw [sumset_eq_sub] at hA\n have : MeasurableSingletonClass G := ⟨λ _ ↦ trivial⟩\n obtain ⟨A_pos, -, K_pos⟩ : (0 : ℝ) < Nat.card A ∧ (0 : ℝ) < Nat.card (A - A) ∧ 0 < K :=\n PFR_conjecture_pos_aux h₀A hA\n let A' := A.toFinite.toFinset\n have h₀A' : Finset.Nonempty A' := by\n simp [A', Finset.Nonempty]\n exact h₀A\n have hAA' : A' = A := Finite.coe_toFinset (toFinite A)\n rcases exists_isUniform_measureSpace A' h₀A' with ⟨Ω₀, mΩ₀, UA, hP₀, UAmeas, UAunif, -, -⟩\n rw [hAA'] at UAunif\n have : d[UA # UA] ≤ log K := rdist_le_of_isUniform_of_card_add_le h₀A hA UAunif UAmeas\n rw [← sumset_eq_sub] at hA\n let p : refPackage Ω₀ Ω₀ G := ⟨UA, UA, UAmeas, UAmeas, 1/9, (by norm_num), (by norm_num)⟩\n -- entropic PFR gives a subgroup `H` which is close to `A` for the Rusza distance\n rcases entropic_PFR_conjecture p (by norm_num) with ⟨H, Ω₁, mΩ₁, UH, hP₁, UHmeas, UHunif, hUH⟩\n rcases independent_copies_two UAmeas UHmeas\n with ⟨Ω, mΩ, VA, VH, hP, VAmeas, VHmeas, Vindep, idVA, idVH⟩\n have VAunif : IsUniform A VA := UAunif.of_identDistrib idVA.symm $ measurableSet_discrete _\n have VA'unif := VAunif\n rw [← hAA'] at VA'unif\n have VHunif : IsUniform H VH := UHunif.of_identDistrib idVH.symm $ measurableSet_discrete _\n let H' := (H:Set G).toFinite.toFinset\n have hHH' : H' = (H:Set G) := Finite.coe_toFinset (toFinite (H:Set G))\n have VH'unif := VHunif\n rw [← hHH'] at VH'unif\n\n have : d[VA # VH] ≤ 11/2 * log K := by rw [idVA.rdist_eq idVH]; linarith\n have H_pos : (0 : ℝ) < Nat.card (H : Set G) := by\n have : 0 < Nat.card (H : Set G) := Nat.card_pos\n positivity\n have VA_ent : H[VA] = log (Nat.card A) := IsUniform.entropy_eq' VAunif VAmeas\n have VH_ent : H[VH] = log (Nat.card (H : Set G)) := IsUniform.entropy_eq' VHunif VHmeas\n have Icard : |log (Nat.card A) - log (Nat.card (H : Set G))| ≤ 11 * log K := by\n rw [← VA_ent, ← VH_ent]\n apply (diff_ent_le_rdist VAmeas VHmeas).trans\n linarith\n have IAH : Nat.card A ≤ K ^ 11 * Nat.card (H : Set G) := by\n have : log (Nat.card A) ≤ log K * 11 + log (Nat.card (H : Set G)) := by\n linarith [(le_abs_self _).trans Icard]\n convert exp_monotone this using 1\n · exact (exp_log A_pos).symm\n · rw [exp_add, exp_log H_pos, ← rpow_def_of_pos K_pos]\n have IHA : Nat.card (H : Set G) ≤ K ^ 11 * Nat.card A := by\n have : log (Nat.card (H : Set G)) ≤ log K * 11 + log (Nat.card A) := by\n linarith [(neg_le_abs _).trans Icard]\n convert exp_monotone this using 1\n · exact (exp_log H_pos).symm\n · rw [exp_add, exp_log A_pos, ← rpow_def_of_pos K_pos]\n -- entropic PFR shows that the entropy of `VA - VH` is small\n have I : log K * (-11/2) + log (Nat.card A) * (-1/2) + log (Nat.card (H : Set G)) * (-1/2)\n ≤ - H[VA - VH] := by\n rw [Vindep.rdist_eq VAmeas VHmeas] at this\n have : H[VA] = log (Nat.card A) := IsUniform.entropy_eq' VAunif VAmeas\n have : H[VH] = log (Nat.card (H : Set G)) := IsUniform.entropy_eq' VHunif VHmeas\n linarith\n -- therefore, there exists a point `x₀` which is attained by `VA - VH` with a large probability\n obtain ⟨x₀, h₀⟩ : ∃ x₀ : G, rexp (- H[VA - VH]) ≤ (ℙ : Measure Ω).real ((VA - VH) ⁻¹' {x₀}) :=\n prob_ge_exp_neg_entropy' _ ((VAmeas.sub VHmeas).comp measurable_id')\n -- massage the previous inequality to get that `A ∩ (H + {x₀})` is large\n have J : K ^ (-11/2) * (Nat.card A) ^ (1/2) * (Nat.card (H : Set G)) ^ (1/2) ≤\n Nat.card (A ∩ (H + {x₀}) : Set G) := by\n rw [VA'unif.measureReal_preimage_sub VAmeas VH'unif VHmeas Vindep] at h₀\n have := (Real.exp_monotone I).trans h₀\n have hAA'_card : Nat.card A' = Nat.card A := congrArg Nat.card (congrArg Subtype hAA')\n have hHH'_card : Nat.card H' = Nat.card (H : Set G) := congrArg Nat.card (congrArg Subtype hHH')\n rw [hAA'_card, hHH'_card, le_div_iff] at this\n convert this using 1\n . rw [exp_add, exp_add, ← rpow_def_of_pos K_pos, ← rpow_def_of_pos A_pos, ← rpow_def_of_pos H_pos]\n rpow_ring\n norm_num\n . rw [hAA', hHH']\n positivity\n\n have Hne : Set.Nonempty (A ∩ (H + {x₀} : Set G)) := by\n by_contra h'\n have : (0 : ℝ) < Nat.card (A ∩ (H + {x₀}) : Set G) := lt_of_lt_of_le (by positivity) J\n simp only [Nat.card_eq_fintype_card, card_of_isEmpty, CharP.cast_eq_zero, lt_self_iff_false,\n not_nonempty_iff_eq_empty.1 h'] at this\n /- use Rusza covering lemma to cover `A` by few translates of `A ∩ (H + {x₀}) - A ∩ (H + {x₀})`\n (which is contained in `H`). The number of translates is at most\n `#(A + (A ∩ (H + {x₀}))) / #(A ∩ (H + {x₀}))`, where the numerator is controlled as this is\n a subset of `A + A`, and the denominator is bounded below by the previous inequality`. -/\n rcases Set.exists_subset_add_sub (toFinite A) (toFinite (A ∩ ((H + {x₀} : Set G)))) Hne with\n ⟨u, hu, Au, -⟩\n have Iu : Nat.card u ≤ K ^ (13/2) * (Nat.card A) ^ (1/2) * (Nat.card (H : Set G)) ^ (-1/2) := by\n have : (0 : ℝ) ≤ Nat.card u := by simp\n have Z1 := mul_le_mul_of_nonneg_left J this\n have Z2 : (Nat.card u * Nat.card (A ∩ (H + {x₀}) : Set G) : ℝ)\n ≤ Nat.card (A + A ∩ (↑H + {x₀})) := by norm_cast\n have Z3 : (Nat.card (A + A ∩ (↑H + {x₀})) : ℝ) ≤ K * Nat.card A := by\n apply le_trans _ hA\n simp only [Nat.cast_le]\n apply Nat.card_mono (toFinite _)\n apply add_subset_add_left (inter_subset_left _ _)\n have : 0 ≤ K ^ (11/2) * Nat.card A ^ (-1/2) * Nat.card (H : Set G) ^ (-1/2) := by positivity\n have T := mul_le_mul_of_nonneg_left ((Z1.trans Z2).trans Z3) this\n convert T using 1 <;> rpow_ring <;> norm_num\n have A_subset_uH : A ⊆ u + H := by\n rw [add_sub_assoc] at Au\n refine Au.trans $ add_subset_add_left $\n (sub_subset_sub (inter_subset_right ..) (inter_subset_right ..)).trans ?_\n rw [add_sub_add_comm, singleton_sub_singleton, sub_self]\n simp\n exact ⟨H, u, Iu, IHA, IAH, A_subset_uH⟩",
"proofType": "tactic",
"proofLengthLines": 108,
"proofLengthTokens": 5869
} | pfr |
import Mathlib.Combinatorics.Additive.RuzsaCovering
import Mathlib.GroupTheory.Complement
import Mathlib.GroupTheory.OrderOfElement
import PFR.Mathlib.GroupTheory.Subgroup.Pointwise
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Tactic.RPowSimp
import PFR.TauFunctional
import PFR.EntropyPFR
/- In this file the power notation will always mean the base and exponent are real numbers. -/
local macro_rules | `($x ^ $y) => `(HPow.hPow ($x : ℝ) ($y : ℝ))
/-!
# Polynomial Freiman-Ruzsa conjecture
Here we prove the polynomial Freiman-Ruzsa conjecture.
-/
open ProbabilityTheory MeasureTheory Real Set Fintype Function
open scoped BigOperators Pointwise
universe u
namespace ProbabilityTheory
variable {G Ω : Type*} [AddCommGroup G] [Fintype G]
[MeasurableSpace G] [MeasurableSingletonClass G] {A B : Finset G}
[MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)] {U V : Ω → G}
/-- Given two independent random variables `U` and `V` uniformly distributed respectively on `A`
and `B`, then `U = V` with probability `# (A ∩ B) / #A ⬝ #B`. -/
lemma IsUniform.measureReal_preimage_sub_zero (Uunif : IsUniform A U) (Umeas : Measurable U)
(Vunif : IsUniform B V) (Vmeas : Measurable V) (hindep : IndepFun U V) :
(ℙ : Measure Ω).real ((U - V) ⁻¹' {0})
= Nat.card (A ∩ B : Set G) / (Nat.card A * Nat.card B) := by
have : (U - V) ⁻¹' {0} = ⋃ (g : G), (U ⁻¹' {g} ∩ V⁻¹' {g}) := by
ext ω; simp [sub_eq_zero, eq_comm]
rw [this, measureReal_iUnion_fintype _
(fun i ↦ (Umeas $ measurableSet_discrete _).inter $ Vmeas $ measurableSet_discrete _)]; swap
· intro g g' hgg'
apply Set.disjoint_iff_inter_eq_empty.2
ext a
simp (config := {contextual := True}) [hgg']
classical
let W : Finset G := A ∩ B
calc
∑ p, (ℙ : Measure Ω).real (U ⁻¹' {p} ∩ V ⁻¹' {p})
= ∑ p, (ℙ : Measure Ω).real (U ⁻¹' {p}) * (ℙ : Measure Ω).real (V ⁻¹' {p}) := by
apply sum_congr _ _ (fun g ↦ ?_)
rw [hindep.measureReal_inter_preimage_eq_mul (measurableSet_discrete _) $
measurableSet_discrete _]
_ = ∑ p in W, (ℙ : Measure Ω).real (U ⁻¹' {p}) * (ℙ : Measure Ω).real (V ⁻¹' {p}) := by
apply (Finset.sum_subset W.subset_univ _).symm
intro i _ hi
replace hi : i ∉ A ∨ i ∉ B := by simp [W] at hi; tauto
rcases hi with h'i|h'i
· simp [Uunif.measureReal_preimage_of_nmem h'i]
· simp [Vunif.measureReal_preimage_of_nmem h'i]
_ = ∑ p in W, (1 / Nat.card A : ℝ) * (1 / Nat.card B) := by
apply Finset.sum_congr rfl (fun i hi ↦ ?_)
replace hi : i ∈ A ∧ i ∈ B := by simpa [W] using hi
rw [Uunif.measureReal_preimage_of_mem (by trivial) hi.1,
Vunif.measureReal_preimage_of_mem (by trivial) hi.2]
_ = (W.card : ℝ) / (Nat.card A * Nat.card B) := by simp [div_eq_inv_mul]; ring
_ = Nat.card (A ∩ B : Set G) / (Nat.card A * Nat.card B) := by
congr
rw [← Finset.coe_inter, Nat.card_eq_fintype_card, Fintype.card_ofFinset]
simp
/-- Given two independent random variables `U` and `V` uniformly distributed respectively on `A`
and `B`, then `U = V + x` with probability `# (A ∩ (B + x)) / #A ⬝ #B`. -/
lemma IsUniform.measureReal_preimage_sub (Uunif : IsUniform A U) (Umeas : Measurable U)
(Vunif : IsUniform B V) (Vmeas : Measurable V) (hindep : IndepFun U V) (x : G) :
(ℙ : Measure Ω).real ((U - V) ⁻¹' {x})
= Nat.card (A ∩ (B + {x}) : Set G) / (Nat.card A * Nat.card B) := by
classical
let W := fun ω ↦ V ω + x
have Wunif : IsUniform (B + {x} : Set G) W := by
convert Vunif.comp (add_left_injective x)
simp
have Wmeas : Measurable W := Vmeas.add_const _
have UWindep : IndepFun U W := by
have : Measurable (fun g ↦ g + x) := measurable_add_const x
exact hindep.comp measurable_id this
have : (U - V) ⁻¹' {x} = (U - W) ⁻¹' {0} := by
ext ω
simp only [W, mem_preimage, Pi.add_apply, mem_singleton_iff, Pi.sub_apply, ← sub_eq_zero (b := x)]
abel_nf
have h : (B:Set G)+{x} = (B+{x}:Finset G) := by simp
rw [h] at Wunif
rw [this, Uunif.measureReal_preimage_sub_zero Umeas Wunif Wmeas UWindep]
congr 3
. rw [add_singleton]; simp
convert Finset.card_vadd_finset (AddOpposite.op x) B
. simp
simp
end ProbabilityTheory
/-- Record positivity results that are useful in the proof of PFR. -/
lemma PFR_conjecture_pos_aux {G : Type*} [AddCommGroup G] {A : Set G} [Finite A] {K : ℝ} (h₀A : A.Nonempty) (hA : Nat.card (A - A) ≤ K * Nat.card A) :
(0 : ℝ) < Nat.card A ∧ (0 : ℝ) < Nat.card (A - A) ∧ 0 < K := by
have card_AA_pos : (0 : ℝ) < Nat.card (A - A) := by
have : Nonempty (A - A) := Set.nonempty_coe_sort.mpr (Set.Nonempty.sub h₀A h₀A)
have : Finite (A - A) := finite_coe_iff.mpr (Finite.image2 _ (Set.toFinite A) (Set.toFinite A))
simp [Nat.cast_pos, Nat.card_pos_iff]
have KA_pos : 0 < K ∧ (0 : ℝ) < Nat.card A := by
have I : ¬ ((Nat.card A : ℝ) < 0) := by simp
simpa [Nat.cast_pos, I, and_false, or_false] using mul_pos_iff.1 (card_AA_pos.trans_le hA)
exact ⟨KA_pos.2, card_AA_pos, KA_pos.1⟩
lemma PFR_conjecture_pos_aux' {G : Type*} [AddCommGroup G] {A : Set G} [Finite A] {K : ℝ} (h₀A : A.Nonempty) (hA : Nat.card (A + A) ≤ K * Nat.card A) :
(0 : ℝ) < Nat.card A ∧ (0 : ℝ) < Nat.card (A + A) ∧ 0 < K := by
have card_AA_pos : (0 : ℝ) < Nat.card (A + A) := by
have : Nonempty (A + A) := Set.nonempty_coe_sort.mpr (Set.Nonempty.add h₀A h₀A)
have : Finite (A + A) := finite_coe_iff.mpr (Finite.image2 _ (Set.toFinite A) (Set.toFinite A))
simp [Nat.cast_pos, Nat.card_pos_iff]
have KA_pos : 0 < K ∧ (0 : ℝ) < Nat.card A := by
have I : ¬ ((Nat.card A : ℝ) < 0) := by simp
simpa [Nat.cast_pos, I, and_false, or_false] using mul_pos_iff.1 (card_AA_pos.trans_le hA)
exact ⟨KA_pos.2, card_AA_pos, KA_pos.1⟩
variable {G : Type*} [AddCommGroup G] [MeasurableSpace G]
[MeasurableSingletonClass G] {A : Set G} [Finite A] {K : ℝ} [Countable G]
/-- A uniform distribution on a set with doubling constant `K` has self Rusza distance
at most `log K`. -/
theorem rdist_le_of_isUniform_of_card_add_le (h₀A : A.Nonempty) (hA : Nat.card (A - A) ≤ K * Nat.card A)
{Ω : Type*} [MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)] {U₀ : Ω → G}
(U₀unif : IsUniform A U₀) (U₀meas : Measurable U₀) : d[U₀ # U₀] ≤ log K := by
obtain ⟨A_pos, AA_pos, K_pos⟩ : (0 : ℝ) < Nat.card A ∧ (0 : ℝ) < Nat.card (A - A) ∧ 0 < K :=
PFR_conjecture_pos_aux h₀A hA
rcases independent_copies_two U₀meas U₀meas with ⟨Ω, mΩ, U, U', hP, hU, hU', UU'_indep, idU, idU'⟩
have Uunif : IsUniform A U := U₀unif.of_identDistrib idU.symm $ measurableSet_discrete _
have U'unif : IsUniform A U' := U₀unif.of_identDistrib idU'.symm $ measurableSet_discrete _
have IU : d[U # U'] ≤ log K := by
have I : H[U - U'] ≤ log (Nat.card (A - A)) := by
convert entropy_le_log_card_of_mem (A := (A-A).toFinite.toFinset) ?_ ?_ with x
. simp
exact Iff.rfl
. measurability
filter_upwards [Uunif.ae_mem, U'unif.ae_mem] with ω h1 h2
simp
exact Set.sub_mem_sub h1 h2
have J : log (Nat.card (A - A)) ≤ log K + log (Nat.card A) := by
apply (log_le_log AA_pos hA).trans (le_of_eq _)
rw [log_mul K_pos.ne' A_pos.ne']
-- have : H[U + U'] = H[U - U'] := by congr; simp
rw [UU'_indep.rdist_eq hU hU', IsUniform.entropy_eq' Uunif hU, IsUniform.entropy_eq' U'unif hU']
linarith
rwa [idU.rdist_eq idU'] at IU
variable [ElementaryAddCommGroup G 2] [Fintype G]
lemma sumset_eq_sub : A + A = A - A := by
rw [← Set.image2_add, ← Set.image2_sub]
congr! 1 with a _ b _
show a + b = a - b
simp
/-- Auxiliary statement towards the polynomial Freiman-Ruzsa (PFR) conjecture: if $A$ is a subset of
an elementary abelian 2-group of doubling constant at most $K$, then there exists a subgroup $H$
such that $A$ can be covered by at most $K^{13/2} |A|^{1/2} / |H|^{1/2}$ cosets of $H$, and $H$ has
the same cardinality as $A$ up to a multiplicative factor $K^11$. -/
lemma PFR_conjecture_aux (h₀A : A.Nonempty) (hA : Nat.card (A + A) ≤ K * Nat.card A) :
∃ (H : AddSubgroup G) (c : Set G),
Nat.card c ≤ K ^ (13/2) * (Nat.card A) ^ (1/2) * (Nat.card (H : Set G)) ^ (-1/2)
∧ Nat.card H ≤ K ^ 11 * Nat.card A ∧ Nat.card A ≤ K ^ 11 * Nat.card H ∧ A ⊆ c + H := by
classical
let _mG : MeasurableSpace G := ⊤
rw [sumset_eq_sub] at hA
have : MeasurableSingletonClass G := ⟨λ _ ↦ trivial⟩
obtain ⟨A_pos, -, K_pos⟩ : (0 : ℝ) < Nat.card A ∧ (0 : ℝ) < Nat.card (A - A) ∧ 0 < K :=
PFR_conjecture_pos_aux h₀A hA
let A' := A.toFinite.toFinset
have h₀A' : Finset.Nonempty A' := by
simp [A', Finset.Nonempty]
exact h₀A
have hAA' : A' = A := Finite.coe_toFinset (toFinite A)
rcases exists_isUniform_measureSpace A' h₀A' with ⟨Ω₀, mΩ₀, UA, hP₀, UAmeas, UAunif, -, -⟩
rw [hAA'] at UAunif
have : d[UA # UA] ≤ log K := rdist_le_of_isUniform_of_card_add_le h₀A hA UAunif UAmeas
rw [← sumset_eq_sub] at hA
let p : refPackage Ω₀ Ω₀ G := ⟨UA, UA, UAmeas, UAmeas, 1/9, (by norm_num), (by norm_num)⟩
-- entropic PFR gives a subgroup `H` which is close to `A` for the Rusza distance
rcases entropic_PFR_conjecture p (by norm_num) with ⟨H, Ω₁, mΩ₁, UH, hP₁, UHmeas, UHunif, hUH⟩
rcases independent_copies_two UAmeas UHmeas
with ⟨Ω, mΩ, VA, VH, hP, VAmeas, VHmeas, Vindep, idVA, idVH⟩
have VAunif : IsUniform A VA := UAunif.of_identDistrib idVA.symm $ measurableSet_discrete _
have VA'unif := VAunif
rw [← hAA'] at VA'unif
have VHunif : IsUniform H VH := UHunif.of_identDistrib idVH.symm $ measurableSet_discrete _
let H' := (H:Set G).toFinite.toFinset
have hHH' : H' = (H:Set G) := Finite.coe_toFinset (toFinite (H:Set G))
have VH'unif := VHunif
rw [← hHH'] at VH'unif
have : d[VA # VH] ≤ 11/2 * log K := by rw [idVA.rdist_eq idVH]; linarith
have H_pos : (0 : ℝ) < Nat.card (H : Set G) := by
have : 0 < Nat.card (H : Set G) := Nat.card_pos
positivity
have VA_ent : H[VA] = log (Nat.card A) := IsUniform.entropy_eq' VAunif VAmeas
have VH_ent : H[VH] = log (Nat.card (H : Set G)) := IsUniform.entropy_eq' VHunif VHmeas
have Icard : |log (Nat.card A) - log (Nat.card (H : Set G))| ≤ 11 * log K := by
rw [← VA_ent, ← VH_ent]
apply (diff_ent_le_rdist VAmeas VHmeas).trans
linarith
have IAH : Nat.card A ≤ K ^ 11 * Nat.card (H : Set G) := by
have : log (Nat.card A) ≤ log K * 11 + log (Nat.card (H : Set G)) := by
linarith [(le_abs_self _).trans Icard]
convert exp_monotone this using 1
· exact (exp_log A_pos).symm
· rw [exp_add, exp_log H_pos, ← rpow_def_of_pos K_pos]
have IHA : Nat.card (H : Set G) ≤ K ^ 11 * Nat.card A := by
have : log (Nat.card (H : Set G)) ≤ log K * 11 + log (Nat.card A) := by
linarith [(neg_le_abs _).trans Icard]
convert exp_monotone this using 1
· exact (exp_log H_pos).symm
· rw [exp_add, exp_log A_pos, ← rpow_def_of_pos K_pos]
-- entropic PFR shows that the entropy of `VA - VH` is small
have I : log K * (-11/2) + log (Nat.card A) * (-1/2) + log (Nat.card (H : Set G)) * (-1/2)
≤ - H[VA - VH] := by
rw [Vindep.rdist_eq VAmeas VHmeas] at this
have : H[VA] = log (Nat.card A) := IsUniform.entropy_eq' VAunif VAmeas
have : H[VH] = log (Nat.card (H : Set G)) := IsUniform.entropy_eq' VHunif VHmeas
linarith
-- therefore, there exists a point `x₀` which is attained by `VA - VH` with a large probability
obtain ⟨x₀, h₀⟩ : ∃ x₀ : G, rexp (- H[VA - VH]) ≤ (ℙ : Measure Ω).real ((VA - VH) ⁻¹' {x₀}) :=
prob_ge_exp_neg_entropy' _ ((VAmeas.sub VHmeas).comp measurable_id')
-- massage the previous inequality to get that `A ∩ (H + {x₀})` is large
have J : K ^ (-11/2) * (Nat.card A) ^ (1/2) * (Nat.card (H : Set G)) ^ (1/2) ≤
Nat.card (A ∩ (H + {x₀}) : Set G) := by
rw [VA'unif.measureReal_preimage_sub VAmeas VH'unif VHmeas Vindep] at h₀
have := (Real.exp_monotone I).trans h₀
have hAA'_card : Nat.card A' = Nat.card A := congrArg Nat.card (congrArg Subtype hAA')
have hHH'_card : Nat.card H' = Nat.card (H : Set G) := congrArg Nat.card (congrArg Subtype hHH')
rw [hAA'_card, hHH'_card, le_div_iff] at this
convert this using 1
. rw [exp_add, exp_add, ← rpow_def_of_pos K_pos, ← rpow_def_of_pos A_pos, ← rpow_def_of_pos H_pos]
rpow_ring
norm_num
. rw [hAA', hHH']
positivity
have Hne : Set.Nonempty (A ∩ (H + {x₀} : Set G)) := by
by_contra h'
have : (0 : ℝ) < Nat.card (A ∩ (H + {x₀}) : Set G) := lt_of_lt_of_le (by positivity) J
simp only [Nat.card_eq_fintype_card, card_of_isEmpty, CharP.cast_eq_zero, lt_self_iff_false,
not_nonempty_iff_eq_empty.1 h'] at this
/- use Rusza covering lemma to cover `A` by few translates of `A ∩ (H + {x₀}) - A ∩ (H + {x₀})`
(which is contained in `H`). The number of translates is at most
`#(A + (A ∩ (H + {x₀}))) / #(A ∩ (H + {x₀}))`, where the numerator is controlled as this is
a subset of `A + A`, and the denominator is bounded below by the previous inequality`. -/
rcases Set.exists_subset_add_sub (toFinite A) (toFinite (A ∩ ((H + {x₀} : Set G)))) Hne with
⟨u, hu, Au, -⟩
have Iu : Nat.card u ≤ K ^ (13/2) * (Nat.card A) ^ (1/2) * (Nat.card (H : Set G)) ^ (-1/2) := by
have : (0 : ℝ) ≤ Nat.card u := by simp
have Z1 := mul_le_mul_of_nonneg_left J this
have Z2 : (Nat.card u * Nat.card (A ∩ (H + {x₀}) : Set G) : ℝ)
≤ Nat.card (A + A ∩ (↑H + {x₀})) := by norm_cast
have Z3 : (Nat.card (A + A ∩ (↑H + {x₀})) : ℝ) ≤ K * Nat.card A := by
apply le_trans _ hA
simp only [Nat.cast_le]
apply Nat.card_mono (toFinite _)
apply add_subset_add_left (inter_subset_left _ _)
have : 0 ≤ K ^ (11/2) * Nat.card A ^ (-1/2) * Nat.card (H : Set G) ^ (-1/2) := by positivity
have T := mul_le_mul_of_nonneg_left ((Z1.trans Z2).trans Z3) this
convert T using 1 <;> rpow_ring <;> norm_num
have A_subset_uH : A ⊆ u + H := by
rw [add_sub_assoc] at Au
refine Au.trans $ add_subset_add_left $
(sub_subset_sub (inter_subset_right ..) (inter_subset_right ..)).trans ?_
rw [add_sub_add_comm, singleton_sub_singleton, sub_self]
simp
exact ⟨H, u, Iu, IHA, IAH, A_subset_uH⟩
/-- The polynomial Freiman-Ruzsa (PFR) conjecture: if $A$ is a subset of an elementary abelian
2-group of doubling constant at most $K$, then $A$ can be covered by at most $2K^{12}$ cosets of
a subgroup of cardinality at most $|A|$. -/
| theorem PFR_conjecture (h₀A : A.Nonempty) (hA : Nat.card (A + A) ≤ K * Nat.card A) :
∃ (H : AddSubgroup G) (c : Set G),
Nat.card c < 2 * K ^ 12 ∧ Nat.card H ≤ Nat.card A ∧ A ⊆ c + H | PFR_conjecture | 516205a 20231114 | b94162e 20231128 | pfr/PFR/Main.lean | {
"lineInFile": 281,
"tokenPositionInFile": 14390,
"theoremPositionInFile": 8
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n obtain ⟨A_pos, -, K_pos⟩ : (0 : ℝ) < Nat.card A ∧ (0 : ℝ) < Nat.card (A + A) ∧ 0 < K :=\n PFR_conjecture_pos_aux' h₀A hA\n -- consider the subgroup `H` given by Lemma `PFR_conjecture_aux`.\n obtain ⟨H, c, hc, IHA, IAH, A_subs_cH⟩ : ∃ (H : AddSubgroup G) (c : Set G),\n Nat.card c ≤ K ^ (13/2) * (Nat.card A) ^ (1/2) * (Nat.card (H : Set G)) ^ (-1/2)\n ∧ Nat.card (H : Set G) ≤ K ^ 11 * Nat.card A ∧ Nat.card A ≤ K ^ 11 * Nat.card (H : Set G)\n ∧ A ⊆ c + H :=\n PFR_conjecture_aux h₀A hA\n have H_pos : (0 : ℝ) < Nat.card (H : Set G) := by\n have : 0 < Nat.card (H : Set G) := Nat.card_pos; positivity\n rcases le_or_lt (Nat.card (H : Set G)) (Nat.card A) with h|h\n -- If `#H ≤ #A`, then `H` satisfies the conclusion of the theorem\n · refine ⟨H, c, ?_, h, A_subs_cH⟩\n calc\n Nat.card c ≤ K ^ (13/2) * (Nat.card A) ^ (1/2) * (Nat.card (H : Set G)) ^ (-1/2) := hc\n _ ≤ K ^ (13/2) * (K ^ 11 * Nat.card (H : Set G)) ^ (1/2) * (Nat.card (H : Set G)) ^ (-1/2) := by\n gcongr\n _ = K ^ 12 := by rpow_ring; norm_num\n _ < 2 * K ^ 12 := by linarith [show 0 < K ^ 12 by positivity]\n -- otherwise, we decompose `H` into cosets of one of its subgroups `H'`, chosen so that\n -- `#A / 2 < #H' ≤ #A`. This `H'` satisfies the desired conclusion.\n · obtain ⟨H', IH'A, IAH', H'H⟩ : ∃ H' : AddSubgroup G, Nat.card (H' : Set G) ≤ Nat.card A\n ∧ Nat.card A < 2 * Nat.card (H' : Set G) ∧ H' ≤ H := by\n have A_pos' : 0 < Nat.card A := mod_cast A_pos\n exact ElementaryAddCommGroup.exists_subgroup_subset_card_le Nat.prime_two H h.le A_pos'.ne'\n have : (Nat.card A / 2 : ℝ) < Nat.card (H' : Set G) := by\n rw [div_lt_iff zero_lt_two, mul_comm]; norm_cast\n have H'_pos : (0 : ℝ) < Nat.card (H' : Set G) := by\n have : 0 < Nat.card (H' : Set G) := Nat.card_pos; positivity\n obtain ⟨u, HH'u, hu⟩ := AddSubgroup.exists_left_transversal_of_le H'H\n refine ⟨H', c + u, ?_, IH'A, by rwa [add_assoc, HH'u]⟩\n calc\n (Nat.card (c + u) : ℝ)\n ≤ Nat.card c * Nat.card u := mod_cast card_add_le\n _ ≤ (K ^ (13/2) * (Nat.card A) ^ (1 / 2) * (Nat.card (H : Set G) ^ (-1 / 2)))\n * (Nat.card (H : Set G) / Nat.card (H' : Set G)) := by\n gcongr\n apply le_of_eq\n rw [eq_div_iff H'_pos.ne']\n norm_cast\n _ < (K ^ (13/2) * (Nat.card A) ^ (1 / 2) * (Nat.card (H : Set G) ^ (-1 / 2)))\n * (Nat.card (H : Set G) / (Nat.card A / 2)) := by\n gcongr\n _ = 2 * K ^ (13/2) * (Nat.card A) ^ (-1/2) * (Nat.card (H : Set G)) ^ (1/2) := by\n have : (0 : ℝ) < Nat.card H := H_pos\n field_simp\n rpow_ring\n norm_num\n _ ≤ 2 * K ^ (13/2) * (Nat.card A) ^ (-1/2) * (K ^ 11 * Nat.card A) ^ (1/2) := by\n gcongr\n _ = 2 * K ^ 12 := by\n rpow_ring\n norm_num",
"proofType": "tactic",
"proofLengthLines": 54,
"proofLengthTokens": 2783
} | pfr |
import Mathlib.Combinatorics.Additive.RuzsaCovering
import Mathlib.GroupTheory.Complement
import Mathlib.GroupTheory.OrderOfElement
import PFR.Mathlib.GroupTheory.Subgroup.Pointwise
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Tactic.RPowSimp
import PFR.TauFunctional
import PFR.EntropyPFR
/- In this file the power notation will always mean the base and exponent are real numbers. -/
local macro_rules | `($x ^ $y) => `(HPow.hPow ($x : ℝ) ($y : ℝ))
/-!
# Polynomial Freiman-Ruzsa conjecture
Here we prove the polynomial Freiman-Ruzsa conjecture.
-/
open ProbabilityTheory MeasureTheory Real Set Fintype Function
open scoped BigOperators Pointwise
universe u
namespace ProbabilityTheory
variable {G Ω : Type*} [AddCommGroup G] [Fintype G]
[MeasurableSpace G] [MeasurableSingletonClass G] {A B : Finset G}
[MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)] {U V : Ω → G}
/-- Given two independent random variables `U` and `V` uniformly distributed respectively on `A`
and `B`, then `U = V` with probability `# (A ∩ B) / #A ⬝ #B`. -/
lemma IsUniform.measureReal_preimage_sub_zero (Uunif : IsUniform A U) (Umeas : Measurable U)
(Vunif : IsUniform B V) (Vmeas : Measurable V) (hindep : IndepFun U V) :
(ℙ : Measure Ω).real ((U - V) ⁻¹' {0})
= Nat.card (A ∩ B : Set G) / (Nat.card A * Nat.card B) := by
have : (U - V) ⁻¹' {0} = ⋃ (g : G), (U ⁻¹' {g} ∩ V⁻¹' {g}) := by
ext ω; simp [sub_eq_zero, eq_comm]
rw [this, measureReal_iUnion_fintype _
(fun i ↦ (Umeas $ measurableSet_discrete _).inter $ Vmeas $ measurableSet_discrete _)]; swap
· intro g g' hgg'
apply Set.disjoint_iff_inter_eq_empty.2
ext a
simp (config := {contextual := True}) [hgg']
classical
let W : Finset G := A ∩ B
calc
∑ p, (ℙ : Measure Ω).real (U ⁻¹' {p} ∩ V ⁻¹' {p})
= ∑ p, (ℙ : Measure Ω).real (U ⁻¹' {p}) * (ℙ : Measure Ω).real (V ⁻¹' {p}) := by
apply sum_congr _ _ (fun g ↦ ?_)
rw [hindep.measureReal_inter_preimage_eq_mul (measurableSet_discrete _) $
measurableSet_discrete _]
_ = ∑ p in W, (ℙ : Measure Ω).real (U ⁻¹' {p}) * (ℙ : Measure Ω).real (V ⁻¹' {p}) := by
apply (Finset.sum_subset W.subset_univ _).symm
intro i _ hi
replace hi : i ∉ A ∨ i ∉ B := by simp [W] at hi; tauto
rcases hi with h'i|h'i
· simp [Uunif.measureReal_preimage_of_nmem h'i]
· simp [Vunif.measureReal_preimage_of_nmem h'i]
_ = ∑ p in W, (1 / Nat.card A : ℝ) * (1 / Nat.card B) := by
apply Finset.sum_congr rfl (fun i hi ↦ ?_)
replace hi : i ∈ A ∧ i ∈ B := by simpa [W] using hi
rw [Uunif.measureReal_preimage_of_mem (by trivial) hi.1,
Vunif.measureReal_preimage_of_mem (by trivial) hi.2]
_ = (W.card : ℝ) / (Nat.card A * Nat.card B) := by simp [div_eq_inv_mul]; ring
_ = Nat.card (A ∩ B : Set G) / (Nat.card A * Nat.card B) := by
congr
rw [← Finset.coe_inter, Nat.card_eq_fintype_card, Fintype.card_ofFinset]
simp
/-- Given two independent random variables `U` and `V` uniformly distributed respectively on `A`
and `B`, then `U = V + x` with probability `# (A ∩ (B + x)) / #A ⬝ #B`. -/
lemma IsUniform.measureReal_preimage_sub (Uunif : IsUniform A U) (Umeas : Measurable U)
(Vunif : IsUniform B V) (Vmeas : Measurable V) (hindep : IndepFun U V) (x : G) :
(ℙ : Measure Ω).real ((U - V) ⁻¹' {x})
= Nat.card (A ∩ (B + {x}) : Set G) / (Nat.card A * Nat.card B) := by
classical
let W := fun ω ↦ V ω + x
have Wunif : IsUniform (B + {x} : Set G) W := by
convert Vunif.comp (add_left_injective x)
simp
have Wmeas : Measurable W := Vmeas.add_const _
have UWindep : IndepFun U W := by
have : Measurable (fun g ↦ g + x) := measurable_add_const x
exact hindep.comp measurable_id this
have : (U - V) ⁻¹' {x} = (U - W) ⁻¹' {0} := by
ext ω
simp only [W, mem_preimage, Pi.add_apply, mem_singleton_iff, Pi.sub_apply, ← sub_eq_zero (b := x)]
abel_nf
have h : (B:Set G)+{x} = (B+{x}:Finset G) := by simp
rw [h] at Wunif
rw [this, Uunif.measureReal_preimage_sub_zero Umeas Wunif Wmeas UWindep]
congr 3
. rw [add_singleton]; simp
convert Finset.card_vadd_finset (AddOpposite.op x) B
. simp
simp
end ProbabilityTheory
/-- Record positivity results that are useful in the proof of PFR. -/
lemma PFR_conjecture_pos_aux {G : Type*} [AddCommGroup G] {A : Set G} [Finite A] {K : ℝ} (h₀A : A.Nonempty) (hA : Nat.card (A - A) ≤ K * Nat.card A) :
(0 : ℝ) < Nat.card A ∧ (0 : ℝ) < Nat.card (A - A) ∧ 0 < K := by
have card_AA_pos : (0 : ℝ) < Nat.card (A - A) := by
have : Nonempty (A - A) := Set.nonempty_coe_sort.mpr (Set.Nonempty.sub h₀A h₀A)
have : Finite (A - A) := finite_coe_iff.mpr (Finite.image2 _ (Set.toFinite A) (Set.toFinite A))
simp [Nat.cast_pos, Nat.card_pos_iff]
have KA_pos : 0 < K ∧ (0 : ℝ) < Nat.card A := by
have I : ¬ ((Nat.card A : ℝ) < 0) := by simp
simpa [Nat.cast_pos, I, and_false, or_false] using mul_pos_iff.1 (card_AA_pos.trans_le hA)
exact ⟨KA_pos.2, card_AA_pos, KA_pos.1⟩
lemma PFR_conjecture_pos_aux' {G : Type*} [AddCommGroup G] {A : Set G} [Finite A] {K : ℝ} (h₀A : A.Nonempty) (hA : Nat.card (A + A) ≤ K * Nat.card A) :
(0 : ℝ) < Nat.card A ∧ (0 : ℝ) < Nat.card (A + A) ∧ 0 < K := by
have card_AA_pos : (0 : ℝ) < Nat.card (A + A) := by
have : Nonempty (A + A) := Set.nonempty_coe_sort.mpr (Set.Nonempty.add h₀A h₀A)
have : Finite (A + A) := finite_coe_iff.mpr (Finite.image2 _ (Set.toFinite A) (Set.toFinite A))
simp [Nat.cast_pos, Nat.card_pos_iff]
have KA_pos : 0 < K ∧ (0 : ℝ) < Nat.card A := by
have I : ¬ ((Nat.card A : ℝ) < 0) := by simp
simpa [Nat.cast_pos, I, and_false, or_false] using mul_pos_iff.1 (card_AA_pos.trans_le hA)
exact ⟨KA_pos.2, card_AA_pos, KA_pos.1⟩
variable {G : Type*} [AddCommGroup G] [MeasurableSpace G]
[MeasurableSingletonClass G] {A : Set G} [Finite A] {K : ℝ} [Countable G]
/-- A uniform distribution on a set with doubling constant `K` has self Rusza distance
at most `log K`. -/
theorem rdist_le_of_isUniform_of_card_add_le (h₀A : A.Nonempty) (hA : Nat.card (A - A) ≤ K * Nat.card A)
{Ω : Type*} [MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)] {U₀ : Ω → G}
(U₀unif : IsUniform A U₀) (U₀meas : Measurable U₀) : d[U₀ # U₀] ≤ log K := by
obtain ⟨A_pos, AA_pos, K_pos⟩ : (0 : ℝ) < Nat.card A ∧ (0 : ℝ) < Nat.card (A - A) ∧ 0 < K :=
PFR_conjecture_pos_aux h₀A hA
rcases independent_copies_two U₀meas U₀meas with ⟨Ω, mΩ, U, U', hP, hU, hU', UU'_indep, idU, idU'⟩
have Uunif : IsUniform A U := U₀unif.of_identDistrib idU.symm $ measurableSet_discrete _
have U'unif : IsUniform A U' := U₀unif.of_identDistrib idU'.symm $ measurableSet_discrete _
have IU : d[U # U'] ≤ log K := by
have I : H[U - U'] ≤ log (Nat.card (A - A)) := by
convert entropy_le_log_card_of_mem (A := (A-A).toFinite.toFinset) ?_ ?_ with x
. simp
exact Iff.rfl
. measurability
filter_upwards [Uunif.ae_mem, U'unif.ae_mem] with ω h1 h2
simp
exact Set.sub_mem_sub h1 h2
have J : log (Nat.card (A - A)) ≤ log K + log (Nat.card A) := by
apply (log_le_log AA_pos hA).trans (le_of_eq _)
rw [log_mul K_pos.ne' A_pos.ne']
-- have : H[U + U'] = H[U - U'] := by congr; simp
rw [UU'_indep.rdist_eq hU hU', IsUniform.entropy_eq' Uunif hU, IsUniform.entropy_eq' U'unif hU']
linarith
rwa [idU.rdist_eq idU'] at IU
variable [ElementaryAddCommGroup G 2] [Fintype G]
lemma sumset_eq_sub : A + A = A - A := by
rw [← Set.image2_add, ← Set.image2_sub]
congr! 1 with a _ b _
show a + b = a - b
simp
/-- Auxiliary statement towards the polynomial Freiman-Ruzsa (PFR) conjecture: if $A$ is a subset of
an elementary abelian 2-group of doubling constant at most $K$, then there exists a subgroup $H$
such that $A$ can be covered by at most $K^{13/2} |A|^{1/2} / |H|^{1/2}$ cosets of $H$, and $H$ has
the same cardinality as $A$ up to a multiplicative factor $K^11$. -/
lemma PFR_conjecture_aux (h₀A : A.Nonempty) (hA : Nat.card (A + A) ≤ K * Nat.card A) :
∃ (H : AddSubgroup G) (c : Set G),
Nat.card c ≤ K ^ (13/2) * (Nat.card A) ^ (1/2) * (Nat.card (H : Set G)) ^ (-1/2)
∧ Nat.card H ≤ K ^ 11 * Nat.card A ∧ Nat.card A ≤ K ^ 11 * Nat.card H ∧ A ⊆ c + H := by
classical
let _mG : MeasurableSpace G := ⊤
rw [sumset_eq_sub] at hA
have : MeasurableSingletonClass G := ⟨λ _ ↦ trivial⟩
obtain ⟨A_pos, -, K_pos⟩ : (0 : ℝ) < Nat.card A ∧ (0 : ℝ) < Nat.card (A - A) ∧ 0 < K :=
PFR_conjecture_pos_aux h₀A hA
let A' := A.toFinite.toFinset
have h₀A' : Finset.Nonempty A' := by
simp [A', Finset.Nonempty]
exact h₀A
have hAA' : A' = A := Finite.coe_toFinset (toFinite A)
rcases exists_isUniform_measureSpace A' h₀A' with ⟨Ω₀, mΩ₀, UA, hP₀, UAmeas, UAunif, -, -⟩
rw [hAA'] at UAunif
have : d[UA # UA] ≤ log K := rdist_le_of_isUniform_of_card_add_le h₀A hA UAunif UAmeas
rw [← sumset_eq_sub] at hA
let p : refPackage Ω₀ Ω₀ G := ⟨UA, UA, UAmeas, UAmeas, 1/9, (by norm_num), (by norm_num)⟩
-- entropic PFR gives a subgroup `H` which is close to `A` for the Rusza distance
rcases entropic_PFR_conjecture p (by norm_num) with ⟨H, Ω₁, mΩ₁, UH, hP₁, UHmeas, UHunif, hUH⟩
rcases independent_copies_two UAmeas UHmeas
with ⟨Ω, mΩ, VA, VH, hP, VAmeas, VHmeas, Vindep, idVA, idVH⟩
have VAunif : IsUniform A VA := UAunif.of_identDistrib idVA.symm $ measurableSet_discrete _
have VA'unif := VAunif
rw [← hAA'] at VA'unif
have VHunif : IsUniform H VH := UHunif.of_identDistrib idVH.symm $ measurableSet_discrete _
let H' := (H:Set G).toFinite.toFinset
have hHH' : H' = (H:Set G) := Finite.coe_toFinset (toFinite (H:Set G))
have VH'unif := VHunif
rw [← hHH'] at VH'unif
have : d[VA # VH] ≤ 11/2 * log K := by rw [idVA.rdist_eq idVH]; linarith
have H_pos : (0 : ℝ) < Nat.card (H : Set G) := by
have : 0 < Nat.card (H : Set G) := Nat.card_pos
positivity
have VA_ent : H[VA] = log (Nat.card A) := IsUniform.entropy_eq' VAunif VAmeas
have VH_ent : H[VH] = log (Nat.card (H : Set G)) := IsUniform.entropy_eq' VHunif VHmeas
have Icard : |log (Nat.card A) - log (Nat.card (H : Set G))| ≤ 11 * log K := by
rw [← VA_ent, ← VH_ent]
apply (diff_ent_le_rdist VAmeas VHmeas).trans
linarith
have IAH : Nat.card A ≤ K ^ 11 * Nat.card (H : Set G) := by
have : log (Nat.card A) ≤ log K * 11 + log (Nat.card (H : Set G)) := by
linarith [(le_abs_self _).trans Icard]
convert exp_monotone this using 1
· exact (exp_log A_pos).symm
· rw [exp_add, exp_log H_pos, ← rpow_def_of_pos K_pos]
have IHA : Nat.card (H : Set G) ≤ K ^ 11 * Nat.card A := by
have : log (Nat.card (H : Set G)) ≤ log K * 11 + log (Nat.card A) := by
linarith [(neg_le_abs _).trans Icard]
convert exp_monotone this using 1
· exact (exp_log H_pos).symm
· rw [exp_add, exp_log A_pos, ← rpow_def_of_pos K_pos]
-- entropic PFR shows that the entropy of `VA - VH` is small
have I : log K * (-11/2) + log (Nat.card A) * (-1/2) + log (Nat.card (H : Set G)) * (-1/2)
≤ - H[VA - VH] := by
rw [Vindep.rdist_eq VAmeas VHmeas] at this
have : H[VA] = log (Nat.card A) := IsUniform.entropy_eq' VAunif VAmeas
have : H[VH] = log (Nat.card (H : Set G)) := IsUniform.entropy_eq' VHunif VHmeas
linarith
-- therefore, there exists a point `x₀` which is attained by `VA - VH` with a large probability
obtain ⟨x₀, h₀⟩ : ∃ x₀ : G, rexp (- H[VA - VH]) ≤ (ℙ : Measure Ω).real ((VA - VH) ⁻¹' {x₀}) :=
prob_ge_exp_neg_entropy' _ ((VAmeas.sub VHmeas).comp measurable_id')
-- massage the previous inequality to get that `A ∩ (H + {x₀})` is large
have J : K ^ (-11/2) * (Nat.card A) ^ (1/2) * (Nat.card (H : Set G)) ^ (1/2) ≤
Nat.card (A ∩ (H + {x₀}) : Set G) := by
rw [VA'unif.measureReal_preimage_sub VAmeas VH'unif VHmeas Vindep] at h₀
have := (Real.exp_monotone I).trans h₀
have hAA'_card : Nat.card A' = Nat.card A := congrArg Nat.card (congrArg Subtype hAA')
have hHH'_card : Nat.card H' = Nat.card (H : Set G) := congrArg Nat.card (congrArg Subtype hHH')
rw [hAA'_card, hHH'_card, le_div_iff] at this
convert this using 1
. rw [exp_add, exp_add, ← rpow_def_of_pos K_pos, ← rpow_def_of_pos A_pos, ← rpow_def_of_pos H_pos]
rpow_ring
norm_num
. rw [hAA', hHH']
positivity
have Hne : Set.Nonempty (A ∩ (H + {x₀} : Set G)) := by
by_contra h'
have : (0 : ℝ) < Nat.card (A ∩ (H + {x₀}) : Set G) := lt_of_lt_of_le (by positivity) J
simp only [Nat.card_eq_fintype_card, card_of_isEmpty, CharP.cast_eq_zero, lt_self_iff_false,
not_nonempty_iff_eq_empty.1 h'] at this
/- use Rusza covering lemma to cover `A` by few translates of `A ∩ (H + {x₀}) - A ∩ (H + {x₀})`
(which is contained in `H`). The number of translates is at most
`#(A + (A ∩ (H + {x₀}))) / #(A ∩ (H + {x₀}))`, where the numerator is controlled as this is
a subset of `A + A`, and the denominator is bounded below by the previous inequality`. -/
rcases Set.exists_subset_add_sub (toFinite A) (toFinite (A ∩ ((H + {x₀} : Set G)))) Hne with
⟨u, hu, Au, -⟩
have Iu : Nat.card u ≤ K ^ (13/2) * (Nat.card A) ^ (1/2) * (Nat.card (H : Set G)) ^ (-1/2) := by
have : (0 : ℝ) ≤ Nat.card u := by simp
have Z1 := mul_le_mul_of_nonneg_left J this
have Z2 : (Nat.card u * Nat.card (A ∩ (H + {x₀}) : Set G) : ℝ)
≤ Nat.card (A + A ∩ (↑H + {x₀})) := by norm_cast
have Z3 : (Nat.card (A + A ∩ (↑H + {x₀})) : ℝ) ≤ K * Nat.card A := by
apply le_trans _ hA
simp only [Nat.cast_le]
apply Nat.card_mono (toFinite _)
apply add_subset_add_left (inter_subset_left _ _)
have : 0 ≤ K ^ (11/2) * Nat.card A ^ (-1/2) * Nat.card (H : Set G) ^ (-1/2) := by positivity
have T := mul_le_mul_of_nonneg_left ((Z1.trans Z2).trans Z3) this
convert T using 1 <;> rpow_ring <;> norm_num
have A_subset_uH : A ⊆ u + H := by
rw [add_sub_assoc] at Au
refine Au.trans $ add_subset_add_left $
(sub_subset_sub (inter_subset_right ..) (inter_subset_right ..)).trans ?_
rw [add_sub_add_comm, singleton_sub_singleton, sub_self]
simp
exact ⟨H, u, Iu, IHA, IAH, A_subset_uH⟩
/-- The polynomial Freiman-Ruzsa (PFR) conjecture: if $A$ is a subset of an elementary abelian
2-group of doubling constant at most $K$, then $A$ can be covered by at most $2K^{12}$ cosets of
a subgroup of cardinality at most $|A|$. -/
theorem PFR_conjecture (h₀A : A.Nonempty) (hA : Nat.card (A + A) ≤ K * Nat.card A) :
∃ (H : AddSubgroup G) (c : Set G),
Nat.card c < 2 * K ^ 12 ∧ Nat.card H ≤ Nat.card A ∧ A ⊆ c + H := by
obtain ⟨A_pos, -, K_pos⟩ : (0 : ℝ) < Nat.card A ∧ (0 : ℝ) < Nat.card (A + A) ∧ 0 < K :=
PFR_conjecture_pos_aux' h₀A hA
-- consider the subgroup `H` given by Lemma `PFR_conjecture_aux`.
obtain ⟨H, c, hc, IHA, IAH, A_subs_cH⟩ : ∃ (H : AddSubgroup G) (c : Set G),
Nat.card c ≤ K ^ (13/2) * (Nat.card A) ^ (1/2) * (Nat.card (H : Set G)) ^ (-1/2)
∧ Nat.card (H : Set G) ≤ K ^ 11 * Nat.card A ∧ Nat.card A ≤ K ^ 11 * Nat.card (H : Set G)
∧ A ⊆ c + H :=
PFR_conjecture_aux h₀A hA
have H_pos : (0 : ℝ) < Nat.card (H : Set G) := by
have : 0 < Nat.card (H : Set G) := Nat.card_pos; positivity
rcases le_or_lt (Nat.card (H : Set G)) (Nat.card A) with h|h
-- If `#H ≤ #A`, then `H` satisfies the conclusion of the theorem
· refine ⟨H, c, ?_, h, A_subs_cH⟩
calc
Nat.card c ≤ K ^ (13/2) * (Nat.card A) ^ (1/2) * (Nat.card (H : Set G)) ^ (-1/2) := hc
_ ≤ K ^ (13/2) * (K ^ 11 * Nat.card (H : Set G)) ^ (1/2) * (Nat.card (H : Set G)) ^ (-1/2) := by
gcongr
_ = K ^ 12 := by rpow_ring; norm_num
_ < 2 * K ^ 12 := by linarith [show 0 < K ^ 12 by positivity]
-- otherwise, we decompose `H` into cosets of one of its subgroups `H'`, chosen so that
-- `#A / 2 < #H' ≤ #A`. This `H'` satisfies the desired conclusion.
· obtain ⟨H', IH'A, IAH', H'H⟩ : ∃ H' : AddSubgroup G, Nat.card (H' : Set G) ≤ Nat.card A
∧ Nat.card A < 2 * Nat.card (H' : Set G) ∧ H' ≤ H := by
have A_pos' : 0 < Nat.card A := mod_cast A_pos
exact ElementaryAddCommGroup.exists_subgroup_subset_card_le Nat.prime_two H h.le A_pos'.ne'
have : (Nat.card A / 2 : ℝ) < Nat.card (H' : Set G) := by
rw [div_lt_iff zero_lt_two, mul_comm]; norm_cast
have H'_pos : (0 : ℝ) < Nat.card (H' : Set G) := by
have : 0 < Nat.card (H' : Set G) := Nat.card_pos; positivity
obtain ⟨u, HH'u, hu⟩ := AddSubgroup.exists_left_transversal_of_le H'H
refine ⟨H', c + u, ?_, IH'A, by rwa [add_assoc, HH'u]⟩
calc
(Nat.card (c + u) : ℝ)
≤ Nat.card c * Nat.card u := mod_cast card_add_le
_ ≤ (K ^ (13/2) * (Nat.card A) ^ (1 / 2) * (Nat.card (H : Set G) ^ (-1 / 2)))
* (Nat.card (H : Set G) / Nat.card (H' : Set G)) := by
gcongr
apply le_of_eq
rw [eq_div_iff H'_pos.ne']
norm_cast
_ < (K ^ (13/2) * (Nat.card A) ^ (1 / 2) * (Nat.card (H : Set G) ^ (-1 / 2)))
* (Nat.card (H : Set G) / (Nat.card A / 2)) := by
gcongr
_ = 2 * K ^ (13/2) * (Nat.card A) ^ (-1/2) * (Nat.card (H : Set G)) ^ (1/2) := by
have : (0 : ℝ) < Nat.card H := H_pos
field_simp
rpow_ring
norm_num
_ ≤ 2 * K ^ (13/2) * (Nat.card A) ^ (-1/2) * (K ^ 11 * Nat.card A) ^ (1/2) := by
gcongr
_ = 2 * K ^ 12 := by
rpow_ring
norm_num
/-- Corollary of `PFR_conjecture` in which the ambient group is not required to be finite (but) then
$H$ and $c$ are finite. -/
| theorem PFR_conjecture' {G : Type*} [AddCommGroup G] [ElementaryAddCommGroup G 2]
{A : Set G} {K : ℝ} (h₀A : A.Nonempty) (Afin : A.Finite)
(hA : Nat.card (A + A) ≤ K * Nat.card A) :
∃ (H : AddSubgroup G) (c : Set G), c.Finite ∧ (H : Set G).Finite ∧
Nat.card c < 2 * K ^ 12 ∧ Nat.card H ≤ Nat.card A ∧ A ⊆ c + H | PFR_conjecture' | 516205a 20231114 | 12e0125 20231127 | pfr/PFR/Main.lean | {
"lineInFile": 340,
"tokenPositionInFile": 17499,
"theoremPositionInFile": 9
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n let G' := AddSubgroup.closure A\n let G'fin : Fintype G' := by\n exact Finite.fintype (ElementaryAddCommGroup.finite_closure Afin)\n have G'Elem : ElementaryAddCommGroup G' 2 := ElementaryAddCommGroup.subgroup _\n let ι : G'→+ G := G'.subtype\n have ι_inj : Injective ι := AddSubgroup.subtype_injective G'\n let A' : Set G' := ι ⁻¹' A\n have A_rg : A ⊆ range ι := by\n simp only [AddSubgroup.coeSubtype, Subtype.range_coe_subtype, SetLike.mem_coe, G', ι]\n exact AddSubgroup.subset_closure\n have cardA' : Nat.card A' = Nat.card A := Nat.card_preimage_of_injective ι_inj A_rg\n have hA' : Nat.card (A' + A') ≤ K * Nat.card A' := by\n rwa [cardA', ← preimage_add _ ι_inj A_rg A_rg,\n Nat.card_preimage_of_injective ι_inj (add_subset_range _ A_rg A_rg)]\n rcases PFR_conjecture (h₀A.preimage' A_rg) hA' with ⟨H', c', hc', hH', hH'₂⟩\n refine ⟨AddSubgroup.map ι H', ι '' c', toFinite _, toFinite (ι '' H'), ?_, ?_, fun x hx ↦ ?_⟩\n · rwa [Nat.card_image_of_injective ι_inj]\n · erw [Nat.card_image_of_injective ι_inj, ← cardA']\n exact hH'\n · erw [← image_add]\n exact ⟨⟨x, AddSubgroup.subset_closure hx⟩, hH'₂ hx, rfl⟩",
"proofType": "tactic",
"proofLengthLines": 22,
"proofLengthTokens": 1141
} | pfr |
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Quotient
import Mathlib.GroupTheory.Torsion
import Mathlib.GroupTheory.Torsion
import Mathlib.LinearAlgebra.FreeModule.PID
import PFR.Mathlib.Data.Set.Pointwise.SMul
import PFR.EntropyPFR
import PFR.ImprovedPFR
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Mathlib.GroupTheory.Torsion
/-!
# Weak PFR over the integers
Here we use the entropic form of PFR to deduce a weak form of PFR over the integers.
## Main statement
* `weak_PFR_int`: Let $A\subseteq \mathbb{Z}^d$ and $\lvert A+A\rvert\leq K\lvert A\rvert$.
There exists $A'\subseteq A$ such that $\lvert A'\rvert \geq K^{-17}\lvert A\rvert$ and
$\dim A' \leq (40/\log 2)\log K$.
-/
section AddCommGroup
variable {G : Type*} [AddCommGroup G] {A B : Set G}
open Set
open scoped Pointwise
def IsShift (A B : Set G) : Prop := ∃ x : G, A = x +ᵥ B
| lemma IsShift.sub_self_congr : IsShift A B → A - A = B - B | IsShift.sub_self_congr | 25309ad 20231211 | c0c547a 20240116 | pfr/PFR/WeakPFR.lean | {
"lineInFile": 33,
"tokenPositionInFile": 881,
"theoremPositionInFile": 1
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n rintro ⟨x, rfl⟩; simp [vadd_sub_vadd_comm, singleton_zero]",
"proofType": "tactic",
"proofLengthLines": 2,
"proofLengthTokens": 63
} | pfr |
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Quotient
import Mathlib.GroupTheory.Torsion
import Mathlib.GroupTheory.Torsion
import Mathlib.LinearAlgebra.FreeModule.PID
import PFR.Mathlib.Data.Set.Pointwise.SMul
import PFR.EntropyPFR
import PFR.ImprovedPFR
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Mathlib.GroupTheory.Torsion
/-!
# Weak PFR over the integers
Here we use the entropic form of PFR to deduce a weak form of PFR over the integers.
## Main statement
* `weak_PFR_int`: Let $A\subseteq \mathbb{Z}^d$ and $\lvert A+A\rvert\leq K\lvert A\rvert$.
There exists $A'\subseteq A$ such that $\lvert A'\rvert \geq K^{-17}\lvert A\rvert$ and
$\dim A' \leq (40/\log 2)\log K$.
-/
section AddCommGroup
variable {G : Type*} [AddCommGroup G] {A B : Set G}
open Set
open scoped Pointwise
def IsShift (A B : Set G) : Prop := ∃ x : G, A = x +ᵥ B
lemma IsShift.sub_self_congr : IsShift A B → A - A = B - B := by
rintro ⟨x, rfl⟩; simp [vadd_sub_vadd_comm, singleton_zero]
| lemma IsShift.card_congr : IsShift A B → Nat.card A = Nat.card B | IsShift.card_congr | 25309ad 20231211 | c0c547a 20240116 | pfr/PFR/WeakPFR.lean | {
"lineInFile": 36,
"tokenPositionInFile": 1008,
"theoremPositionInFile": 2
} | {
"inFilePremises": true,
"repositoryPremises": false
} | {
"hasProof": true,
"proof": "by rintro ⟨x, rfl⟩; simp",
"proofType": "tactic",
"proofLengthLines": 1,
"proofLengthTokens": 24
} | pfr |
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Quotient
import Mathlib.GroupTheory.Torsion
import Mathlib.GroupTheory.Torsion
import Mathlib.LinearAlgebra.FreeModule.PID
import PFR.Mathlib.Data.Set.Pointwise.SMul
import PFR.EntropyPFR
import PFR.ImprovedPFR
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Mathlib.GroupTheory.Torsion
/-!
# Weak PFR over the integers
Here we use the entropic form of PFR to deduce a weak form of PFR over the integers.
## Main statement
* `weak_PFR_int`: Let $A\subseteq \mathbb{Z}^d$ and $\lvert A+A\rvert\leq K\lvert A\rvert$.
There exists $A'\subseteq A$ such that $\lvert A'\rvert \geq K^{-17}\lvert A\rvert$ and
$\dim A' \leq (40/\log 2)\log K$.
-/
section AddCommGroup
variable {G : Type*} [AddCommGroup G] {A B : Set G}
open Set
open scoped Pointwise
def IsShift (A B : Set G) : Prop := ∃ x : G, A = x +ᵥ B
lemma IsShift.sub_self_congr : IsShift A B → A - A = B - B := by
rintro ⟨x, rfl⟩; simp [vadd_sub_vadd_comm, singleton_zero]
lemma IsShift.card_congr : IsShift A B → Nat.card A = Nat.card B := by rintro ⟨x, rfl⟩; simp
/-- The property of two sets A, B of a group G not being contained in cosets of the same proper
subgroup -/
def NotInCoset (A B : Set G) : Prop := AddSubgroup.closure ((A - A) ∪ (B - B)) = ⊤
/-- Without loss of generality, one can move (up to translation and embedding) any pair A, B of non-empty sets into a subgroup where they are not in a coset. -/
| lemma wlog_notInCoset (hA : A.Nonempty) (hB : B.Nonempty) :
∃ (G' : AddSubgroup G) (A' B' : Set G'), IsShift A A' ∧ IsShift B B' ∧ NotInCoset A' B' | wlog_notInCoset | 25309ad 20231211 | c0c547a 20240116 | pfr/PFR/WeakPFR.lean | {
"lineInFile": 43,
"tokenPositionInFile": 1455,
"theoremPositionInFile": 4
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n obtain ⟨x, hx⟩ := hA\n obtain ⟨y, hy⟩ := hB\n set G' := AddSubgroup.closure ((A - A) ∪ (B - B))\n set A' : Set G' := (↑) ⁻¹' ((-x) +ᵥ A)\n set B' : Set G' := (↑) ⁻¹' ((-y) +ᵥ B)\n have hxA : -x +ᵥ A ⊆ range ((↑) : G' → G) := by\n simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,\n Subtype.range_coe_subtype, SetLike.mem_coe]\n exact (sub_subset_sub_left $ singleton_subset_iff.2 hx).trans $ (subset_union_left ..).trans\n AddSubgroup.subset_closure\n have hyB : -y +ᵥ B ⊆ range ((↑) : G' → G) := by\n simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,\n Subtype.range_coe_subtype, SetLike.mem_coe]\n exact (sub_subset_sub_left $ singleton_subset_iff.2 hy).trans $ (subset_union_right ..).trans\n AddSubgroup.subset_closure\n have hA : IsShift A A' := ⟨x, by rw [Set.image_preimage_eq_of_subset hxA, vadd_neg_vadd]⟩\n have hB : IsShift B B' := ⟨y, by rw [Set.image_preimage_eq_of_subset hyB, vadd_neg_vadd]⟩\n refine ⟨G', A', B', hA, hB, ?_⟩\n unfold NotInCoset\n convert AddSubgroup.closure_preimage_eq_top ((A - A) ∪ (B - B))\n simp_rw [preimage_union, hA.sub_self_congr, hB.sub_self_congr]\n rw [preimage_sub, preimage_sub]\n simp [A', B', preimage_image_preimage]\n all_goals apply_rules [Subtype.coe_injective, (image_preimage_subset ..).trans, hxA, hyB]",
"proofType": "tactic",
"proofLengthLines": 25,
"proofLengthTokens": 1355
} | pfr |
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Quotient
import Mathlib.GroupTheory.Torsion
import Mathlib.GroupTheory.Torsion
import Mathlib.LinearAlgebra.FreeModule.PID
import PFR.Mathlib.Data.Set.Pointwise.SMul
import PFR.EntropyPFR
import PFR.ImprovedPFR
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Mathlib.GroupTheory.Torsion
/-!
# Weak PFR over the integers
Here we use the entropic form of PFR to deduce a weak form of PFR over the integers.
## Main statement
* `weak_PFR_int`: Let $A\subseteq \mathbb{Z}^d$ and $\lvert A+A\rvert\leq K\lvert A\rvert$.
There exists $A'\subseteq A$ such that $\lvert A'\rvert \geq K^{-17}\lvert A\rvert$ and
$\dim A' \leq (40/\log 2)\log K$.
-/
section AddCommGroup
variable {G : Type*} [AddCommGroup G] {A B : Set G}
open Set
open scoped Pointwise
def IsShift (A B : Set G) : Prop := ∃ x : G, A = x +ᵥ B
lemma IsShift.sub_self_congr : IsShift A B → A - A = B - B := by
rintro ⟨x, rfl⟩; simp [vadd_sub_vadd_comm, singleton_zero]
lemma IsShift.card_congr : IsShift A B → Nat.card A = Nat.card B := by rintro ⟨x, rfl⟩; simp
/-- The property of two sets A, B of a group G not being contained in cosets of the same proper
subgroup -/
def NotInCoset (A B : Set G) : Prop := AddSubgroup.closure ((A - A) ∪ (B - B)) = ⊤
/-- Without loss of generality, one can move (up to translation and embedding) any pair A, B of non-empty sets into a subgroup where they are not in a coset. -/
lemma wlog_notInCoset (hA : A.Nonempty) (hB : B.Nonempty) :
∃ (G' : AddSubgroup G) (A' B' : Set G'), IsShift A A' ∧ IsShift B B' ∧ NotInCoset A' B' := by
obtain ⟨x, hx⟩ := hA
obtain ⟨y, hy⟩ := hB
set G' := AddSubgroup.closure ((A - A) ∪ (B - B))
set A' : Set G' := (↑) ⁻¹' ((-x) +ᵥ A)
set B' : Set G' := (↑) ⁻¹' ((-y) +ᵥ B)
have hxA : -x +ᵥ A ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hx).trans $ (subset_union_left ..).trans
AddSubgroup.subset_closure
have hyB : -y +ᵥ B ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hy).trans $ (subset_union_right ..).trans
AddSubgroup.subset_closure
have hA : IsShift A A' := ⟨x, by rw [Set.image_preimage_eq_of_subset hxA, vadd_neg_vadd]⟩
have hB : IsShift B B' := ⟨y, by rw [Set.image_preimage_eq_of_subset hyB, vadd_neg_vadd]⟩
refine ⟨G', A', B', hA, hB, ?_⟩
unfold NotInCoset
convert AddSubgroup.closure_preimage_eq_top ((A - A) ∪ (B - B))
simp_rw [preimage_union, hA.sub_self_congr, hB.sub_self_congr]
rw [preimage_sub, preimage_sub]
simp [A', B', preimage_image_preimage]
all_goals apply_rules [Subtype.coe_injective, (image_preimage_subset ..).trans, hxA, hyB]
end AddCommGroup
section Torsion
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [MeasurableSpace G] [MeasurableSingletonClass G]
[Countable G] {Ω Ω' : Type u} [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ': Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
/-- If $G$ is torsion-free and $X,Y$ are $G$-valued random variables then $d[X;2Y]\leq 5d[X;Y]$. -/
| lemma torsion_free_doubling [FiniteRange X] [FiniteRange Y]
(hX : Measurable X) (hY : Measurable Y) (hG : AddMonoid.IsTorsionFree G) :
d[X ; μ # (Y + Y) ; μ'] ≤ 5 * d[X; μ # Y ; μ'] | torsion_free_doubling | 25309ad 20231211 | 1226201 20240103 | pfr/PFR/WeakPFR.lean | {
"lineInFile": 82,
"tokenPositionInFile": 3455,
"theoremPositionInFile": 5
} | {
"inFilePremises": false,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n obtain ⟨A, mA, μA, X', Y'₁, Y'₂, hμA, h_indep, hX'_meas, hY'₁_meas, hY'₂_meas, hX'_ident,\n hY'₁_ident, hY'₂_ident, _, _, _⟩ := independent_copies3_nondep_finiteRange hX hY hY μ μ' μ'\n have h_meas (i : Fin 3) : Measurable (![X', Y'₁, Y'₂] i) := by fin_cases i <;> assumption\n haveI : NoZeroSMulDivisors ℕ G := hG.noZeroNsmulDivisors\n have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc\n H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] := by\n let f : G × G × G → G × G × G := fun ⟨x, y₁, y₂⟩ ↦ (x, y₁ - y₂, x - 2 • y₁)\n show H[f ∘ ⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] = _\n refine entropy_comp_of_injective μA ?_ f ?_\n · exact Measurable.prod hX'_meas <| Measurable.prod hY'₁_meas hY'₂_meas\n · exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all [smul_right_inj]\n _ = H[X ; μ] + 2 * H[Y ; μ'] := by\n have : IndepFun X' (prod Y'₁ Y'₂) μA := Indep.symm <|\n h_indep.indepFun_prod_mk h_meas 1 2 0 (by decide) (by decide)\n rw [this.entropy_pair_eq_add hX'_meas (by exact Measurable.prod hY'₁_meas hY'₂_meas),\n IndepFun.entropy_pair_eq_add hY'₁_meas hY'₂_meas (h_indep.indepFun (show 1 ≠ 2 by decide)),\n hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, two_mul]\n have : H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[X ; μ] + H[Y ; μ'] := calc\n H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[⟨X', Y'₁⟩ ; μA] := by\n let f : G × G → G × G := fun ⟨x, y₁⟩ ↦ (x, x - 2 • y₁)\n show H[f ∘ ⟨X', Y'₁⟩ ; μA] = _\n apply entropy_comp_of_injective μA (by exact Measurable.prod hX'_meas hY'₁_meas) f\n exact fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all [smul_right_inj]\n _ = H[X ; μ] + H[Y ; μ'] := by\n rw [IndepFun.entropy_pair_eq_add hX'_meas hY'₁_meas (h_indep.indepFun (show 0 ≠ 1 by decide)),\n hX'_ident.entropy_eq, hY'₁_ident.entropy_eq]\n let f : G × G → G × G := fun ⟨x, y⟩ ↦ (x, y - x)\n have hf : f.Injective := fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all\n have : H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] := calc\n H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] = H[f ∘ ⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by\n show _ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂ - (Y'₁ - Y'₂)⟩ ; μA]\n rw [sub_sub_sub_cancel_right, ← sub_add_eq_sub_sub, two_nsmul]\n _ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by\n refine entropy_comp_of_injective μA (Measurable.prod ?_ ?_) f hf\n · exact Measurable.sub hY'₁_meas hY'₂_meas\n · exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas\n _ ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] :=\n entropy_pair_le_add (hY'₁_meas.sub' hY'₂_meas) (hX'_meas.sub' hY'₁_meas |>.sub' hY'₂_meas) μA\n have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] + H[X' - 2 • Y'₁ ; μA] ≤\n H[⟨X', X' - 2 • Y'₁⟩ ; μA] + H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] := by\n haveI : FiniteRange (Y'₁ - Y'₂) := FiniteRange.sub Y'₁ Y'₂\n haveI : FiniteRange (2 • Y'₁) := by show FiniteRange ((fun x ↦ 2 • x) ∘ Y'₁); infer_instance\n apply entropy_triple_add_entropy_le μA hX'_meas (Measurable.sub hY'₁_meas hY'₂_meas)\n exact Measurable.sub' hX'_meas <| Measurable.const_smul hY'₁_meas 2\n have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc\n H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] := by\n let f : G × G × G → G × G × G := fun ⟨y₁, y₂, x⟩ ↦ (y₁, y₂, x - y₁ - y₂)\n show H[f ∘ ⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA]\n refine entropy_comp_of_injective μA ?_ f ?_\n · exact Measurable.prod hY'₁_meas <| Measurable.prod hY'₂_meas hX'_meas\n · exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all\n _ = H[X ; μ] + 2 * H[Y ; μ'] := by\n have : IndepFun Y'₁ (prod Y'₂ X') μA := Indep.symm <|\n h_indep.indepFun_prod_mk h_meas 2 0 1 (by decide) (by decide)\n rw [this.entropy_pair_eq_add hY'₁_meas (by exact Measurable.prod hY'₂_meas hX'_meas),\n IndepFun.entropy_pair_eq_add hY'₂_meas hX'_meas (h_indep.indepFun (show 2 ≠ 0 by decide)),\n hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq]\n group\n have : H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₂ ; μA] := calc\n H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₁, X' - Y'₂⟩ ; μA] := by rw [sub_right_comm] ; rfl\n _ = H[⟨Y'₁, X' - Y'₂⟩ ; μA] := entropy_comp_of_injective μA\n (by exact Measurable.prod hY'₁_meas <| Measurable.sub hX'_meas hY'₂_meas) f hf\n _ = H[Y ; μ'] + H[X' - Y'₂ ; μA] := by\n haveI : FiniteRange (X' - Y'₂) := FiniteRange.sub X' Y'₂\n convert IndepFun.entropy_pair_eq_add hY'₁_meas (hX'_meas.sub hY'₂_meas)\n <| h_indep.indepFun_sub_right h_meas 1 0 2 (by decide) (by decide)\n exact hY'₁_ident.entropy_eq.symm\n have : H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₁ ; μA] := calc\n H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₂, X' - Y'₁⟩ ; μA] := rfl\n _ = H[⟨Y'₂, X' - Y'₁⟩ ; μA] := entropy_comp_of_injective μA\n (by exact Measurable.prod hY'₂_meas <| Measurable.sub hX'_meas hY'₁_meas) f hf\n _ = H[Y ; μ'] + H[X' - Y'₁ ; μA] := by\n haveI : FiniteRange (X' - Y'₁) := FiniteRange.sub X' Y'₁\n convert IndepFun.entropy_pair_eq_add hY'₂_meas (hX'_meas.sub hY'₁_meas)\n <| h_indep.indepFun_sub_right h_meas 2 0 1 (by decide) (by decide)\n exact hY'₂_ident.entropy_eq.symm\n have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] ≤\n H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] + H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by\n apply entropy_triple_add_entropy_le μA hY'₁_meas hY'₂_meas\n exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas\n have : H[X' - Y'₁ - Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := calc\n H[X' - Y'₁ - Y'₂ ; μA] ≤ H[X' - Y'₁ ; μA] + H[X' - Y'₂ ; μA] - H[X ; μ] := by linarith\n _ = 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := by\n nth_rw 1 [two_mul, ← hX'_ident.rdist_eq hY'₁_ident, ← hX'_ident.rdist_eq hY'₂_ident]\n have h1 : d[X' ; μA # Y'₁ ; μA] = H[X' - Y'₁ ; μA] - H[X' ; μA] / 2 - H[Y'₁ ; μA] / 2 :=\n (h_indep.indepFun (show 0 ≠ 1 by decide)).rdist_eq hX'_meas hY'₁_meas\n have h2 : d[X' ; μA # Y'₂ ; μA] = H[X' - Y'₂ ; μA] - H[X' ; μA] / 2 - H[Y'₂ ; μA] / 2 :=\n (h_indep.indepFun (show 0 ≠ 2 by decide)).rdist_eq hX'_meas hY'₂_meas\n rw [h1, h2, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, hX'_ident.entropy_eq]\n group\n have : d[X ; μ # 2 • Y ; μ'] ≤\n d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := calc\n d[X ; μ # 2 • Y ; μ'] = H[X' - 2 • Y'₁ ; μA] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by\n have h2Y_ident : IdentDistrib (2 • Y'₁) (2 • Y) (μ := μA) (ν := μ') := by\n convert hY'₁_ident.comp <| measurable_discrete <| fun g ↦ 2 • g\n have h2Y_indep : IndepFun X' (2 • Y'₁) (μ := μA) := by\n convert (h_indep.indepFun (show 0 ≠ 1 by decide)).comp measurable_id\n (measurable_const_smul 2)\n rw [← hX'_ident.rdist_eq h2Y_ident,\n h2Y_indep.rdist_eq hX'_meas <| Measurable.const_smul hY'₁_meas 2,\n hX'_ident.entropy_eq, h2Y_ident.entropy_eq]\n _ ≤ H[Y'₁ - Y'₂ ; μA] + 2 * d[X ; μ # Y ; μ'] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by linarith\n _ = d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := by\n have H2Y : H[2 • Y ; μ'] = H[Y ; μ'] := by\n let f (g : G) := 2 • g\n exact entropy_comp_of_injective μ' hY f (fun _ _ ↦ by simp [f, smul_right_inj])\n have : d[Y'₁ ; μA # Y'₂ ; μA] = H[Y'₁ - Y'₂ ; μA] - H[Y'₁ ; μA] / 2 - H[Y'₂ ; μA] / 2 :=\n (h_indep.indepFun (show 1 ≠ 2 by decide)).rdist_eq hY'₁_meas hY'₂_meas\n rw [this, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, H2Y]\n group\n have : d[Y'₁ ; μA # Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] := by\n rw [two_mul]\n convert rdist_triangle hY'₁_meas hX'_meas hY'₂_meas (μ := μA) (μ' := μA) (μ'' := μA)\n · exact rdist_symm.trans (hY'₁_ident.rdist_eq hX'_ident).symm\n · exact (hX'_ident.rdist_eq hY'₂_ident).symm\n rw [← two_nsmul]\n linarith [abs_le.mp <| diff_ent_le_rdist hX hY (μ := μ) (μ' := μ')]",
"proofType": "tactic",
"proofLengthLines": 118,
"proofLengthTokens": 8122
} | pfr |
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Quotient
import Mathlib.GroupTheory.Torsion
import Mathlib.GroupTheory.Torsion
import Mathlib.LinearAlgebra.FreeModule.PID
import PFR.Mathlib.Data.Set.Pointwise.SMul
import PFR.EntropyPFR
import PFR.ImprovedPFR
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Mathlib.GroupTheory.Torsion
/-!
# Weak PFR over the integers
Here we use the entropic form of PFR to deduce a weak form of PFR over the integers.
## Main statement
* `weak_PFR_int`: Let $A\subseteq \mathbb{Z}^d$ and $\lvert A+A\rvert\leq K\lvert A\rvert$.
There exists $A'\subseteq A$ such that $\lvert A'\rvert \geq K^{-17}\lvert A\rvert$ and
$\dim A' \leq (40/\log 2)\log K$.
-/
section AddCommGroup
variable {G : Type*} [AddCommGroup G] {A B : Set G}
open Set
open scoped Pointwise
def IsShift (A B : Set G) : Prop := ∃ x : G, A = x +ᵥ B
lemma IsShift.sub_self_congr : IsShift A B → A - A = B - B := by
rintro ⟨x, rfl⟩; simp [vadd_sub_vadd_comm, singleton_zero]
lemma IsShift.card_congr : IsShift A B → Nat.card A = Nat.card B := by rintro ⟨x, rfl⟩; simp
/-- The property of two sets A, B of a group G not being contained in cosets of the same proper
subgroup -/
def NotInCoset (A B : Set G) : Prop := AddSubgroup.closure ((A - A) ∪ (B - B)) = ⊤
/-- Without loss of generality, one can move (up to translation and embedding) any pair A, B of non-empty sets into a subgroup where they are not in a coset. -/
lemma wlog_notInCoset (hA : A.Nonempty) (hB : B.Nonempty) :
∃ (G' : AddSubgroup G) (A' B' : Set G'), IsShift A A' ∧ IsShift B B' ∧ NotInCoset A' B' := by
obtain ⟨x, hx⟩ := hA
obtain ⟨y, hy⟩ := hB
set G' := AddSubgroup.closure ((A - A) ∪ (B - B))
set A' : Set G' := (↑) ⁻¹' ((-x) +ᵥ A)
set B' : Set G' := (↑) ⁻¹' ((-y) +ᵥ B)
have hxA : -x +ᵥ A ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hx).trans $ (subset_union_left ..).trans
AddSubgroup.subset_closure
have hyB : -y +ᵥ B ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hy).trans $ (subset_union_right ..).trans
AddSubgroup.subset_closure
have hA : IsShift A A' := ⟨x, by rw [Set.image_preimage_eq_of_subset hxA, vadd_neg_vadd]⟩
have hB : IsShift B B' := ⟨y, by rw [Set.image_preimage_eq_of_subset hyB, vadd_neg_vadd]⟩
refine ⟨G', A', B', hA, hB, ?_⟩
unfold NotInCoset
convert AddSubgroup.closure_preimage_eq_top ((A - A) ∪ (B - B))
simp_rw [preimage_union, hA.sub_self_congr, hB.sub_self_congr]
rw [preimage_sub, preimage_sub]
simp [A', B', preimage_image_preimage]
all_goals apply_rules [Subtype.coe_injective, (image_preimage_subset ..).trans, hxA, hyB]
end AddCommGroup
section Torsion
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [MeasurableSpace G] [MeasurableSingletonClass G]
[Countable G] {Ω Ω' : Type u} [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ': Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
/-- If $G$ is torsion-free and $X,Y$ are $G$-valued random variables then $d[X;2Y]\leq 5d[X;Y]$. -/
lemma torsion_free_doubling [FiniteRange X] [FiniteRange Y]
(hX : Measurable X) (hY : Measurable Y) (hG : AddMonoid.IsTorsionFree G) :
d[X ; μ # (Y + Y) ; μ'] ≤ 5 * d[X; μ # Y ; μ'] := by
obtain ⟨A, mA, μA, X', Y'₁, Y'₂, hμA, h_indep, hX'_meas, hY'₁_meas, hY'₂_meas, hX'_ident,
hY'₁_ident, hY'₂_ident, _, _, _⟩ := independent_copies3_nondep_finiteRange hX hY hY μ μ' μ'
have h_meas (i : Fin 3) : Measurable (![X', Y'₁, Y'₂] i) := by fin_cases i <;> assumption
haveI : NoZeroSMulDivisors ℕ G := hG.noZeroNsmulDivisors
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨x, y₁, y₂⟩ ↦ (x, y₁ - y₂, x - 2 • y₁)
show H[f ∘ ⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] = _
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hX'_meas <| Measurable.prod hY'₁_meas hY'₂_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun X' (prod Y'₁ Y'₂) μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 1 2 0 (by decide) (by decide)
rw [this.entropy_pair_eq_add hX'_meas (by exact Measurable.prod hY'₁_meas hY'₂_meas),
IndepFun.entropy_pair_eq_add hY'₁_meas hY'₂_meas (h_indep.indepFun (show 1 ≠ 2 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, two_mul]
have : H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[X ; μ] + H[Y ; μ'] := calc
H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[⟨X', Y'₁⟩ ; μA] := by
let f : G × G → G × G := fun ⟨x, y₁⟩ ↦ (x, x - 2 • y₁)
show H[f ∘ ⟨X', Y'₁⟩ ; μA] = _
apply entropy_comp_of_injective μA (by exact Measurable.prod hX'_meas hY'₁_meas) f
exact fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + H[Y ; μ'] := by
rw [IndepFun.entropy_pair_eq_add hX'_meas hY'₁_meas (h_indep.indepFun (show 0 ≠ 1 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq]
let f : G × G → G × G := fun ⟨x, y⟩ ↦ (x, y - x)
have hf : f.Injective := fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all
have : H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] := calc
H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] = H[f ∘ ⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
show _ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂ - (Y'₁ - Y'₂)⟩ ; μA]
rw [sub_sub_sub_cancel_right, ← sub_add_eq_sub_sub, two_nsmul]
_ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
refine entropy_comp_of_injective μA (Measurable.prod ?_ ?_) f hf
· exact Measurable.sub hY'₁_meas hY'₂_meas
· exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
_ ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] :=
entropy_pair_le_add (hY'₁_meas.sub' hY'₂_meas) (hX'_meas.sub' hY'₁_meas |>.sub' hY'₂_meas) μA
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] + H[X' - 2 • Y'₁ ; μA] ≤
H[⟨X', X' - 2 • Y'₁⟩ ; μA] + H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] := by
haveI : FiniteRange (Y'₁ - Y'₂) := FiniteRange.sub Y'₁ Y'₂
haveI : FiniteRange (2 • Y'₁) := by show FiniteRange ((fun x ↦ 2 • x) ∘ Y'₁); infer_instance
apply entropy_triple_add_entropy_le μA hX'_meas (Measurable.sub hY'₁_meas hY'₂_meas)
exact Measurable.sub' hX'_meas <| Measurable.const_smul hY'₁_meas 2
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨y₁, y₂, x⟩ ↦ (y₁, y₂, x - y₁ - y₂)
show H[f ∘ ⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA]
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hY'₁_meas <| Measurable.prod hY'₂_meas hX'_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun Y'₁ (prod Y'₂ X') μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 2 0 1 (by decide) (by decide)
rw [this.entropy_pair_eq_add hY'₁_meas (by exact Measurable.prod hY'₂_meas hX'_meas),
IndepFun.entropy_pair_eq_add hY'₂_meas hX'_meas (h_indep.indepFun (show 2 ≠ 0 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq]
group
have : H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₂ ; μA] := calc
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₁, X' - Y'₂⟩ ; μA] := by rw [sub_right_comm] ; rfl
_ = H[⟨Y'₁, X' - Y'₂⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₁_meas <| Measurable.sub hX'_meas hY'₂_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₂ ; μA] := by
haveI : FiniteRange (X' - Y'₂) := FiniteRange.sub X' Y'₂
convert IndepFun.entropy_pair_eq_add hY'₁_meas (hX'_meas.sub hY'₂_meas)
<| h_indep.indepFun_sub_right h_meas 1 0 2 (by decide) (by decide)
exact hY'₁_ident.entropy_eq.symm
have : H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₁ ; μA] := calc
H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₂, X' - Y'₁⟩ ; μA] := rfl
_ = H[⟨Y'₂, X' - Y'₁⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₂_meas <| Measurable.sub hX'_meas hY'₁_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₁ ; μA] := by
haveI : FiniteRange (X' - Y'₁) := FiniteRange.sub X' Y'₁
convert IndepFun.entropy_pair_eq_add hY'₂_meas (hX'_meas.sub hY'₁_meas)
<| h_indep.indepFun_sub_right h_meas 2 0 1 (by decide) (by decide)
exact hY'₂_ident.entropy_eq.symm
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] ≤
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] + H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
apply entropy_triple_add_entropy_le μA hY'₁_meas hY'₂_meas
exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
have : H[X' - Y'₁ - Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := calc
H[X' - Y'₁ - Y'₂ ; μA] ≤ H[X' - Y'₁ ; μA] + H[X' - Y'₂ ; μA] - H[X ; μ] := by linarith
_ = 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := by
nth_rw 1 [two_mul, ← hX'_ident.rdist_eq hY'₁_ident, ← hX'_ident.rdist_eq hY'₂_ident]
have h1 : d[X' ; μA # Y'₁ ; μA] = H[X' - Y'₁ ; μA] - H[X' ; μA] / 2 - H[Y'₁ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 1 by decide)).rdist_eq hX'_meas hY'₁_meas
have h2 : d[X' ; μA # Y'₂ ; μA] = H[X' - Y'₂ ; μA] - H[X' ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 2 by decide)).rdist_eq hX'_meas hY'₂_meas
rw [h1, h2, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, hX'_ident.entropy_eq]
group
have : d[X ; μ # 2 • Y ; μ'] ≤
d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := calc
d[X ; μ # 2 • Y ; μ'] = H[X' - 2 • Y'₁ ; μA] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by
have h2Y_ident : IdentDistrib (2 • Y'₁) (2 • Y) (μ := μA) (ν := μ') := by
convert hY'₁_ident.comp <| measurable_discrete <| fun g ↦ 2 • g
have h2Y_indep : IndepFun X' (2 • Y'₁) (μ := μA) := by
convert (h_indep.indepFun (show 0 ≠ 1 by decide)).comp measurable_id
(measurable_const_smul 2)
rw [← hX'_ident.rdist_eq h2Y_ident,
h2Y_indep.rdist_eq hX'_meas <| Measurable.const_smul hY'₁_meas 2,
hX'_ident.entropy_eq, h2Y_ident.entropy_eq]
_ ≤ H[Y'₁ - Y'₂ ; μA] + 2 * d[X ; μ # Y ; μ'] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by linarith
_ = d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := by
have H2Y : H[2 • Y ; μ'] = H[Y ; μ'] := by
let f (g : G) := 2 • g
exact entropy_comp_of_injective μ' hY f (fun _ _ ↦ by simp [f, smul_right_inj])
have : d[Y'₁ ; μA # Y'₂ ; μA] = H[Y'₁ - Y'₂ ; μA] - H[Y'₁ ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 1 ≠ 2 by decide)).rdist_eq hY'₁_meas hY'₂_meas
rw [this, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, H2Y]
group
have : d[Y'₁ ; μA # Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] := by
rw [two_mul]
convert rdist_triangle hY'₁_meas hX'_meas hY'₂_meas (μ := μA) (μ' := μA) (μ'' := μA)
· exact rdist_symm.trans (hY'₁_ident.rdist_eq hX'_ident).symm
· exact (hX'_ident.rdist_eq hY'₂_ident).symm
rw [← two_nsmul]
linarith [abs_le.mp <| diff_ent_le_rdist hX hY (μ := μ) (μ' := μ')]
/-- If $G$ is a torsion-free group and $X,Y$ are $G$-valued random variables and
$\phi : G\to \mathbb{F}_2^d$ is a homomorphism then
\[\mathbb{H}(\phi(X))\leq 10d[X;Y].\] -/
| lemma torsion_dist_shrinking {H : Type u} [FiniteRange X] [FiniteRange Y] (hX : Measurable X)
(hY : Measurable Y) [AddCommGroup H] [ElementaryAddCommGroup H 2]
[MeasurableSpace H] [MeasurableSingletonClass H] [Countable H]
(hG : AddMonoid.IsTorsionFree G) (φ : G →+ H) :
H[φ ∘ X ; μ] ≤ 10 * d[X; μ # Y ; μ'] | torsion_dist_shrinking | 25309ad 20231211 | 22c3a7e 20240105 | pfr/PFR/WeakPFR.lean | {
"lineInFile": 206,
"tokenPositionInFile": 11946,
"theoremPositionInFile": 6
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n have :=\n calc d[φ ∘ X ; μ # φ ∘ (Y + Y); μ'] ≤ d[X; μ # (Y + Y) ; μ'] := rdist_of_hom_le φ hX (Measurable.add hY hY)\n _ ≤ 5 * d[X; μ # Y ; μ'] := torsion_free_doubling X Y μ μ' hX hY hG\n have eq_zero : φ ∘ (Y + Y) = fun _ ↦ 0 := by ext x ; simp only [Function.comp_apply, Pi.add_apply,\n map_add, ElementaryAddCommGroup.add_self]\n rwa [eq_zero, rdist_zero_eq_half_ent, div_le_iff zero_lt_two, mul_assoc, mul_comm _ 2, ←mul_assoc,\n show (5*2 : ℝ) = 10 by norm_num] at this",
"proofType": "tactic",
"proofLengthLines": 8,
"proofLengthTokens": 489
} | pfr |
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Quotient
import Mathlib.GroupTheory.Torsion
import Mathlib.GroupTheory.Torsion
import Mathlib.LinearAlgebra.FreeModule.PID
import PFR.Mathlib.Data.Set.Pointwise.SMul
import PFR.EntropyPFR
import PFR.ImprovedPFR
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Mathlib.GroupTheory.Torsion
/-!
# Weak PFR over the integers
Here we use the entropic form of PFR to deduce a weak form of PFR over the integers.
## Main statement
* `weak_PFR_int`: Let $A\subseteq \mathbb{Z}^d$ and $\lvert A+A\rvert\leq K\lvert A\rvert$.
There exists $A'\subseteq A$ such that $\lvert A'\rvert \geq K^{-17}\lvert A\rvert$ and
$\dim A' \leq (40/\log 2)\log K$.
-/
section AddCommGroup
variable {G : Type*} [AddCommGroup G] {A B : Set G}
open Set
open scoped Pointwise
def IsShift (A B : Set G) : Prop := ∃ x : G, A = x +ᵥ B
lemma IsShift.sub_self_congr : IsShift A B → A - A = B - B := by
rintro ⟨x, rfl⟩; simp [vadd_sub_vadd_comm, singleton_zero]
lemma IsShift.card_congr : IsShift A B → Nat.card A = Nat.card B := by rintro ⟨x, rfl⟩; simp
/-- The property of two sets A, B of a group G not being contained in cosets of the same proper
subgroup -/
def NotInCoset (A B : Set G) : Prop := AddSubgroup.closure ((A - A) ∪ (B - B)) = ⊤
/-- Without loss of generality, one can move (up to translation and embedding) any pair A, B of non-empty sets into a subgroup where they are not in a coset. -/
lemma wlog_notInCoset (hA : A.Nonempty) (hB : B.Nonempty) :
∃ (G' : AddSubgroup G) (A' B' : Set G'), IsShift A A' ∧ IsShift B B' ∧ NotInCoset A' B' := by
obtain ⟨x, hx⟩ := hA
obtain ⟨y, hy⟩ := hB
set G' := AddSubgroup.closure ((A - A) ∪ (B - B))
set A' : Set G' := (↑) ⁻¹' ((-x) +ᵥ A)
set B' : Set G' := (↑) ⁻¹' ((-y) +ᵥ B)
have hxA : -x +ᵥ A ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hx).trans $ (subset_union_left ..).trans
AddSubgroup.subset_closure
have hyB : -y +ᵥ B ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hy).trans $ (subset_union_right ..).trans
AddSubgroup.subset_closure
have hA : IsShift A A' := ⟨x, by rw [Set.image_preimage_eq_of_subset hxA, vadd_neg_vadd]⟩
have hB : IsShift B B' := ⟨y, by rw [Set.image_preimage_eq_of_subset hyB, vadd_neg_vadd]⟩
refine ⟨G', A', B', hA, hB, ?_⟩
unfold NotInCoset
convert AddSubgroup.closure_preimage_eq_top ((A - A) ∪ (B - B))
simp_rw [preimage_union, hA.sub_self_congr, hB.sub_self_congr]
rw [preimage_sub, preimage_sub]
simp [A', B', preimage_image_preimage]
all_goals apply_rules [Subtype.coe_injective, (image_preimage_subset ..).trans, hxA, hyB]
end AddCommGroup
section Torsion
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [MeasurableSpace G] [MeasurableSingletonClass G]
[Countable G] {Ω Ω' : Type u} [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ': Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
/-- If $G$ is torsion-free and $X,Y$ are $G$-valued random variables then $d[X;2Y]\leq 5d[X;Y]$. -/
lemma torsion_free_doubling [FiniteRange X] [FiniteRange Y]
(hX : Measurable X) (hY : Measurable Y) (hG : AddMonoid.IsTorsionFree G) :
d[X ; μ # (Y + Y) ; μ'] ≤ 5 * d[X; μ # Y ; μ'] := by
obtain ⟨A, mA, μA, X', Y'₁, Y'₂, hμA, h_indep, hX'_meas, hY'₁_meas, hY'₂_meas, hX'_ident,
hY'₁_ident, hY'₂_ident, _, _, _⟩ := independent_copies3_nondep_finiteRange hX hY hY μ μ' μ'
have h_meas (i : Fin 3) : Measurable (![X', Y'₁, Y'₂] i) := by fin_cases i <;> assumption
haveI : NoZeroSMulDivisors ℕ G := hG.noZeroNsmulDivisors
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨x, y₁, y₂⟩ ↦ (x, y₁ - y₂, x - 2 • y₁)
show H[f ∘ ⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] = _
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hX'_meas <| Measurable.prod hY'₁_meas hY'₂_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun X' (prod Y'₁ Y'₂) μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 1 2 0 (by decide) (by decide)
rw [this.entropy_pair_eq_add hX'_meas (by exact Measurable.prod hY'₁_meas hY'₂_meas),
IndepFun.entropy_pair_eq_add hY'₁_meas hY'₂_meas (h_indep.indepFun (show 1 ≠ 2 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, two_mul]
have : H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[X ; μ] + H[Y ; μ'] := calc
H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[⟨X', Y'₁⟩ ; μA] := by
let f : G × G → G × G := fun ⟨x, y₁⟩ ↦ (x, x - 2 • y₁)
show H[f ∘ ⟨X', Y'₁⟩ ; μA] = _
apply entropy_comp_of_injective μA (by exact Measurable.prod hX'_meas hY'₁_meas) f
exact fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + H[Y ; μ'] := by
rw [IndepFun.entropy_pair_eq_add hX'_meas hY'₁_meas (h_indep.indepFun (show 0 ≠ 1 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq]
let f : G × G → G × G := fun ⟨x, y⟩ ↦ (x, y - x)
have hf : f.Injective := fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all
have : H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] := calc
H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] = H[f ∘ ⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
show _ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂ - (Y'₁ - Y'₂)⟩ ; μA]
rw [sub_sub_sub_cancel_right, ← sub_add_eq_sub_sub, two_nsmul]
_ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
refine entropy_comp_of_injective μA (Measurable.prod ?_ ?_) f hf
· exact Measurable.sub hY'₁_meas hY'₂_meas
· exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
_ ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] :=
entropy_pair_le_add (hY'₁_meas.sub' hY'₂_meas) (hX'_meas.sub' hY'₁_meas |>.sub' hY'₂_meas) μA
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] + H[X' - 2 • Y'₁ ; μA] ≤
H[⟨X', X' - 2 • Y'₁⟩ ; μA] + H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] := by
haveI : FiniteRange (Y'₁ - Y'₂) := FiniteRange.sub Y'₁ Y'₂
haveI : FiniteRange (2 • Y'₁) := by show FiniteRange ((fun x ↦ 2 • x) ∘ Y'₁); infer_instance
apply entropy_triple_add_entropy_le μA hX'_meas (Measurable.sub hY'₁_meas hY'₂_meas)
exact Measurable.sub' hX'_meas <| Measurable.const_smul hY'₁_meas 2
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨y₁, y₂, x⟩ ↦ (y₁, y₂, x - y₁ - y₂)
show H[f ∘ ⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA]
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hY'₁_meas <| Measurable.prod hY'₂_meas hX'_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun Y'₁ (prod Y'₂ X') μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 2 0 1 (by decide) (by decide)
rw [this.entropy_pair_eq_add hY'₁_meas (by exact Measurable.prod hY'₂_meas hX'_meas),
IndepFun.entropy_pair_eq_add hY'₂_meas hX'_meas (h_indep.indepFun (show 2 ≠ 0 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq]
group
have : H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₂ ; μA] := calc
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₁, X' - Y'₂⟩ ; μA] := by rw [sub_right_comm] ; rfl
_ = H[⟨Y'₁, X' - Y'₂⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₁_meas <| Measurable.sub hX'_meas hY'₂_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₂ ; μA] := by
haveI : FiniteRange (X' - Y'₂) := FiniteRange.sub X' Y'₂
convert IndepFun.entropy_pair_eq_add hY'₁_meas (hX'_meas.sub hY'₂_meas)
<| h_indep.indepFun_sub_right h_meas 1 0 2 (by decide) (by decide)
exact hY'₁_ident.entropy_eq.symm
have : H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₁ ; μA] := calc
H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₂, X' - Y'₁⟩ ; μA] := rfl
_ = H[⟨Y'₂, X' - Y'₁⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₂_meas <| Measurable.sub hX'_meas hY'₁_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₁ ; μA] := by
haveI : FiniteRange (X' - Y'₁) := FiniteRange.sub X' Y'₁
convert IndepFun.entropy_pair_eq_add hY'₂_meas (hX'_meas.sub hY'₁_meas)
<| h_indep.indepFun_sub_right h_meas 2 0 1 (by decide) (by decide)
exact hY'₂_ident.entropy_eq.symm
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] ≤
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] + H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
apply entropy_triple_add_entropy_le μA hY'₁_meas hY'₂_meas
exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
have : H[X' - Y'₁ - Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := calc
H[X' - Y'₁ - Y'₂ ; μA] ≤ H[X' - Y'₁ ; μA] + H[X' - Y'₂ ; μA] - H[X ; μ] := by linarith
_ = 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := by
nth_rw 1 [two_mul, ← hX'_ident.rdist_eq hY'₁_ident, ← hX'_ident.rdist_eq hY'₂_ident]
have h1 : d[X' ; μA # Y'₁ ; μA] = H[X' - Y'₁ ; μA] - H[X' ; μA] / 2 - H[Y'₁ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 1 by decide)).rdist_eq hX'_meas hY'₁_meas
have h2 : d[X' ; μA # Y'₂ ; μA] = H[X' - Y'₂ ; μA] - H[X' ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 2 by decide)).rdist_eq hX'_meas hY'₂_meas
rw [h1, h2, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, hX'_ident.entropy_eq]
group
have : d[X ; μ # 2 • Y ; μ'] ≤
d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := calc
d[X ; μ # 2 • Y ; μ'] = H[X' - 2 • Y'₁ ; μA] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by
have h2Y_ident : IdentDistrib (2 • Y'₁) (2 • Y) (μ := μA) (ν := μ') := by
convert hY'₁_ident.comp <| measurable_discrete <| fun g ↦ 2 • g
have h2Y_indep : IndepFun X' (2 • Y'₁) (μ := μA) := by
convert (h_indep.indepFun (show 0 ≠ 1 by decide)).comp measurable_id
(measurable_const_smul 2)
rw [← hX'_ident.rdist_eq h2Y_ident,
h2Y_indep.rdist_eq hX'_meas <| Measurable.const_smul hY'₁_meas 2,
hX'_ident.entropy_eq, h2Y_ident.entropy_eq]
_ ≤ H[Y'₁ - Y'₂ ; μA] + 2 * d[X ; μ # Y ; μ'] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by linarith
_ = d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := by
have H2Y : H[2 • Y ; μ'] = H[Y ; μ'] := by
let f (g : G) := 2 • g
exact entropy_comp_of_injective μ' hY f (fun _ _ ↦ by simp [f, smul_right_inj])
have : d[Y'₁ ; μA # Y'₂ ; μA] = H[Y'₁ - Y'₂ ; μA] - H[Y'₁ ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 1 ≠ 2 by decide)).rdist_eq hY'₁_meas hY'₂_meas
rw [this, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, H2Y]
group
have : d[Y'₁ ; μA # Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] := by
rw [two_mul]
convert rdist_triangle hY'₁_meas hX'_meas hY'₂_meas (μ := μA) (μ' := μA) (μ'' := μA)
· exact rdist_symm.trans (hY'₁_ident.rdist_eq hX'_ident).symm
· exact (hX'_ident.rdist_eq hY'₂_ident).symm
rw [← two_nsmul]
linarith [abs_le.mp <| diff_ent_le_rdist hX hY (μ := μ) (μ' := μ')]
/-- If $G$ is a torsion-free group and $X,Y$ are $G$-valued random variables and
$\phi : G\to \mathbb{F}_2^d$ is a homomorphism then
\[\mathbb{H}(\phi(X))\leq 10d[X;Y].\] -/
lemma torsion_dist_shrinking {H : Type u} [FiniteRange X] [FiniteRange Y] (hX : Measurable X)
(hY : Measurable Y) [AddCommGroup H] [ElementaryAddCommGroup H 2]
[MeasurableSpace H] [MeasurableSingletonClass H] [Countable H]
(hG : AddMonoid.IsTorsionFree G) (φ : G →+ H) :
H[φ ∘ X ; μ] ≤ 10 * d[X; μ # Y ; μ'] := by
have :=
calc d[φ ∘ X ; μ # φ ∘ (Y + Y); μ'] ≤ d[X; μ # (Y + Y) ; μ'] := rdist_of_hom_le φ hX (Measurable.add hY hY)
_ ≤ 5 * d[X; μ # Y ; μ'] := torsion_free_doubling X Y μ μ' hX hY hG
have eq_zero : φ ∘ (Y + Y) = fun _ ↦ 0 := by ext x ; simp only [Function.comp_apply, Pi.add_apply,
map_add, ElementaryAddCommGroup.add_self]
rwa [eq_zero, rdist_zero_eq_half_ent, div_le_iff zero_lt_two, mul_assoc, mul_comm _ 2, ←mul_assoc,
show (5*2 : ℝ) = 10 by norm_num] at this
end Torsion
| instance {G : Type u} [AddCommGroup G] [Fintype G] [MeasurableSpace G] [MeasurableSingletonClass G] (H : AddSubgroup G)
: MeasurableSingletonClass (G ⧸ H) | null | 25309ad 20231211 | 9275a21 20240110 | pfr/PFR/WeakPFR.lean | {
"lineInFile": 221,
"tokenPositionInFile": 12769,
"theoremPositionInFile": 7
} | {
"inFilePremises": false,
"repositoryPremises": false
} | {
"hasProof": true,
"proof": "⟨λ _ ↦ by { rw [measurableSet_quotient]; simp [measurableSet_discrete] }⟩",
"proofType": "term",
"proofLengthLines": 1,
"proofLengthTokens": 73
} | pfr |
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Quotient
import Mathlib.GroupTheory.Torsion
import Mathlib.GroupTheory.Torsion
import Mathlib.LinearAlgebra.FreeModule.PID
import PFR.Mathlib.Data.Set.Pointwise.SMul
import PFR.EntropyPFR
import PFR.ImprovedPFR
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Mathlib.GroupTheory.Torsion
/-!
# Weak PFR over the integers
Here we use the entropic form of PFR to deduce a weak form of PFR over the integers.
## Main statement
* `weak_PFR_int`: Let $A\subseteq \mathbb{Z}^d$ and $\lvert A+A\rvert\leq K\lvert A\rvert$.
There exists $A'\subseteq A$ such that $\lvert A'\rvert \geq K^{-17}\lvert A\rvert$ and
$\dim A' \leq (40/\log 2)\log K$.
-/
section AddCommGroup
variable {G : Type*} [AddCommGroup G] {A B : Set G}
open Set
open scoped Pointwise
def IsShift (A B : Set G) : Prop := ∃ x : G, A = x +ᵥ B
lemma IsShift.sub_self_congr : IsShift A B → A - A = B - B := by
rintro ⟨x, rfl⟩; simp [vadd_sub_vadd_comm, singleton_zero]
lemma IsShift.card_congr : IsShift A B → Nat.card A = Nat.card B := by rintro ⟨x, rfl⟩; simp
/-- The property of two sets A, B of a group G not being contained in cosets of the same proper
subgroup -/
def NotInCoset (A B : Set G) : Prop := AddSubgroup.closure ((A - A) ∪ (B - B)) = ⊤
/-- Without loss of generality, one can move (up to translation and embedding) any pair A, B of non-empty sets into a subgroup where they are not in a coset. -/
lemma wlog_notInCoset (hA : A.Nonempty) (hB : B.Nonempty) :
∃ (G' : AddSubgroup G) (A' B' : Set G'), IsShift A A' ∧ IsShift B B' ∧ NotInCoset A' B' := by
obtain ⟨x, hx⟩ := hA
obtain ⟨y, hy⟩ := hB
set G' := AddSubgroup.closure ((A - A) ∪ (B - B))
set A' : Set G' := (↑) ⁻¹' ((-x) +ᵥ A)
set B' : Set G' := (↑) ⁻¹' ((-y) +ᵥ B)
have hxA : -x +ᵥ A ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hx).trans $ (subset_union_left ..).trans
AddSubgroup.subset_closure
have hyB : -y +ᵥ B ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hy).trans $ (subset_union_right ..).trans
AddSubgroup.subset_closure
have hA : IsShift A A' := ⟨x, by rw [Set.image_preimage_eq_of_subset hxA, vadd_neg_vadd]⟩
have hB : IsShift B B' := ⟨y, by rw [Set.image_preimage_eq_of_subset hyB, vadd_neg_vadd]⟩
refine ⟨G', A', B', hA, hB, ?_⟩
unfold NotInCoset
convert AddSubgroup.closure_preimage_eq_top ((A - A) ∪ (B - B))
simp_rw [preimage_union, hA.sub_self_congr, hB.sub_self_congr]
rw [preimage_sub, preimage_sub]
simp [A', B', preimage_image_preimage]
all_goals apply_rules [Subtype.coe_injective, (image_preimage_subset ..).trans, hxA, hyB]
end AddCommGroup
section Torsion
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [MeasurableSpace G] [MeasurableSingletonClass G]
[Countable G] {Ω Ω' : Type u} [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ': Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
/-- If $G$ is torsion-free and $X,Y$ are $G$-valued random variables then $d[X;2Y]\leq 5d[X;Y]$. -/
lemma torsion_free_doubling [FiniteRange X] [FiniteRange Y]
(hX : Measurable X) (hY : Measurable Y) (hG : AddMonoid.IsTorsionFree G) :
d[X ; μ # (Y + Y) ; μ'] ≤ 5 * d[X; μ # Y ; μ'] := by
obtain ⟨A, mA, μA, X', Y'₁, Y'₂, hμA, h_indep, hX'_meas, hY'₁_meas, hY'₂_meas, hX'_ident,
hY'₁_ident, hY'₂_ident, _, _, _⟩ := independent_copies3_nondep_finiteRange hX hY hY μ μ' μ'
have h_meas (i : Fin 3) : Measurable (![X', Y'₁, Y'₂] i) := by fin_cases i <;> assumption
haveI : NoZeroSMulDivisors ℕ G := hG.noZeroNsmulDivisors
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨x, y₁, y₂⟩ ↦ (x, y₁ - y₂, x - 2 • y₁)
show H[f ∘ ⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] = _
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hX'_meas <| Measurable.prod hY'₁_meas hY'₂_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun X' (prod Y'₁ Y'₂) μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 1 2 0 (by decide) (by decide)
rw [this.entropy_pair_eq_add hX'_meas (by exact Measurable.prod hY'₁_meas hY'₂_meas),
IndepFun.entropy_pair_eq_add hY'₁_meas hY'₂_meas (h_indep.indepFun (show 1 ≠ 2 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, two_mul]
have : H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[X ; μ] + H[Y ; μ'] := calc
H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[⟨X', Y'₁⟩ ; μA] := by
let f : G × G → G × G := fun ⟨x, y₁⟩ ↦ (x, x - 2 • y₁)
show H[f ∘ ⟨X', Y'₁⟩ ; μA] = _
apply entropy_comp_of_injective μA (by exact Measurable.prod hX'_meas hY'₁_meas) f
exact fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + H[Y ; μ'] := by
rw [IndepFun.entropy_pair_eq_add hX'_meas hY'₁_meas (h_indep.indepFun (show 0 ≠ 1 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq]
let f : G × G → G × G := fun ⟨x, y⟩ ↦ (x, y - x)
have hf : f.Injective := fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all
have : H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] := calc
H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] = H[f ∘ ⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
show _ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂ - (Y'₁ - Y'₂)⟩ ; μA]
rw [sub_sub_sub_cancel_right, ← sub_add_eq_sub_sub, two_nsmul]
_ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
refine entropy_comp_of_injective μA (Measurable.prod ?_ ?_) f hf
· exact Measurable.sub hY'₁_meas hY'₂_meas
· exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
_ ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] :=
entropy_pair_le_add (hY'₁_meas.sub' hY'₂_meas) (hX'_meas.sub' hY'₁_meas |>.sub' hY'₂_meas) μA
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] + H[X' - 2 • Y'₁ ; μA] ≤
H[⟨X', X' - 2 • Y'₁⟩ ; μA] + H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] := by
haveI : FiniteRange (Y'₁ - Y'₂) := FiniteRange.sub Y'₁ Y'₂
haveI : FiniteRange (2 • Y'₁) := by show FiniteRange ((fun x ↦ 2 • x) ∘ Y'₁); infer_instance
apply entropy_triple_add_entropy_le μA hX'_meas (Measurable.sub hY'₁_meas hY'₂_meas)
exact Measurable.sub' hX'_meas <| Measurable.const_smul hY'₁_meas 2
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨y₁, y₂, x⟩ ↦ (y₁, y₂, x - y₁ - y₂)
show H[f ∘ ⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA]
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hY'₁_meas <| Measurable.prod hY'₂_meas hX'_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun Y'₁ (prod Y'₂ X') μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 2 0 1 (by decide) (by decide)
rw [this.entropy_pair_eq_add hY'₁_meas (by exact Measurable.prod hY'₂_meas hX'_meas),
IndepFun.entropy_pair_eq_add hY'₂_meas hX'_meas (h_indep.indepFun (show 2 ≠ 0 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq]
group
have : H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₂ ; μA] := calc
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₁, X' - Y'₂⟩ ; μA] := by rw [sub_right_comm] ; rfl
_ = H[⟨Y'₁, X' - Y'₂⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₁_meas <| Measurable.sub hX'_meas hY'₂_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₂ ; μA] := by
haveI : FiniteRange (X' - Y'₂) := FiniteRange.sub X' Y'₂
convert IndepFun.entropy_pair_eq_add hY'₁_meas (hX'_meas.sub hY'₂_meas)
<| h_indep.indepFun_sub_right h_meas 1 0 2 (by decide) (by decide)
exact hY'₁_ident.entropy_eq.symm
have : H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₁ ; μA] := calc
H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₂, X' - Y'₁⟩ ; μA] := rfl
_ = H[⟨Y'₂, X' - Y'₁⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₂_meas <| Measurable.sub hX'_meas hY'₁_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₁ ; μA] := by
haveI : FiniteRange (X' - Y'₁) := FiniteRange.sub X' Y'₁
convert IndepFun.entropy_pair_eq_add hY'₂_meas (hX'_meas.sub hY'₁_meas)
<| h_indep.indepFun_sub_right h_meas 2 0 1 (by decide) (by decide)
exact hY'₂_ident.entropy_eq.symm
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] ≤
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] + H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
apply entropy_triple_add_entropy_le μA hY'₁_meas hY'₂_meas
exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
have : H[X' - Y'₁ - Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := calc
H[X' - Y'₁ - Y'₂ ; μA] ≤ H[X' - Y'₁ ; μA] + H[X' - Y'₂ ; μA] - H[X ; μ] := by linarith
_ = 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := by
nth_rw 1 [two_mul, ← hX'_ident.rdist_eq hY'₁_ident, ← hX'_ident.rdist_eq hY'₂_ident]
have h1 : d[X' ; μA # Y'₁ ; μA] = H[X' - Y'₁ ; μA] - H[X' ; μA] / 2 - H[Y'₁ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 1 by decide)).rdist_eq hX'_meas hY'₁_meas
have h2 : d[X' ; μA # Y'₂ ; μA] = H[X' - Y'₂ ; μA] - H[X' ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 2 by decide)).rdist_eq hX'_meas hY'₂_meas
rw [h1, h2, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, hX'_ident.entropy_eq]
group
have : d[X ; μ # 2 • Y ; μ'] ≤
d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := calc
d[X ; μ # 2 • Y ; μ'] = H[X' - 2 • Y'₁ ; μA] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by
have h2Y_ident : IdentDistrib (2 • Y'₁) (2 • Y) (μ := μA) (ν := μ') := by
convert hY'₁_ident.comp <| measurable_discrete <| fun g ↦ 2 • g
have h2Y_indep : IndepFun X' (2 • Y'₁) (μ := μA) := by
convert (h_indep.indepFun (show 0 ≠ 1 by decide)).comp measurable_id
(measurable_const_smul 2)
rw [← hX'_ident.rdist_eq h2Y_ident,
h2Y_indep.rdist_eq hX'_meas <| Measurable.const_smul hY'₁_meas 2,
hX'_ident.entropy_eq, h2Y_ident.entropy_eq]
_ ≤ H[Y'₁ - Y'₂ ; μA] + 2 * d[X ; μ # Y ; μ'] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by linarith
_ = d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := by
have H2Y : H[2 • Y ; μ'] = H[Y ; μ'] := by
let f (g : G) := 2 • g
exact entropy_comp_of_injective μ' hY f (fun _ _ ↦ by simp [f, smul_right_inj])
have : d[Y'₁ ; μA # Y'₂ ; μA] = H[Y'₁ - Y'₂ ; μA] - H[Y'₁ ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 1 ≠ 2 by decide)).rdist_eq hY'₁_meas hY'₂_meas
rw [this, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, H2Y]
group
have : d[Y'₁ ; μA # Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] := by
rw [two_mul]
convert rdist_triangle hY'₁_meas hX'_meas hY'₂_meas (μ := μA) (μ' := μA) (μ'' := μA)
· exact rdist_symm.trans (hY'₁_ident.rdist_eq hX'_ident).symm
· exact (hX'_ident.rdist_eq hY'₂_ident).symm
rw [← two_nsmul]
linarith [abs_le.mp <| diff_ent_le_rdist hX hY (μ := μ) (μ' := μ')]
/-- If $G$ is a torsion-free group and $X,Y$ are $G$-valued random variables and
$\phi : G\to \mathbb{F}_2^d$ is a homomorphism then
\[\mathbb{H}(\phi(X))\leq 10d[X;Y].\] -/
lemma torsion_dist_shrinking {H : Type u} [FiniteRange X] [FiniteRange Y] (hX : Measurable X)
(hY : Measurable Y) [AddCommGroup H] [ElementaryAddCommGroup H 2]
[MeasurableSpace H] [MeasurableSingletonClass H] [Countable H]
(hG : AddMonoid.IsTorsionFree G) (φ : G →+ H) :
H[φ ∘ X ; μ] ≤ 10 * d[X; μ # Y ; μ'] := by
have :=
calc d[φ ∘ X ; μ # φ ∘ (Y + Y); μ'] ≤ d[X; μ # (Y + Y) ; μ'] := rdist_of_hom_le φ hX (Measurable.add hY hY)
_ ≤ 5 * d[X; μ # Y ; μ'] := torsion_free_doubling X Y μ μ' hX hY hG
have eq_zero : φ ∘ (Y + Y) = fun _ ↦ 0 := by ext x ; simp only [Function.comp_apply, Pi.add_apply,
map_add, ElementaryAddCommGroup.add_self]
rwa [eq_zero, rdist_zero_eq_half_ent, div_le_iff zero_lt_two, mul_assoc, mul_comm _ 2, ←mul_assoc,
show (5*2 : ℝ) = 10 by norm_num] at this
end Torsion
instance {G : Type u} [AddCommGroup G] [Fintype G] [MeasurableSpace G] [MeasurableSingletonClass G] (H : AddSubgroup G)
: MeasurableSingletonClass (G ⧸ H) :=
⟨λ _ ↦ by { rw [measurableSet_quotient]; simp [measurableSet_discrete] }⟩
section F2_projection
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [ElementaryAddCommGroup G 2] [Fintype G] [MeasurableSpace G]
[MeasurableSingletonClass G] {Ω Ω' : Type*}
/-- Let $G=\mathbb{F}_2^n$ and $X,Y$ be $G$-valued random variables such that
\[\mathbb{H}(X)+\mathbb{H}(Y)> (20/\alpha) d[X;Y],\]
for some $\alpha > 0$.
There is a non-trivial subgroup $H\leq G$ such that
\[\log \lvert H\rvert <(1+\alpha)/2 (\mathbb{H}(X)+\mathbb{H}(Y))\] and
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))< \alpha (\mathbb{H}(X)+\mathbb{H}(Y))\]
where $\psi:G\to G/H$ is the natural projection homomorphism.
-/
| lemma app_ent_PFR' [MeasureSpace Ω] [MeasureSpace Ω'] (X : Ω → G) (Y : Ω' → G)
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
{α : ℝ} (hent : 20 * d[X # Y] < α * (H[X] + H[Y])) (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X] + H[Y]) ∧
H[(QuotientAddGroup.mk' H) ∘ X] + H[(QuotientAddGroup.mk' H) ∘ Y] < α * (H[X] + H[Y]) | app_ent_PFR' | 25309ad 20231211 | 9275a21 20240110 | pfr/PFR/WeakPFR.lean | {
"lineInFile": 240,
"tokenPositionInFile": 13644,
"theoremPositionInFile": 8
} | {
"inFilePremises": false,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n let p : refPackage Ω Ω' G := {\n X₀₁ := X\n X₀₂ := Y\n hmeas1 := hX\n hmeas2 := hY\n η := 1/8\n hη := by norm_num\n hη' := by norm_num }\n obtain ⟨H, Ω'', hΩ'', U, _, hUmeas, hUunif, ineq⟩ := entropic_PFR_conjecture_improv p rfl\n let ψ := (QuotientAddGroup.mk' H)\n use H\n haveI : Finite H := Subtype.finite\n -- Note that H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y]\n have ent_le : H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y] := calc\n H[ψ ∘ X] + H[ψ ∘ Y] ≤ 2 * d[X # U] + 2 * d[Y # U] := by\n gcongr\n · exact ent_of_proj_le hX hUmeas hUunif\n · exact ent_of_proj_le hY hUmeas hUunif\n _ = 2 * (d[X # U] + d[Y # U]) := by ring\n _ ≤ 2 * (10 * d[X # Y]) := by gcongr\n _ = 20 * d[X # Y] := by ring\n -- Note that (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y]\n have log_sub_le : (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y] := calc\n (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) =\n (H[U] - H[X]) + (H[U] - H[Y]) := by\n rw [IsUniform.entropy_eq' hUunif hUmeas, SetLike.coe_sort_coe]\n _ ≤ |(H[U] - H[X])| + |(H[U] - H[Y])| := by gcongr <;> exact le_abs_self _\n _ ≤ 2 * d[X # U] + 2 * d[Y # U] := by\n gcongr\n · rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hX\n · rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hY\n _ = 2 * (d[X # U] + d[Y # U]) := by ring\n _ ≤ 2 * (10 * d[X # Y]) := by gcongr\n _ = 20 * d[X # Y] := by ring\n -- then the conclusion follows from the assumption `hent` and basic inequality manipulations\n exact ⟨by linarith, by linarith⟩",
"proofType": "tactic",
"proofLengthLines": 37,
"proofLengthTokens": 1581
} | pfr |
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Quotient
import Mathlib.GroupTheory.Torsion
import Mathlib.GroupTheory.Torsion
import Mathlib.LinearAlgebra.FreeModule.PID
import PFR.Mathlib.Data.Set.Pointwise.SMul
import PFR.EntropyPFR
import PFR.ImprovedPFR
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Mathlib.GroupTheory.Torsion
/-!
# Weak PFR over the integers
Here we use the entropic form of PFR to deduce a weak form of PFR over the integers.
## Main statement
* `weak_PFR_int`: Let $A\subseteq \mathbb{Z}^d$ and $\lvert A+A\rvert\leq K\lvert A\rvert$.
There exists $A'\subseteq A$ such that $\lvert A'\rvert \geq K^{-17}\lvert A\rvert$ and
$\dim A' \leq (40/\log 2)\log K$.
-/
section AddCommGroup
variable {G : Type*} [AddCommGroup G] {A B : Set G}
open Set
open scoped Pointwise
def IsShift (A B : Set G) : Prop := ∃ x : G, A = x +ᵥ B
lemma IsShift.sub_self_congr : IsShift A B → A - A = B - B := by
rintro ⟨x, rfl⟩; simp [vadd_sub_vadd_comm, singleton_zero]
lemma IsShift.card_congr : IsShift A B → Nat.card A = Nat.card B := by rintro ⟨x, rfl⟩; simp
/-- The property of two sets A, B of a group G not being contained in cosets of the same proper
subgroup -/
def NotInCoset (A B : Set G) : Prop := AddSubgroup.closure ((A - A) ∪ (B - B)) = ⊤
/-- Without loss of generality, one can move (up to translation and embedding) any pair A, B of non-empty sets into a subgroup where they are not in a coset. -/
lemma wlog_notInCoset (hA : A.Nonempty) (hB : B.Nonempty) :
∃ (G' : AddSubgroup G) (A' B' : Set G'), IsShift A A' ∧ IsShift B B' ∧ NotInCoset A' B' := by
obtain ⟨x, hx⟩ := hA
obtain ⟨y, hy⟩ := hB
set G' := AddSubgroup.closure ((A - A) ∪ (B - B))
set A' : Set G' := (↑) ⁻¹' ((-x) +ᵥ A)
set B' : Set G' := (↑) ⁻¹' ((-y) +ᵥ B)
have hxA : -x +ᵥ A ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hx).trans $ (subset_union_left ..).trans
AddSubgroup.subset_closure
have hyB : -y +ᵥ B ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hy).trans $ (subset_union_right ..).trans
AddSubgroup.subset_closure
have hA : IsShift A A' := ⟨x, by rw [Set.image_preimage_eq_of_subset hxA, vadd_neg_vadd]⟩
have hB : IsShift B B' := ⟨y, by rw [Set.image_preimage_eq_of_subset hyB, vadd_neg_vadd]⟩
refine ⟨G', A', B', hA, hB, ?_⟩
unfold NotInCoset
convert AddSubgroup.closure_preimage_eq_top ((A - A) ∪ (B - B))
simp_rw [preimage_union, hA.sub_self_congr, hB.sub_self_congr]
rw [preimage_sub, preimage_sub]
simp [A', B', preimage_image_preimage]
all_goals apply_rules [Subtype.coe_injective, (image_preimage_subset ..).trans, hxA, hyB]
end AddCommGroup
section Torsion
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [MeasurableSpace G] [MeasurableSingletonClass G]
[Countable G] {Ω Ω' : Type u} [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ': Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
/-- If $G$ is torsion-free and $X,Y$ are $G$-valued random variables then $d[X;2Y]\leq 5d[X;Y]$. -/
lemma torsion_free_doubling [FiniteRange X] [FiniteRange Y]
(hX : Measurable X) (hY : Measurable Y) (hG : AddMonoid.IsTorsionFree G) :
d[X ; μ # (Y + Y) ; μ'] ≤ 5 * d[X; μ # Y ; μ'] := by
obtain ⟨A, mA, μA, X', Y'₁, Y'₂, hμA, h_indep, hX'_meas, hY'₁_meas, hY'₂_meas, hX'_ident,
hY'₁_ident, hY'₂_ident, _, _, _⟩ := independent_copies3_nondep_finiteRange hX hY hY μ μ' μ'
have h_meas (i : Fin 3) : Measurable (![X', Y'₁, Y'₂] i) := by fin_cases i <;> assumption
haveI : NoZeroSMulDivisors ℕ G := hG.noZeroNsmulDivisors
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨x, y₁, y₂⟩ ↦ (x, y₁ - y₂, x - 2 • y₁)
show H[f ∘ ⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] = _
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hX'_meas <| Measurable.prod hY'₁_meas hY'₂_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun X' (prod Y'₁ Y'₂) μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 1 2 0 (by decide) (by decide)
rw [this.entropy_pair_eq_add hX'_meas (by exact Measurable.prod hY'₁_meas hY'₂_meas),
IndepFun.entropy_pair_eq_add hY'₁_meas hY'₂_meas (h_indep.indepFun (show 1 ≠ 2 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, two_mul]
have : H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[X ; μ] + H[Y ; μ'] := calc
H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[⟨X', Y'₁⟩ ; μA] := by
let f : G × G → G × G := fun ⟨x, y₁⟩ ↦ (x, x - 2 • y₁)
show H[f ∘ ⟨X', Y'₁⟩ ; μA] = _
apply entropy_comp_of_injective μA (by exact Measurable.prod hX'_meas hY'₁_meas) f
exact fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + H[Y ; μ'] := by
rw [IndepFun.entropy_pair_eq_add hX'_meas hY'₁_meas (h_indep.indepFun (show 0 ≠ 1 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq]
let f : G × G → G × G := fun ⟨x, y⟩ ↦ (x, y - x)
have hf : f.Injective := fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all
have : H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] := calc
H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] = H[f ∘ ⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
show _ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂ - (Y'₁ - Y'₂)⟩ ; μA]
rw [sub_sub_sub_cancel_right, ← sub_add_eq_sub_sub, two_nsmul]
_ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
refine entropy_comp_of_injective μA (Measurable.prod ?_ ?_) f hf
· exact Measurable.sub hY'₁_meas hY'₂_meas
· exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
_ ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] :=
entropy_pair_le_add (hY'₁_meas.sub' hY'₂_meas) (hX'_meas.sub' hY'₁_meas |>.sub' hY'₂_meas) μA
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] + H[X' - 2 • Y'₁ ; μA] ≤
H[⟨X', X' - 2 • Y'₁⟩ ; μA] + H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] := by
haveI : FiniteRange (Y'₁ - Y'₂) := FiniteRange.sub Y'₁ Y'₂
haveI : FiniteRange (2 • Y'₁) := by show FiniteRange ((fun x ↦ 2 • x) ∘ Y'₁); infer_instance
apply entropy_triple_add_entropy_le μA hX'_meas (Measurable.sub hY'₁_meas hY'₂_meas)
exact Measurable.sub' hX'_meas <| Measurable.const_smul hY'₁_meas 2
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨y₁, y₂, x⟩ ↦ (y₁, y₂, x - y₁ - y₂)
show H[f ∘ ⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA]
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hY'₁_meas <| Measurable.prod hY'₂_meas hX'_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun Y'₁ (prod Y'₂ X') μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 2 0 1 (by decide) (by decide)
rw [this.entropy_pair_eq_add hY'₁_meas (by exact Measurable.prod hY'₂_meas hX'_meas),
IndepFun.entropy_pair_eq_add hY'₂_meas hX'_meas (h_indep.indepFun (show 2 ≠ 0 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq]
group
have : H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₂ ; μA] := calc
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₁, X' - Y'₂⟩ ; μA] := by rw [sub_right_comm] ; rfl
_ = H[⟨Y'₁, X' - Y'₂⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₁_meas <| Measurable.sub hX'_meas hY'₂_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₂ ; μA] := by
haveI : FiniteRange (X' - Y'₂) := FiniteRange.sub X' Y'₂
convert IndepFun.entropy_pair_eq_add hY'₁_meas (hX'_meas.sub hY'₂_meas)
<| h_indep.indepFun_sub_right h_meas 1 0 2 (by decide) (by decide)
exact hY'₁_ident.entropy_eq.symm
have : H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₁ ; μA] := calc
H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₂, X' - Y'₁⟩ ; μA] := rfl
_ = H[⟨Y'₂, X' - Y'₁⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₂_meas <| Measurable.sub hX'_meas hY'₁_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₁ ; μA] := by
haveI : FiniteRange (X' - Y'₁) := FiniteRange.sub X' Y'₁
convert IndepFun.entropy_pair_eq_add hY'₂_meas (hX'_meas.sub hY'₁_meas)
<| h_indep.indepFun_sub_right h_meas 2 0 1 (by decide) (by decide)
exact hY'₂_ident.entropy_eq.symm
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] ≤
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] + H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
apply entropy_triple_add_entropy_le μA hY'₁_meas hY'₂_meas
exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
have : H[X' - Y'₁ - Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := calc
H[X' - Y'₁ - Y'₂ ; μA] ≤ H[X' - Y'₁ ; μA] + H[X' - Y'₂ ; μA] - H[X ; μ] := by linarith
_ = 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := by
nth_rw 1 [two_mul, ← hX'_ident.rdist_eq hY'₁_ident, ← hX'_ident.rdist_eq hY'₂_ident]
have h1 : d[X' ; μA # Y'₁ ; μA] = H[X' - Y'₁ ; μA] - H[X' ; μA] / 2 - H[Y'₁ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 1 by decide)).rdist_eq hX'_meas hY'₁_meas
have h2 : d[X' ; μA # Y'₂ ; μA] = H[X' - Y'₂ ; μA] - H[X' ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 2 by decide)).rdist_eq hX'_meas hY'₂_meas
rw [h1, h2, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, hX'_ident.entropy_eq]
group
have : d[X ; μ # 2 • Y ; μ'] ≤
d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := calc
d[X ; μ # 2 • Y ; μ'] = H[X' - 2 • Y'₁ ; μA] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by
have h2Y_ident : IdentDistrib (2 • Y'₁) (2 • Y) (μ := μA) (ν := μ') := by
convert hY'₁_ident.comp <| measurable_discrete <| fun g ↦ 2 • g
have h2Y_indep : IndepFun X' (2 • Y'₁) (μ := μA) := by
convert (h_indep.indepFun (show 0 ≠ 1 by decide)).comp measurable_id
(measurable_const_smul 2)
rw [← hX'_ident.rdist_eq h2Y_ident,
h2Y_indep.rdist_eq hX'_meas <| Measurable.const_smul hY'₁_meas 2,
hX'_ident.entropy_eq, h2Y_ident.entropy_eq]
_ ≤ H[Y'₁ - Y'₂ ; μA] + 2 * d[X ; μ # Y ; μ'] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by linarith
_ = d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := by
have H2Y : H[2 • Y ; μ'] = H[Y ; μ'] := by
let f (g : G) := 2 • g
exact entropy_comp_of_injective μ' hY f (fun _ _ ↦ by simp [f, smul_right_inj])
have : d[Y'₁ ; μA # Y'₂ ; μA] = H[Y'₁ - Y'₂ ; μA] - H[Y'₁ ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 1 ≠ 2 by decide)).rdist_eq hY'₁_meas hY'₂_meas
rw [this, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, H2Y]
group
have : d[Y'₁ ; μA # Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] := by
rw [two_mul]
convert rdist_triangle hY'₁_meas hX'_meas hY'₂_meas (μ := μA) (μ' := μA) (μ'' := μA)
· exact rdist_symm.trans (hY'₁_ident.rdist_eq hX'_ident).symm
· exact (hX'_ident.rdist_eq hY'₂_ident).symm
rw [← two_nsmul]
linarith [abs_le.mp <| diff_ent_le_rdist hX hY (μ := μ) (μ' := μ')]
/-- If $G$ is a torsion-free group and $X,Y$ are $G$-valued random variables and
$\phi : G\to \mathbb{F}_2^d$ is a homomorphism then
\[\mathbb{H}(\phi(X))\leq 10d[X;Y].\] -/
lemma torsion_dist_shrinking {H : Type u} [FiniteRange X] [FiniteRange Y] (hX : Measurable X)
(hY : Measurable Y) [AddCommGroup H] [ElementaryAddCommGroup H 2]
[MeasurableSpace H] [MeasurableSingletonClass H] [Countable H]
(hG : AddMonoid.IsTorsionFree G) (φ : G →+ H) :
H[φ ∘ X ; μ] ≤ 10 * d[X; μ # Y ; μ'] := by
have :=
calc d[φ ∘ X ; μ # φ ∘ (Y + Y); μ'] ≤ d[X; μ # (Y + Y) ; μ'] := rdist_of_hom_le φ hX (Measurable.add hY hY)
_ ≤ 5 * d[X; μ # Y ; μ'] := torsion_free_doubling X Y μ μ' hX hY hG
have eq_zero : φ ∘ (Y + Y) = fun _ ↦ 0 := by ext x ; simp only [Function.comp_apply, Pi.add_apply,
map_add, ElementaryAddCommGroup.add_self]
rwa [eq_zero, rdist_zero_eq_half_ent, div_le_iff zero_lt_two, mul_assoc, mul_comm _ 2, ←mul_assoc,
show (5*2 : ℝ) = 10 by norm_num] at this
end Torsion
instance {G : Type u} [AddCommGroup G] [Fintype G] [MeasurableSpace G] [MeasurableSingletonClass G] (H : AddSubgroup G)
: MeasurableSingletonClass (G ⧸ H) :=
⟨λ _ ↦ by { rw [measurableSet_quotient]; simp [measurableSet_discrete] }⟩
section F2_projection
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [ElementaryAddCommGroup G 2] [Fintype G] [MeasurableSpace G]
[MeasurableSingletonClass G] {Ω Ω' : Type*}
/-- Let $G=\mathbb{F}_2^n$ and $X,Y$ be $G$-valued random variables such that
\[\mathbb{H}(X)+\mathbb{H}(Y)> (20/\alpha) d[X;Y],\]
for some $\alpha > 0$.
There is a non-trivial subgroup $H\leq G$ such that
\[\log \lvert H\rvert <(1+\alpha)/2 (\mathbb{H}(X)+\mathbb{H}(Y))\] and
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))< \alpha (\mathbb{H}(X)+\mathbb{H}(Y))\]
where $\psi:G\to G/H$ is the natural projection homomorphism.
-/
lemma app_ent_PFR' [MeasureSpace Ω] [MeasureSpace Ω'] (X : Ω → G) (Y : Ω' → G)
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
{α : ℝ} (hent : 20 * d[X # Y] < α * (H[X] + H[Y])) (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X] + H[Y]) ∧
H[(QuotientAddGroup.mk' H) ∘ X] + H[(QuotientAddGroup.mk' H) ∘ Y] < α * (H[X] + H[Y]) := by
let p : refPackage Ω Ω' G := {
X₀₁ := X
X₀₂ := Y
hmeas1 := hX
hmeas2 := hY
η := 1/8
hη := by norm_num
hη' := by norm_num }
obtain ⟨H, Ω'', hΩ'', U, _, hUmeas, hUunif, ineq⟩ := entropic_PFR_conjecture_improv p rfl
let ψ := (QuotientAddGroup.mk' H)
use H
haveI : Finite H := Subtype.finite
-- Note that H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y]
have ent_le : H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y] := calc
H[ψ ∘ X] + H[ψ ∘ Y] ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· exact ent_of_proj_le hX hUmeas hUunif
· exact ent_of_proj_le hY hUmeas hUunif
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- Note that (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y]
have log_sub_le : (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y] := calc
(log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) =
(H[U] - H[X]) + (H[U] - H[Y]) := by
rw [IsUniform.entropy_eq' hUunif hUmeas, SetLike.coe_sort_coe]
_ ≤ |(H[U] - H[X])| + |(H[U] - H[Y])| := by gcongr <;> exact le_abs_self _
_ ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hX
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hY
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- then the conclusion follows from the assumption `hent` and basic inequality manipulations
exact ⟨by linarith, by linarith⟩
variable [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ' : Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
| lemma app_ent_PFR (α : ℝ) (hent: 20 * d[X;μ # Y;μ'] < α * (H[X; μ] + H[Y; μ'])) (hX : Measurable X)
(hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ']
< α * (H[ X; μ] + H[Y; μ']) | app_ent_PFR | 25309ad 20231211 | 9275a21 20240110 | pfr/PFR/WeakPFR.lean | {
"lineInFile": 286,
"tokenPositionInFile": 15840,
"theoremPositionInFile": 9
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "@app_ent_PFR' _ _ _ _ _ _ _ _ (MeasureSpace.mk μ) (MeasureSpace.mk μ') _ _ _ _ α hent hX hY",
"proofType": "term",
"proofLengthLines": 1,
"proofLengthTokens": 91
} | pfr |
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Quotient
import Mathlib.GroupTheory.Torsion
import Mathlib.GroupTheory.Torsion
import Mathlib.LinearAlgebra.FreeModule.PID
import PFR.Mathlib.Data.Set.Pointwise.SMul
import PFR.EntropyPFR
import PFR.ImprovedPFR
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Mathlib.GroupTheory.Torsion
/-!
# Weak PFR over the integers
Here we use the entropic form of PFR to deduce a weak form of PFR over the integers.
## Main statement
* `weak_PFR_int`: Let $A\subseteq \mathbb{Z}^d$ and $\lvert A+A\rvert\leq K\lvert A\rvert$.
There exists $A'\subseteq A$ such that $\lvert A'\rvert \geq K^{-17}\lvert A\rvert$ and
$\dim A' \leq (40/\log 2)\log K$.
-/
section AddCommGroup
variable {G : Type*} [AddCommGroup G] {A B : Set G}
open Set
open scoped Pointwise
def IsShift (A B : Set G) : Prop := ∃ x : G, A = x +ᵥ B
lemma IsShift.sub_self_congr : IsShift A B → A - A = B - B := by
rintro ⟨x, rfl⟩; simp [vadd_sub_vadd_comm, singleton_zero]
lemma IsShift.card_congr : IsShift A B → Nat.card A = Nat.card B := by rintro ⟨x, rfl⟩; simp
/-- The property of two sets A, B of a group G not being contained in cosets of the same proper
subgroup -/
def NotInCoset (A B : Set G) : Prop := AddSubgroup.closure ((A - A) ∪ (B - B)) = ⊤
/-- Without loss of generality, one can move (up to translation and embedding) any pair A, B of non-empty sets into a subgroup where they are not in a coset. -/
lemma wlog_notInCoset (hA : A.Nonempty) (hB : B.Nonempty) :
∃ (G' : AddSubgroup G) (A' B' : Set G'), IsShift A A' ∧ IsShift B B' ∧ NotInCoset A' B' := by
obtain ⟨x, hx⟩ := hA
obtain ⟨y, hy⟩ := hB
set G' := AddSubgroup.closure ((A - A) ∪ (B - B))
set A' : Set G' := (↑) ⁻¹' ((-x) +ᵥ A)
set B' : Set G' := (↑) ⁻¹' ((-y) +ᵥ B)
have hxA : -x +ᵥ A ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hx).trans $ (subset_union_left ..).trans
AddSubgroup.subset_closure
have hyB : -y +ᵥ B ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hy).trans $ (subset_union_right ..).trans
AddSubgroup.subset_closure
have hA : IsShift A A' := ⟨x, by rw [Set.image_preimage_eq_of_subset hxA, vadd_neg_vadd]⟩
have hB : IsShift B B' := ⟨y, by rw [Set.image_preimage_eq_of_subset hyB, vadd_neg_vadd]⟩
refine ⟨G', A', B', hA, hB, ?_⟩
unfold NotInCoset
convert AddSubgroup.closure_preimage_eq_top ((A - A) ∪ (B - B))
simp_rw [preimage_union, hA.sub_self_congr, hB.sub_self_congr]
rw [preimage_sub, preimage_sub]
simp [A', B', preimage_image_preimage]
all_goals apply_rules [Subtype.coe_injective, (image_preimage_subset ..).trans, hxA, hyB]
end AddCommGroup
section Torsion
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [MeasurableSpace G] [MeasurableSingletonClass G]
[Countable G] {Ω Ω' : Type u} [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ': Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
/-- If $G$ is torsion-free and $X,Y$ are $G$-valued random variables then $d[X;2Y]\leq 5d[X;Y]$. -/
lemma torsion_free_doubling [FiniteRange X] [FiniteRange Y]
(hX : Measurable X) (hY : Measurable Y) (hG : AddMonoid.IsTorsionFree G) :
d[X ; μ # (Y + Y) ; μ'] ≤ 5 * d[X; μ # Y ; μ'] := by
obtain ⟨A, mA, μA, X', Y'₁, Y'₂, hμA, h_indep, hX'_meas, hY'₁_meas, hY'₂_meas, hX'_ident,
hY'₁_ident, hY'₂_ident, _, _, _⟩ := independent_copies3_nondep_finiteRange hX hY hY μ μ' μ'
have h_meas (i : Fin 3) : Measurable (![X', Y'₁, Y'₂] i) := by fin_cases i <;> assumption
haveI : NoZeroSMulDivisors ℕ G := hG.noZeroNsmulDivisors
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨x, y₁, y₂⟩ ↦ (x, y₁ - y₂, x - 2 • y₁)
show H[f ∘ ⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] = _
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hX'_meas <| Measurable.prod hY'₁_meas hY'₂_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun X' (prod Y'₁ Y'₂) μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 1 2 0 (by decide) (by decide)
rw [this.entropy_pair_eq_add hX'_meas (by exact Measurable.prod hY'₁_meas hY'₂_meas),
IndepFun.entropy_pair_eq_add hY'₁_meas hY'₂_meas (h_indep.indepFun (show 1 ≠ 2 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, two_mul]
have : H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[X ; μ] + H[Y ; μ'] := calc
H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[⟨X', Y'₁⟩ ; μA] := by
let f : G × G → G × G := fun ⟨x, y₁⟩ ↦ (x, x - 2 • y₁)
show H[f ∘ ⟨X', Y'₁⟩ ; μA] = _
apply entropy_comp_of_injective μA (by exact Measurable.prod hX'_meas hY'₁_meas) f
exact fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + H[Y ; μ'] := by
rw [IndepFun.entropy_pair_eq_add hX'_meas hY'₁_meas (h_indep.indepFun (show 0 ≠ 1 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq]
let f : G × G → G × G := fun ⟨x, y⟩ ↦ (x, y - x)
have hf : f.Injective := fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all
have : H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] := calc
H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] = H[f ∘ ⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
show _ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂ - (Y'₁ - Y'₂)⟩ ; μA]
rw [sub_sub_sub_cancel_right, ← sub_add_eq_sub_sub, two_nsmul]
_ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
refine entropy_comp_of_injective μA (Measurable.prod ?_ ?_) f hf
· exact Measurable.sub hY'₁_meas hY'₂_meas
· exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
_ ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] :=
entropy_pair_le_add (hY'₁_meas.sub' hY'₂_meas) (hX'_meas.sub' hY'₁_meas |>.sub' hY'₂_meas) μA
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] + H[X' - 2 • Y'₁ ; μA] ≤
H[⟨X', X' - 2 • Y'₁⟩ ; μA] + H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] := by
haveI : FiniteRange (Y'₁ - Y'₂) := FiniteRange.sub Y'₁ Y'₂
haveI : FiniteRange (2 • Y'₁) := by show FiniteRange ((fun x ↦ 2 • x) ∘ Y'₁); infer_instance
apply entropy_triple_add_entropy_le μA hX'_meas (Measurable.sub hY'₁_meas hY'₂_meas)
exact Measurable.sub' hX'_meas <| Measurable.const_smul hY'₁_meas 2
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨y₁, y₂, x⟩ ↦ (y₁, y₂, x - y₁ - y₂)
show H[f ∘ ⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA]
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hY'₁_meas <| Measurable.prod hY'₂_meas hX'_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun Y'₁ (prod Y'₂ X') μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 2 0 1 (by decide) (by decide)
rw [this.entropy_pair_eq_add hY'₁_meas (by exact Measurable.prod hY'₂_meas hX'_meas),
IndepFun.entropy_pair_eq_add hY'₂_meas hX'_meas (h_indep.indepFun (show 2 ≠ 0 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq]
group
have : H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₂ ; μA] := calc
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₁, X' - Y'₂⟩ ; μA] := by rw [sub_right_comm] ; rfl
_ = H[⟨Y'₁, X' - Y'₂⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₁_meas <| Measurable.sub hX'_meas hY'₂_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₂ ; μA] := by
haveI : FiniteRange (X' - Y'₂) := FiniteRange.sub X' Y'₂
convert IndepFun.entropy_pair_eq_add hY'₁_meas (hX'_meas.sub hY'₂_meas)
<| h_indep.indepFun_sub_right h_meas 1 0 2 (by decide) (by decide)
exact hY'₁_ident.entropy_eq.symm
have : H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₁ ; μA] := calc
H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₂, X' - Y'₁⟩ ; μA] := rfl
_ = H[⟨Y'₂, X' - Y'₁⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₂_meas <| Measurable.sub hX'_meas hY'₁_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₁ ; μA] := by
haveI : FiniteRange (X' - Y'₁) := FiniteRange.sub X' Y'₁
convert IndepFun.entropy_pair_eq_add hY'₂_meas (hX'_meas.sub hY'₁_meas)
<| h_indep.indepFun_sub_right h_meas 2 0 1 (by decide) (by decide)
exact hY'₂_ident.entropy_eq.symm
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] ≤
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] + H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
apply entropy_triple_add_entropy_le μA hY'₁_meas hY'₂_meas
exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
have : H[X' - Y'₁ - Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := calc
H[X' - Y'₁ - Y'₂ ; μA] ≤ H[X' - Y'₁ ; μA] + H[X' - Y'₂ ; μA] - H[X ; μ] := by linarith
_ = 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := by
nth_rw 1 [two_mul, ← hX'_ident.rdist_eq hY'₁_ident, ← hX'_ident.rdist_eq hY'₂_ident]
have h1 : d[X' ; μA # Y'₁ ; μA] = H[X' - Y'₁ ; μA] - H[X' ; μA] / 2 - H[Y'₁ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 1 by decide)).rdist_eq hX'_meas hY'₁_meas
have h2 : d[X' ; μA # Y'₂ ; μA] = H[X' - Y'₂ ; μA] - H[X' ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 2 by decide)).rdist_eq hX'_meas hY'₂_meas
rw [h1, h2, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, hX'_ident.entropy_eq]
group
have : d[X ; μ # 2 • Y ; μ'] ≤
d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := calc
d[X ; μ # 2 • Y ; μ'] = H[X' - 2 • Y'₁ ; μA] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by
have h2Y_ident : IdentDistrib (2 • Y'₁) (2 • Y) (μ := μA) (ν := μ') := by
convert hY'₁_ident.comp <| measurable_discrete <| fun g ↦ 2 • g
have h2Y_indep : IndepFun X' (2 • Y'₁) (μ := μA) := by
convert (h_indep.indepFun (show 0 ≠ 1 by decide)).comp measurable_id
(measurable_const_smul 2)
rw [← hX'_ident.rdist_eq h2Y_ident,
h2Y_indep.rdist_eq hX'_meas <| Measurable.const_smul hY'₁_meas 2,
hX'_ident.entropy_eq, h2Y_ident.entropy_eq]
_ ≤ H[Y'₁ - Y'₂ ; μA] + 2 * d[X ; μ # Y ; μ'] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by linarith
_ = d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := by
have H2Y : H[2 • Y ; μ'] = H[Y ; μ'] := by
let f (g : G) := 2 • g
exact entropy_comp_of_injective μ' hY f (fun _ _ ↦ by simp [f, smul_right_inj])
have : d[Y'₁ ; μA # Y'₂ ; μA] = H[Y'₁ - Y'₂ ; μA] - H[Y'₁ ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 1 ≠ 2 by decide)).rdist_eq hY'₁_meas hY'₂_meas
rw [this, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, H2Y]
group
have : d[Y'₁ ; μA # Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] := by
rw [two_mul]
convert rdist_triangle hY'₁_meas hX'_meas hY'₂_meas (μ := μA) (μ' := μA) (μ'' := μA)
· exact rdist_symm.trans (hY'₁_ident.rdist_eq hX'_ident).symm
· exact (hX'_ident.rdist_eq hY'₂_ident).symm
rw [← two_nsmul]
linarith [abs_le.mp <| diff_ent_le_rdist hX hY (μ := μ) (μ' := μ')]
/-- If $G$ is a torsion-free group and $X,Y$ are $G$-valued random variables and
$\phi : G\to \mathbb{F}_2^d$ is a homomorphism then
\[\mathbb{H}(\phi(X))\leq 10d[X;Y].\] -/
lemma torsion_dist_shrinking {H : Type u} [FiniteRange X] [FiniteRange Y] (hX : Measurable X)
(hY : Measurable Y) [AddCommGroup H] [ElementaryAddCommGroup H 2]
[MeasurableSpace H] [MeasurableSingletonClass H] [Countable H]
(hG : AddMonoid.IsTorsionFree G) (φ : G →+ H) :
H[φ ∘ X ; μ] ≤ 10 * d[X; μ # Y ; μ'] := by
have :=
calc d[φ ∘ X ; μ # φ ∘ (Y + Y); μ'] ≤ d[X; μ # (Y + Y) ; μ'] := rdist_of_hom_le φ hX (Measurable.add hY hY)
_ ≤ 5 * d[X; μ # Y ; μ'] := torsion_free_doubling X Y μ μ' hX hY hG
have eq_zero : φ ∘ (Y + Y) = fun _ ↦ 0 := by ext x ; simp only [Function.comp_apply, Pi.add_apply,
map_add, ElementaryAddCommGroup.add_self]
rwa [eq_zero, rdist_zero_eq_half_ent, div_le_iff zero_lt_two, mul_assoc, mul_comm _ 2, ←mul_assoc,
show (5*2 : ℝ) = 10 by norm_num] at this
end Torsion
instance {G : Type u} [AddCommGroup G] [Fintype G] [MeasurableSpace G] [MeasurableSingletonClass G] (H : AddSubgroup G)
: MeasurableSingletonClass (G ⧸ H) :=
⟨λ _ ↦ by { rw [measurableSet_quotient]; simp [measurableSet_discrete] }⟩
section F2_projection
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [ElementaryAddCommGroup G 2] [Fintype G] [MeasurableSpace G]
[MeasurableSingletonClass G] {Ω Ω' : Type*}
/-- Let $G=\mathbb{F}_2^n$ and $X,Y$ be $G$-valued random variables such that
\[\mathbb{H}(X)+\mathbb{H}(Y)> (20/\alpha) d[X;Y],\]
for some $\alpha > 0$.
There is a non-trivial subgroup $H\leq G$ such that
\[\log \lvert H\rvert <(1+\alpha)/2 (\mathbb{H}(X)+\mathbb{H}(Y))\] and
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))< \alpha (\mathbb{H}(X)+\mathbb{H}(Y))\]
where $\psi:G\to G/H$ is the natural projection homomorphism.
-/
lemma app_ent_PFR' [MeasureSpace Ω] [MeasureSpace Ω'] (X : Ω → G) (Y : Ω' → G)
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
{α : ℝ} (hent : 20 * d[X # Y] < α * (H[X] + H[Y])) (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X] + H[Y]) ∧
H[(QuotientAddGroup.mk' H) ∘ X] + H[(QuotientAddGroup.mk' H) ∘ Y] < α * (H[X] + H[Y]) := by
let p : refPackage Ω Ω' G := {
X₀₁ := X
X₀₂ := Y
hmeas1 := hX
hmeas2 := hY
η := 1/8
hη := by norm_num
hη' := by norm_num }
obtain ⟨H, Ω'', hΩ'', U, _, hUmeas, hUunif, ineq⟩ := entropic_PFR_conjecture_improv p rfl
let ψ := (QuotientAddGroup.mk' H)
use H
haveI : Finite H := Subtype.finite
-- Note that H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y]
have ent_le : H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y] := calc
H[ψ ∘ X] + H[ψ ∘ Y] ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· exact ent_of_proj_le hX hUmeas hUunif
· exact ent_of_proj_le hY hUmeas hUunif
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- Note that (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y]
have log_sub_le : (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y] := calc
(log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) =
(H[U] - H[X]) + (H[U] - H[Y]) := by
rw [IsUniform.entropy_eq' hUunif hUmeas, SetLike.coe_sort_coe]
_ ≤ |(H[U] - H[X])| + |(H[U] - H[Y])| := by gcongr <;> exact le_abs_self _
_ ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hX
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hY
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- then the conclusion follows from the assumption `hent` and basic inequality manipulations
exact ⟨by linarith, by linarith⟩
variable [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ' : Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
lemma app_ent_PFR (α : ℝ) (hent: 20 * d[X;μ # Y;μ'] < α * (H[X; μ] + H[Y; μ'])) (hX : Measurable X)
(hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ']
< α * (H[ X; μ] + H[Y; μ']) :=
@app_ent_PFR' _ _ _ _ _ _ _ _ (MeasureSpace.mk μ) (MeasureSpace.mk μ') _ _ _ _ α hent hX hY
set_option maxHeartbeats 300000 in
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables and $\alpha < 1$ then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq (1 + α) / (2 * (1 - α)) * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 20/\alpha * d[\psi(X);\psi(Y)].\] -/
| lemma PFR_projection'
(α : ℝ) (hX : Measurable X) (hY : Measurable Y) (αpos : 0 < α) (αone : α < 1) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (H[X ; μ] + H[Y ; μ']) ∧
α * (H[(QuotientAddGroup.mk' H) ∘ X ; μ] + H[(QuotientAddGroup.mk' H) ∘ Y ; μ']) ≤
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] | PFR_projection' | 25309ad 20231211 | 9692d13 20240111 | pfr/PFR/WeakPFR.lean | {
"lineInFile": 299,
"tokenPositionInFile": 16657,
"theoremPositionInFile": 10
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n let S := { H : AddSubgroup G | (∃ (c : ℝ), 0 ≤ c ∧\n log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (1 - c) * (H[X; μ] + H[Y;μ']) ∧\n H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤\n c * (H[X; μ] + H[Y;μ'])) ∧\n 20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] <\n α * (H[ (QuotientAddGroup.mk' H) ∘ X; μ ] + H[ (QuotientAddGroup.mk' H) ∘ Y; μ']) }\n have : 0 ≤ H[X ; μ] + H[Y ; μ'] := by linarith [entropy_nonneg X μ, entropy_nonneg Y μ']\n have : 0 < 1 - α := sub_pos.mpr αone\n by_cases hE : (⊥ : AddSubgroup G) ∈ S\n · classical\n obtain ⟨H, ⟨⟨c, hc, hlog, hup⟩, hent⟩, hMaxl⟩ :=\n S.toFinite.exists_maximal_wrt id S (Set.nonempty_of_mem hE)\n set ψ : G →+ G ⧸ H := QuotientAddGroup.mk' H\n have surj : Function.Surjective ψ := QuotientAddGroup.mk'_surjective H\n\n set G' := G ⧸ H\n have : ElementaryAddCommGroup G' 2 := ElementaryAddCommGroup.quotient_group (by decide)\n (by simp [AddSubgroup.zero_mem])\n\n obtain ⟨H', hlog', hup'⟩ := app_ent_PFR _ _ _ _ α hent ((measurable_discrete _).comp hX)\n ((measurable_discrete _).comp hY)\n have H_ne_bot: H' ≠ ⊥ := by\n by_contra!\n rcases this with rfl\n have inj : Function.Injective (QuotientAddGroup.mk' (⊥ : AddSubgroup G')) :=\n (QuotientAddGroup.quotientBot : (G' ⧸ ⊥) ≃+ G').symm.injective\n rw [entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ inj,\n entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ inj] at hup'\n nlinarith [entropy_nonneg (ψ ∘ X) μ, entropy_nonneg (ψ ∘ Y) μ']\n let H'' := H'.comap ψ\n use H''\n\n rw [← (AddSubgroup.map_comap_eq_self_of_surjective surj _ : H''.map ψ = H')] at hup' hlog'\n set H' := H''.map ψ\n\n have Hlt : H < H'' := by\n have : H = (⊥ : AddSubgroup G').comap ψ := by\n simp only [ψ, AddMonoidHom.comap_bot, QuotientAddGroup.ker_mk']\n rw [this, AddSubgroup.comap_lt_comap_of_surjective surj]\n exact Ne.bot_lt H_ne_bot\n\n let φ : G' ⧸ H' ≃+ G ⧸ H'' := QuotientAddGroup.quotientQuotientEquivQuotient H H'' Hlt.le\n set ψ' : G' →+ G' ⧸ H' := QuotientAddGroup.mk' H'\n set ψ'' : G →+ G ⧸ H'' := QuotientAddGroup.mk' H''\n have diag : ψ' ∘ ψ = φ.symm ∘ ψ'' := rfl\n rw [← Function.comp.assoc, ← Function.comp.assoc, diag, Function.comp.assoc,\n Function.comp.assoc] at hup'\n\n have cond : log (Nat.card H'') ≤\n (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := by\n have cardprod : Nat.card H'' = Nat.card H' * Nat.card H := by\n have hcard₀ := Nat.card_congr <| (AddSubgroup.addSubgroupOfEquivOfLe Hlt.le).toEquiv\n have hcard₁ := Nat.card_congr <|\n (QuotientAddGroup.quotientKerEquivRange (ψ.restrict H'')).toEquiv\n have hcard₂ := AddSubgroup.card_eq_card_quotient_mul_card_addSubgroup (H.addSubgroupOf H'')\n rw [ψ.ker_restrict H'', QuotientAddGroup.ker_mk', ψ.restrict_range H''] at hcard₁\n simpa only [← Nat.card_eq_fintype_card, hcard₀, hcard₁] using hcard₂\n calc\n log (Nat.card H'')\n _ = log ((Nat.card H' : ℝ) * (Nat.card H : ℝ)) := by rw [cardprod]; norm_cast\n _ = log (Nat.card H') + log (Nat.card H) := by\n rw [Real.log_mul (Nat.cast_ne_zero.2 (@Nat.card_pos H').ne')\n (Nat.cast_ne_zero.2 (@Nat.card_pos H).ne')]\n _ ≤ (1 + α) / 2 * (H[⇑ψ ∘ X ; μ] + H[⇑ψ ∘ Y ; μ']) + log (Nat.card H) := by gcongr\n _ ≤ (1 + α) / 2 * (c * (H[X; μ] + H[Y;μ'])) +\n (1 + α) / (2 * (1 - α)) * (1 - c) * (H[X ; μ] + H[Y ; μ']) := by gcongr\n _ = (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X ; μ] + H[Y ; μ']) := by\n field_simp; ring\n\n have HS : H'' ∉ S := λ Hs => Hlt.ne (hMaxl H'' Hs Hlt.le)\n simp only [S, Set.mem_setOf_eq, not_and, not_lt] at HS\n refine ⟨?_, HS ⟨α * c, by positivity, cond, ?_⟩⟩\n · calc\n log (Nat.card H'')\n _ ≤ (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := cond\n _ ≤ (1 + α) / (2 * (1 - α)) * 1 * (H[X; μ] + H[Y;μ']) := by gcongr; simp; positivity\n _ = (1 + α) / (2 * (1 - α)) * (H[X; μ] + H[Y;μ']) := by simp only [mul_one]\n · calc\n H[ ψ'' ∘ X; μ ] + H[ ψ'' ∘ Y; μ' ]\n _ = H[ φ.symm ∘ ψ'' ∘ X; μ ] + H[ φ.symm ∘ ψ'' ∘ Y; μ' ] := by\n simp_rw [← entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ φ.symm.injective,\n ← entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ φ.symm.injective]\n _ ≤ α * (H[ ψ ∘ X; μ ] + H[ ψ ∘ Y; μ' ]) := hup'.le\n _ ≤ α * (c * (H[X ; μ] + H[Y ; μ'])) := by gcongr\n _ = (α * c) * (H[X ; μ] + H[Y ; μ']) := by ring\n · use ⊥\n constructor\n · simp only [AddSubgroup.mem_bot, Nat.card_eq_fintype_card, Fintype.card_ofSubsingleton,\n Nat.cast_one, log_one]\n positivity\n · simp only [S, Set.mem_setOf_eq, not_and, not_lt] at hE\n exact hE ⟨1, by norm_num, by\n norm_num; exact add_le_add (entropy_comp_le μ hX _) (entropy_comp_le μ' hY _)⟩",
"proofType": "tactic",
"proofLengthLines": 94,
"proofLengthTokens": 4970
} | pfr |
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Quotient
import Mathlib.GroupTheory.Torsion
import Mathlib.GroupTheory.Torsion
import Mathlib.LinearAlgebra.FreeModule.PID
import PFR.Mathlib.Data.Set.Pointwise.SMul
import PFR.EntropyPFR
import PFR.ImprovedPFR
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Mathlib.GroupTheory.Torsion
/-!
# Weak PFR over the integers
Here we use the entropic form of PFR to deduce a weak form of PFR over the integers.
## Main statement
* `weak_PFR_int`: Let $A\subseteq \mathbb{Z}^d$ and $\lvert A+A\rvert\leq K\lvert A\rvert$.
There exists $A'\subseteq A$ such that $\lvert A'\rvert \geq K^{-17}\lvert A\rvert$ and
$\dim A' \leq (40/\log 2)\log K$.
-/
section AddCommGroup
variable {G : Type*} [AddCommGroup G] {A B : Set G}
open Set
open scoped Pointwise
def IsShift (A B : Set G) : Prop := ∃ x : G, A = x +ᵥ B
lemma IsShift.sub_self_congr : IsShift A B → A - A = B - B := by
rintro ⟨x, rfl⟩; simp [vadd_sub_vadd_comm, singleton_zero]
lemma IsShift.card_congr : IsShift A B → Nat.card A = Nat.card B := by rintro ⟨x, rfl⟩; simp
/-- The property of two sets A, B of a group G not being contained in cosets of the same proper
subgroup -/
def NotInCoset (A B : Set G) : Prop := AddSubgroup.closure ((A - A) ∪ (B - B)) = ⊤
/-- Without loss of generality, one can move (up to translation and embedding) any pair A, B of non-empty sets into a subgroup where they are not in a coset. -/
lemma wlog_notInCoset (hA : A.Nonempty) (hB : B.Nonempty) :
∃ (G' : AddSubgroup G) (A' B' : Set G'), IsShift A A' ∧ IsShift B B' ∧ NotInCoset A' B' := by
obtain ⟨x, hx⟩ := hA
obtain ⟨y, hy⟩ := hB
set G' := AddSubgroup.closure ((A - A) ∪ (B - B))
set A' : Set G' := (↑) ⁻¹' ((-x) +ᵥ A)
set B' : Set G' := (↑) ⁻¹' ((-y) +ᵥ B)
have hxA : -x +ᵥ A ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hx).trans $ (subset_union_left ..).trans
AddSubgroup.subset_closure
have hyB : -y +ᵥ B ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hy).trans $ (subset_union_right ..).trans
AddSubgroup.subset_closure
have hA : IsShift A A' := ⟨x, by rw [Set.image_preimage_eq_of_subset hxA, vadd_neg_vadd]⟩
have hB : IsShift B B' := ⟨y, by rw [Set.image_preimage_eq_of_subset hyB, vadd_neg_vadd]⟩
refine ⟨G', A', B', hA, hB, ?_⟩
unfold NotInCoset
convert AddSubgroup.closure_preimage_eq_top ((A - A) ∪ (B - B))
simp_rw [preimage_union, hA.sub_self_congr, hB.sub_self_congr]
rw [preimage_sub, preimage_sub]
simp [A', B', preimage_image_preimage]
all_goals apply_rules [Subtype.coe_injective, (image_preimage_subset ..).trans, hxA, hyB]
end AddCommGroup
section Torsion
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [MeasurableSpace G] [MeasurableSingletonClass G]
[Countable G] {Ω Ω' : Type u} [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ': Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
/-- If $G$ is torsion-free and $X,Y$ are $G$-valued random variables then $d[X;2Y]\leq 5d[X;Y]$. -/
lemma torsion_free_doubling [FiniteRange X] [FiniteRange Y]
(hX : Measurable X) (hY : Measurable Y) (hG : AddMonoid.IsTorsionFree G) :
d[X ; μ # (Y + Y) ; μ'] ≤ 5 * d[X; μ # Y ; μ'] := by
obtain ⟨A, mA, μA, X', Y'₁, Y'₂, hμA, h_indep, hX'_meas, hY'₁_meas, hY'₂_meas, hX'_ident,
hY'₁_ident, hY'₂_ident, _, _, _⟩ := independent_copies3_nondep_finiteRange hX hY hY μ μ' μ'
have h_meas (i : Fin 3) : Measurable (![X', Y'₁, Y'₂] i) := by fin_cases i <;> assumption
haveI : NoZeroSMulDivisors ℕ G := hG.noZeroNsmulDivisors
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨x, y₁, y₂⟩ ↦ (x, y₁ - y₂, x - 2 • y₁)
show H[f ∘ ⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] = _
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hX'_meas <| Measurable.prod hY'₁_meas hY'₂_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun X' (prod Y'₁ Y'₂) μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 1 2 0 (by decide) (by decide)
rw [this.entropy_pair_eq_add hX'_meas (by exact Measurable.prod hY'₁_meas hY'₂_meas),
IndepFun.entropy_pair_eq_add hY'₁_meas hY'₂_meas (h_indep.indepFun (show 1 ≠ 2 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, two_mul]
have : H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[X ; μ] + H[Y ; μ'] := calc
H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[⟨X', Y'₁⟩ ; μA] := by
let f : G × G → G × G := fun ⟨x, y₁⟩ ↦ (x, x - 2 • y₁)
show H[f ∘ ⟨X', Y'₁⟩ ; μA] = _
apply entropy_comp_of_injective μA (by exact Measurable.prod hX'_meas hY'₁_meas) f
exact fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + H[Y ; μ'] := by
rw [IndepFun.entropy_pair_eq_add hX'_meas hY'₁_meas (h_indep.indepFun (show 0 ≠ 1 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq]
let f : G × G → G × G := fun ⟨x, y⟩ ↦ (x, y - x)
have hf : f.Injective := fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all
have : H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] := calc
H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] = H[f ∘ ⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
show _ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂ - (Y'₁ - Y'₂)⟩ ; μA]
rw [sub_sub_sub_cancel_right, ← sub_add_eq_sub_sub, two_nsmul]
_ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
refine entropy_comp_of_injective μA (Measurable.prod ?_ ?_) f hf
· exact Measurable.sub hY'₁_meas hY'₂_meas
· exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
_ ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] :=
entropy_pair_le_add (hY'₁_meas.sub' hY'₂_meas) (hX'_meas.sub' hY'₁_meas |>.sub' hY'₂_meas) μA
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] + H[X' - 2 • Y'₁ ; μA] ≤
H[⟨X', X' - 2 • Y'₁⟩ ; μA] + H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] := by
haveI : FiniteRange (Y'₁ - Y'₂) := FiniteRange.sub Y'₁ Y'₂
haveI : FiniteRange (2 • Y'₁) := by show FiniteRange ((fun x ↦ 2 • x) ∘ Y'₁); infer_instance
apply entropy_triple_add_entropy_le μA hX'_meas (Measurable.sub hY'₁_meas hY'₂_meas)
exact Measurable.sub' hX'_meas <| Measurable.const_smul hY'₁_meas 2
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨y₁, y₂, x⟩ ↦ (y₁, y₂, x - y₁ - y₂)
show H[f ∘ ⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA]
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hY'₁_meas <| Measurable.prod hY'₂_meas hX'_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun Y'₁ (prod Y'₂ X') μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 2 0 1 (by decide) (by decide)
rw [this.entropy_pair_eq_add hY'₁_meas (by exact Measurable.prod hY'₂_meas hX'_meas),
IndepFun.entropy_pair_eq_add hY'₂_meas hX'_meas (h_indep.indepFun (show 2 ≠ 0 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq]
group
have : H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₂ ; μA] := calc
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₁, X' - Y'₂⟩ ; μA] := by rw [sub_right_comm] ; rfl
_ = H[⟨Y'₁, X' - Y'₂⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₁_meas <| Measurable.sub hX'_meas hY'₂_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₂ ; μA] := by
haveI : FiniteRange (X' - Y'₂) := FiniteRange.sub X' Y'₂
convert IndepFun.entropy_pair_eq_add hY'₁_meas (hX'_meas.sub hY'₂_meas)
<| h_indep.indepFun_sub_right h_meas 1 0 2 (by decide) (by decide)
exact hY'₁_ident.entropy_eq.symm
have : H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₁ ; μA] := calc
H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₂, X' - Y'₁⟩ ; μA] := rfl
_ = H[⟨Y'₂, X' - Y'₁⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₂_meas <| Measurable.sub hX'_meas hY'₁_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₁ ; μA] := by
haveI : FiniteRange (X' - Y'₁) := FiniteRange.sub X' Y'₁
convert IndepFun.entropy_pair_eq_add hY'₂_meas (hX'_meas.sub hY'₁_meas)
<| h_indep.indepFun_sub_right h_meas 2 0 1 (by decide) (by decide)
exact hY'₂_ident.entropy_eq.symm
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] ≤
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] + H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
apply entropy_triple_add_entropy_le μA hY'₁_meas hY'₂_meas
exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
have : H[X' - Y'₁ - Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := calc
H[X' - Y'₁ - Y'₂ ; μA] ≤ H[X' - Y'₁ ; μA] + H[X' - Y'₂ ; μA] - H[X ; μ] := by linarith
_ = 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := by
nth_rw 1 [two_mul, ← hX'_ident.rdist_eq hY'₁_ident, ← hX'_ident.rdist_eq hY'₂_ident]
have h1 : d[X' ; μA # Y'₁ ; μA] = H[X' - Y'₁ ; μA] - H[X' ; μA] / 2 - H[Y'₁ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 1 by decide)).rdist_eq hX'_meas hY'₁_meas
have h2 : d[X' ; μA # Y'₂ ; μA] = H[X' - Y'₂ ; μA] - H[X' ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 2 by decide)).rdist_eq hX'_meas hY'₂_meas
rw [h1, h2, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, hX'_ident.entropy_eq]
group
have : d[X ; μ # 2 • Y ; μ'] ≤
d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := calc
d[X ; μ # 2 • Y ; μ'] = H[X' - 2 • Y'₁ ; μA] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by
have h2Y_ident : IdentDistrib (2 • Y'₁) (2 • Y) (μ := μA) (ν := μ') := by
convert hY'₁_ident.comp <| measurable_discrete <| fun g ↦ 2 • g
have h2Y_indep : IndepFun X' (2 • Y'₁) (μ := μA) := by
convert (h_indep.indepFun (show 0 ≠ 1 by decide)).comp measurable_id
(measurable_const_smul 2)
rw [← hX'_ident.rdist_eq h2Y_ident,
h2Y_indep.rdist_eq hX'_meas <| Measurable.const_smul hY'₁_meas 2,
hX'_ident.entropy_eq, h2Y_ident.entropy_eq]
_ ≤ H[Y'₁ - Y'₂ ; μA] + 2 * d[X ; μ # Y ; μ'] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by linarith
_ = d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := by
have H2Y : H[2 • Y ; μ'] = H[Y ; μ'] := by
let f (g : G) := 2 • g
exact entropy_comp_of_injective μ' hY f (fun _ _ ↦ by simp [f, smul_right_inj])
have : d[Y'₁ ; μA # Y'₂ ; μA] = H[Y'₁ - Y'₂ ; μA] - H[Y'₁ ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 1 ≠ 2 by decide)).rdist_eq hY'₁_meas hY'₂_meas
rw [this, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, H2Y]
group
have : d[Y'₁ ; μA # Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] := by
rw [two_mul]
convert rdist_triangle hY'₁_meas hX'_meas hY'₂_meas (μ := μA) (μ' := μA) (μ'' := μA)
· exact rdist_symm.trans (hY'₁_ident.rdist_eq hX'_ident).symm
· exact (hX'_ident.rdist_eq hY'₂_ident).symm
rw [← two_nsmul]
linarith [abs_le.mp <| diff_ent_le_rdist hX hY (μ := μ) (μ' := μ')]
/-- If $G$ is a torsion-free group and $X,Y$ are $G$-valued random variables and
$\phi : G\to \mathbb{F}_2^d$ is a homomorphism then
\[\mathbb{H}(\phi(X))\leq 10d[X;Y].\] -/
lemma torsion_dist_shrinking {H : Type u} [FiniteRange X] [FiniteRange Y] (hX : Measurable X)
(hY : Measurable Y) [AddCommGroup H] [ElementaryAddCommGroup H 2]
[MeasurableSpace H] [MeasurableSingletonClass H] [Countable H]
(hG : AddMonoid.IsTorsionFree G) (φ : G →+ H) :
H[φ ∘ X ; μ] ≤ 10 * d[X; μ # Y ; μ'] := by
have :=
calc d[φ ∘ X ; μ # φ ∘ (Y + Y); μ'] ≤ d[X; μ # (Y + Y) ; μ'] := rdist_of_hom_le φ hX (Measurable.add hY hY)
_ ≤ 5 * d[X; μ # Y ; μ'] := torsion_free_doubling X Y μ μ' hX hY hG
have eq_zero : φ ∘ (Y + Y) = fun _ ↦ 0 := by ext x ; simp only [Function.comp_apply, Pi.add_apply,
map_add, ElementaryAddCommGroup.add_self]
rwa [eq_zero, rdist_zero_eq_half_ent, div_le_iff zero_lt_two, mul_assoc, mul_comm _ 2, ←mul_assoc,
show (5*2 : ℝ) = 10 by norm_num] at this
end Torsion
instance {G : Type u} [AddCommGroup G] [Fintype G] [MeasurableSpace G] [MeasurableSingletonClass G] (H : AddSubgroup G)
: MeasurableSingletonClass (G ⧸ H) :=
⟨λ _ ↦ by { rw [measurableSet_quotient]; simp [measurableSet_discrete] }⟩
section F2_projection
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [ElementaryAddCommGroup G 2] [Fintype G] [MeasurableSpace G]
[MeasurableSingletonClass G] {Ω Ω' : Type*}
/-- Let $G=\mathbb{F}_2^n$ and $X,Y$ be $G$-valued random variables such that
\[\mathbb{H}(X)+\mathbb{H}(Y)> (20/\alpha) d[X;Y],\]
for some $\alpha > 0$.
There is a non-trivial subgroup $H\leq G$ such that
\[\log \lvert H\rvert <(1+\alpha)/2 (\mathbb{H}(X)+\mathbb{H}(Y))\] and
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))< \alpha (\mathbb{H}(X)+\mathbb{H}(Y))\]
where $\psi:G\to G/H$ is the natural projection homomorphism.
-/
lemma app_ent_PFR' [MeasureSpace Ω] [MeasureSpace Ω'] (X : Ω → G) (Y : Ω' → G)
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
{α : ℝ} (hent : 20 * d[X # Y] < α * (H[X] + H[Y])) (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X] + H[Y]) ∧
H[(QuotientAddGroup.mk' H) ∘ X] + H[(QuotientAddGroup.mk' H) ∘ Y] < α * (H[X] + H[Y]) := by
let p : refPackage Ω Ω' G := {
X₀₁ := X
X₀₂ := Y
hmeas1 := hX
hmeas2 := hY
η := 1/8
hη := by norm_num
hη' := by norm_num }
obtain ⟨H, Ω'', hΩ'', U, _, hUmeas, hUunif, ineq⟩ := entropic_PFR_conjecture_improv p rfl
let ψ := (QuotientAddGroup.mk' H)
use H
haveI : Finite H := Subtype.finite
-- Note that H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y]
have ent_le : H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y] := calc
H[ψ ∘ X] + H[ψ ∘ Y] ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· exact ent_of_proj_le hX hUmeas hUunif
· exact ent_of_proj_le hY hUmeas hUunif
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- Note that (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y]
have log_sub_le : (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y] := calc
(log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) =
(H[U] - H[X]) + (H[U] - H[Y]) := by
rw [IsUniform.entropy_eq' hUunif hUmeas, SetLike.coe_sort_coe]
_ ≤ |(H[U] - H[X])| + |(H[U] - H[Y])| := by gcongr <;> exact le_abs_self _
_ ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hX
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hY
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- then the conclusion follows from the assumption `hent` and basic inequality manipulations
exact ⟨by linarith, by linarith⟩
variable [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ' : Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
lemma app_ent_PFR (α : ℝ) (hent: 20 * d[X;μ # Y;μ'] < α * (H[X; μ] + H[Y; μ'])) (hX : Measurable X)
(hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ']
< α * (H[ X; μ] + H[Y; μ']) :=
@app_ent_PFR' _ _ _ _ _ _ _ _ (MeasureSpace.mk μ) (MeasureSpace.mk μ') _ _ _ _ α hent hX hY
set_option maxHeartbeats 300000 in
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables and $\alpha < 1$ then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq (1 + α) / (2 * (1 - α)) * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 20/\alpha * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection'
(α : ℝ) (hX : Measurable X) (hY : Measurable Y) (αpos : 0 < α) (αone : α < 1) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (H[X ; μ] + H[Y ; μ']) ∧
α * (H[(QuotientAddGroup.mk' H) ∘ X ; μ] + H[(QuotientAddGroup.mk' H) ∘ Y ; μ']) ≤
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] := by
let S := { H : AddSubgroup G | (∃ (c : ℝ), 0 ≤ c ∧
log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (1 - c) * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
c * (H[X; μ] + H[Y;μ'])) ∧
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] <
α * (H[ (QuotientAddGroup.mk' H) ∘ X; μ ] + H[ (QuotientAddGroup.mk' H) ∘ Y; μ']) }
have : 0 ≤ H[X ; μ] + H[Y ; μ'] := by linarith [entropy_nonneg X μ, entropy_nonneg Y μ']
have : 0 < 1 - α := sub_pos.mpr αone
by_cases hE : (⊥ : AddSubgroup G) ∈ S
· classical
obtain ⟨H, ⟨⟨c, hc, hlog, hup⟩, hent⟩, hMaxl⟩ :=
S.toFinite.exists_maximal_wrt id S (Set.nonempty_of_mem hE)
set ψ : G →+ G ⧸ H := QuotientAddGroup.mk' H
have surj : Function.Surjective ψ := QuotientAddGroup.mk'_surjective H
set G' := G ⧸ H
have : ElementaryAddCommGroup G' 2 := ElementaryAddCommGroup.quotient_group (by decide)
(by simp [AddSubgroup.zero_mem])
obtain ⟨H', hlog', hup'⟩ := app_ent_PFR _ _ _ _ α hent ((measurable_discrete _).comp hX)
((measurable_discrete _).comp hY)
have H_ne_bot: H' ≠ ⊥ := by
by_contra!
rcases this with rfl
have inj : Function.Injective (QuotientAddGroup.mk' (⊥ : AddSubgroup G')) :=
(QuotientAddGroup.quotientBot : (G' ⧸ ⊥) ≃+ G').symm.injective
rw [entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ inj,
entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ inj] at hup'
nlinarith [entropy_nonneg (ψ ∘ X) μ, entropy_nonneg (ψ ∘ Y) μ']
let H'' := H'.comap ψ
use H''
rw [← (AddSubgroup.map_comap_eq_self_of_surjective surj _ : H''.map ψ = H')] at hup' hlog'
set H' := H''.map ψ
have Hlt : H < H'' := by
have : H = (⊥ : AddSubgroup G').comap ψ := by
simp only [ψ, AddMonoidHom.comap_bot, QuotientAddGroup.ker_mk']
rw [this, AddSubgroup.comap_lt_comap_of_surjective surj]
exact Ne.bot_lt H_ne_bot
let φ : G' ⧸ H' ≃+ G ⧸ H'' := QuotientAddGroup.quotientQuotientEquivQuotient H H'' Hlt.le
set ψ' : G' →+ G' ⧸ H' := QuotientAddGroup.mk' H'
set ψ'' : G →+ G ⧸ H'' := QuotientAddGroup.mk' H''
have diag : ψ' ∘ ψ = φ.symm ∘ ψ'' := rfl
rw [← Function.comp.assoc, ← Function.comp.assoc, diag, Function.comp.assoc,
Function.comp.assoc] at hup'
have cond : log (Nat.card H'') ≤
(1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := by
have cardprod : Nat.card H'' = Nat.card H' * Nat.card H := by
have hcard₀ := Nat.card_congr <| (AddSubgroup.addSubgroupOfEquivOfLe Hlt.le).toEquiv
have hcard₁ := Nat.card_congr <|
(QuotientAddGroup.quotientKerEquivRange (ψ.restrict H'')).toEquiv
have hcard₂ := AddSubgroup.card_eq_card_quotient_mul_card_addSubgroup (H.addSubgroupOf H'')
rw [ψ.ker_restrict H'', QuotientAddGroup.ker_mk', ψ.restrict_range H''] at hcard₁
simpa only [← Nat.card_eq_fintype_card, hcard₀, hcard₁] using hcard₂
calc
log (Nat.card H'')
_ = log ((Nat.card H' : ℝ) * (Nat.card H : ℝ)) := by rw [cardprod]; norm_cast
_ = log (Nat.card H') + log (Nat.card H) := by
rw [Real.log_mul (Nat.cast_ne_zero.2 (@Nat.card_pos H').ne')
(Nat.cast_ne_zero.2 (@Nat.card_pos H).ne')]
_ ≤ (1 + α) / 2 * (H[⇑ψ ∘ X ; μ] + H[⇑ψ ∘ Y ; μ']) + log (Nat.card H) := by gcongr
_ ≤ (1 + α) / 2 * (c * (H[X; μ] + H[Y;μ'])) +
(1 + α) / (2 * (1 - α)) * (1 - c) * (H[X ; μ] + H[Y ; μ']) := by gcongr
_ = (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X ; μ] + H[Y ; μ']) := by
field_simp; ring
have HS : H'' ∉ S := λ Hs => Hlt.ne (hMaxl H'' Hs Hlt.le)
simp only [S, Set.mem_setOf_eq, not_and, not_lt] at HS
refine ⟨?_, HS ⟨α * c, by positivity, cond, ?_⟩⟩
· calc
log (Nat.card H'')
_ ≤ (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := cond
_ ≤ (1 + α) / (2 * (1 - α)) * 1 * (H[X; μ] + H[Y;μ']) := by gcongr; simp; positivity
_ = (1 + α) / (2 * (1 - α)) * (H[X; μ] + H[Y;μ']) := by simp only [mul_one]
· calc
H[ ψ'' ∘ X; μ ] + H[ ψ'' ∘ Y; μ' ]
_ = H[ φ.symm ∘ ψ'' ∘ X; μ ] + H[ φ.symm ∘ ψ'' ∘ Y; μ' ] := by
simp_rw [← entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ φ.symm.injective,
← entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ φ.symm.injective]
_ ≤ α * (H[ ψ ∘ X; μ ] + H[ ψ ∘ Y; μ' ]) := hup'.le
_ ≤ α * (c * (H[X ; μ] + H[Y ; μ'])) := by gcongr
_ = (α * c) * (H[X ; μ] + H[Y ; μ']) := by ring
· use ⊥
constructor
· simp only [AddSubgroup.mem_bot, Nat.card_eq_fintype_card, Fintype.card_ofSubsingleton,
Nat.cast_one, log_one]
positivity
· simp only [S, Set.mem_setOf_eq, not_and, not_lt] at hE
exact hE ⟨1, by norm_num, by
norm_num; exact add_le_add (entropy_comp_le μ hX _) (entropy_comp_le μ' hY _)⟩
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq 2 * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 34 * d[\psi(X);\psi(Y)].\] -/
| lemma PFR_projection (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
34 * d[(QuotientAddGroup.mk' H) ∘ X;μ # (QuotientAddGroup.mk' H) ∘ Y;μ'] | PFR_projection | 25309ad 20231211 | 9692d13 20240111 | pfr/PFR/WeakPFR.lean | {
"lineInFile": 403,
"tokenPositionInFile": 22324,
"theoremPositionInFile": 11
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n rcases PFR_projection' X Y μ μ' ((3 : ℝ) / 5) hX hY (by norm_num) (by norm_num) with ⟨H, h, h'⟩\n refine ⟨H, ?_, ?_⟩\n · convert h\n norm_num\n · have : 0 ≤ d[⇑(QuotientAddGroup.mk' H) ∘ X ; μ # ⇑(QuotientAddGroup.mk' H) ∘ Y ; μ'] :=\n rdist_nonneg ((measurable_discrete _).comp hX) ((measurable_discrete _).comp hY)\n linarith",
"proofType": "tactic",
"proofLengthLines": 8,
"proofLengthTokens": 340
} | pfr |
ProbabilityTheory.IdentDistrib.tau_minimizes | lemma four_logs {a b c d : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) (hd : 0 < d) :
log ((a*b)/(c*d)) = log a + log b - log c - log d | four_logs | 25309ad 20231211 | c0c547a 20240116 | pfr/PFR/WeakPFR.lean | {
"lineInFile": 420,
"tokenPositionInFile": 23051,
"theoremPositionInFile": 12
} | {
"inFilePremises": false,
"repositoryPremises": false
} | {
"hasProof": true,
"proof": "by\n rw [log_div, log_mul, log_mul, sub_sub] <;> positivity",
"proofType": "tactic",
"proofLengthLines": 2,
"proofLengthTokens": 59
} | pfr |
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Quotient
import Mathlib.GroupTheory.Torsion
import Mathlib.GroupTheory.Torsion
import Mathlib.LinearAlgebra.FreeModule.PID
import PFR.Mathlib.Data.Set.Pointwise.SMul
import PFR.EntropyPFR
import PFR.ImprovedPFR
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Mathlib.GroupTheory.Torsion
/-!
# Weak PFR over the integers
Here we use the entropic form of PFR to deduce a weak form of PFR over the integers.
## Main statement
* `weak_PFR_int`: Let $A\subseteq \mathbb{Z}^d$ and $\lvert A+A\rvert\leq K\lvert A\rvert$.
There exists $A'\subseteq A$ such that $\lvert A'\rvert \geq K^{-17}\lvert A\rvert$ and
$\dim A' \leq (40/\log 2)\log K$.
-/
section AddCommGroup
variable {G : Type*} [AddCommGroup G] {A B : Set G}
open Set
open scoped Pointwise
def IsShift (A B : Set G) : Prop := ∃ x : G, A = x +ᵥ B
lemma IsShift.sub_self_congr : IsShift A B → A - A = B - B := by
rintro ⟨x, rfl⟩; simp [vadd_sub_vadd_comm, singleton_zero]
lemma IsShift.card_congr : IsShift A B → Nat.card A = Nat.card B := by rintro ⟨x, rfl⟩; simp
/-- The property of two sets A, B of a group G not being contained in cosets of the same proper
subgroup -/
def NotInCoset (A B : Set G) : Prop := AddSubgroup.closure ((A - A) ∪ (B - B)) = ⊤
/-- Without loss of generality, one can move (up to translation and embedding) any pair A, B of non-empty sets into a subgroup where they are not in a coset. -/
lemma wlog_notInCoset (hA : A.Nonempty) (hB : B.Nonempty) :
∃ (G' : AddSubgroup G) (A' B' : Set G'), IsShift A A' ∧ IsShift B B' ∧ NotInCoset A' B' := by
obtain ⟨x, hx⟩ := hA
obtain ⟨y, hy⟩ := hB
set G' := AddSubgroup.closure ((A - A) ∪ (B - B))
set A' : Set G' := (↑) ⁻¹' ((-x) +ᵥ A)
set B' : Set G' := (↑) ⁻¹' ((-y) +ᵥ B)
have hxA : -x +ᵥ A ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hx).trans $ (subset_union_left ..).trans
AddSubgroup.subset_closure
have hyB : -y +ᵥ B ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hy).trans $ (subset_union_right ..).trans
AddSubgroup.subset_closure
have hA : IsShift A A' := ⟨x, by rw [Set.image_preimage_eq_of_subset hxA, vadd_neg_vadd]⟩
have hB : IsShift B B' := ⟨y, by rw [Set.image_preimage_eq_of_subset hyB, vadd_neg_vadd]⟩
refine ⟨G', A', B', hA, hB, ?_⟩
unfold NotInCoset
convert AddSubgroup.closure_preimage_eq_top ((A - A) ∪ (B - B))
simp_rw [preimage_union, hA.sub_self_congr, hB.sub_self_congr]
rw [preimage_sub, preimage_sub]
simp [A', B', preimage_image_preimage]
all_goals apply_rules [Subtype.coe_injective, (image_preimage_subset ..).trans, hxA, hyB]
end AddCommGroup
section Torsion
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [MeasurableSpace G] [MeasurableSingletonClass G]
[Countable G] {Ω Ω' : Type u} [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ': Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
/-- If $G$ is torsion-free and $X,Y$ are $G$-valued random variables then $d[X;2Y]\leq 5d[X;Y]$. -/
lemma torsion_free_doubling [FiniteRange X] [FiniteRange Y]
(hX : Measurable X) (hY : Measurable Y) (hG : AddMonoid.IsTorsionFree G) :
d[X ; μ # (Y + Y) ; μ'] ≤ 5 * d[X; μ # Y ; μ'] := by
obtain ⟨A, mA, μA, X', Y'₁, Y'₂, hμA, h_indep, hX'_meas, hY'₁_meas, hY'₂_meas, hX'_ident,
hY'₁_ident, hY'₂_ident, _, _, _⟩ := independent_copies3_nondep_finiteRange hX hY hY μ μ' μ'
have h_meas (i : Fin 3) : Measurable (![X', Y'₁, Y'₂] i) := by fin_cases i <;> assumption
haveI : NoZeroSMulDivisors ℕ G := hG.noZeroNsmulDivisors
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨x, y₁, y₂⟩ ↦ (x, y₁ - y₂, x - 2 • y₁)
show H[f ∘ ⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] = _
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hX'_meas <| Measurable.prod hY'₁_meas hY'₂_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun X' (prod Y'₁ Y'₂) μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 1 2 0 (by decide) (by decide)
rw [this.entropy_pair_eq_add hX'_meas (by exact Measurable.prod hY'₁_meas hY'₂_meas),
IndepFun.entropy_pair_eq_add hY'₁_meas hY'₂_meas (h_indep.indepFun (show 1 ≠ 2 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, two_mul]
have : H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[X ; μ] + H[Y ; μ'] := calc
H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[⟨X', Y'₁⟩ ; μA] := by
let f : G × G → G × G := fun ⟨x, y₁⟩ ↦ (x, x - 2 • y₁)
show H[f ∘ ⟨X', Y'₁⟩ ; μA] = _
apply entropy_comp_of_injective μA (by exact Measurable.prod hX'_meas hY'₁_meas) f
exact fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + H[Y ; μ'] := by
rw [IndepFun.entropy_pair_eq_add hX'_meas hY'₁_meas (h_indep.indepFun (show 0 ≠ 1 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq]
let f : G × G → G × G := fun ⟨x, y⟩ ↦ (x, y - x)
have hf : f.Injective := fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all
have : H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] := calc
H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] = H[f ∘ ⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
show _ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂ - (Y'₁ - Y'₂)⟩ ; μA]
rw [sub_sub_sub_cancel_right, ← sub_add_eq_sub_sub, two_nsmul]
_ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
refine entropy_comp_of_injective μA (Measurable.prod ?_ ?_) f hf
· exact Measurable.sub hY'₁_meas hY'₂_meas
· exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
_ ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] :=
entropy_pair_le_add (hY'₁_meas.sub' hY'₂_meas) (hX'_meas.sub' hY'₁_meas |>.sub' hY'₂_meas) μA
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] + H[X' - 2 • Y'₁ ; μA] ≤
H[⟨X', X' - 2 • Y'₁⟩ ; μA] + H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] := by
haveI : FiniteRange (Y'₁ - Y'₂) := FiniteRange.sub Y'₁ Y'₂
haveI : FiniteRange (2 • Y'₁) := by show FiniteRange ((fun x ↦ 2 • x) ∘ Y'₁); infer_instance
apply entropy_triple_add_entropy_le μA hX'_meas (Measurable.sub hY'₁_meas hY'₂_meas)
exact Measurable.sub' hX'_meas <| Measurable.const_smul hY'₁_meas 2
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨y₁, y₂, x⟩ ↦ (y₁, y₂, x - y₁ - y₂)
show H[f ∘ ⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA]
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hY'₁_meas <| Measurable.prod hY'₂_meas hX'_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun Y'₁ (prod Y'₂ X') μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 2 0 1 (by decide) (by decide)
rw [this.entropy_pair_eq_add hY'₁_meas (by exact Measurable.prod hY'₂_meas hX'_meas),
IndepFun.entropy_pair_eq_add hY'₂_meas hX'_meas (h_indep.indepFun (show 2 ≠ 0 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq]
group
have : H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₂ ; μA] := calc
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₁, X' - Y'₂⟩ ; μA] := by rw [sub_right_comm] ; rfl
_ = H[⟨Y'₁, X' - Y'₂⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₁_meas <| Measurable.sub hX'_meas hY'₂_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₂ ; μA] := by
haveI : FiniteRange (X' - Y'₂) := FiniteRange.sub X' Y'₂
convert IndepFun.entropy_pair_eq_add hY'₁_meas (hX'_meas.sub hY'₂_meas)
<| h_indep.indepFun_sub_right h_meas 1 0 2 (by decide) (by decide)
exact hY'₁_ident.entropy_eq.symm
have : H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₁ ; μA] := calc
H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₂, X' - Y'₁⟩ ; μA] := rfl
_ = H[⟨Y'₂, X' - Y'₁⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₂_meas <| Measurable.sub hX'_meas hY'₁_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₁ ; μA] := by
haveI : FiniteRange (X' - Y'₁) := FiniteRange.sub X' Y'₁
convert IndepFun.entropy_pair_eq_add hY'₂_meas (hX'_meas.sub hY'₁_meas)
<| h_indep.indepFun_sub_right h_meas 2 0 1 (by decide) (by decide)
exact hY'₂_ident.entropy_eq.symm
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] ≤
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] + H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
apply entropy_triple_add_entropy_le μA hY'₁_meas hY'₂_meas
exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
have : H[X' - Y'₁ - Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := calc
H[X' - Y'₁ - Y'₂ ; μA] ≤ H[X' - Y'₁ ; μA] + H[X' - Y'₂ ; μA] - H[X ; μ] := by linarith
_ = 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := by
nth_rw 1 [two_mul, ← hX'_ident.rdist_eq hY'₁_ident, ← hX'_ident.rdist_eq hY'₂_ident]
have h1 : d[X' ; μA # Y'₁ ; μA] = H[X' - Y'₁ ; μA] - H[X' ; μA] / 2 - H[Y'₁ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 1 by decide)).rdist_eq hX'_meas hY'₁_meas
have h2 : d[X' ; μA # Y'₂ ; μA] = H[X' - Y'₂ ; μA] - H[X' ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 2 by decide)).rdist_eq hX'_meas hY'₂_meas
rw [h1, h2, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, hX'_ident.entropy_eq]
group
have : d[X ; μ # 2 • Y ; μ'] ≤
d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := calc
d[X ; μ # 2 • Y ; μ'] = H[X' - 2 • Y'₁ ; μA] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by
have h2Y_ident : IdentDistrib (2 • Y'₁) (2 • Y) (μ := μA) (ν := μ') := by
convert hY'₁_ident.comp <| measurable_discrete <| fun g ↦ 2 • g
have h2Y_indep : IndepFun X' (2 • Y'₁) (μ := μA) := by
convert (h_indep.indepFun (show 0 ≠ 1 by decide)).comp measurable_id
(measurable_const_smul 2)
rw [← hX'_ident.rdist_eq h2Y_ident,
h2Y_indep.rdist_eq hX'_meas <| Measurable.const_smul hY'₁_meas 2,
hX'_ident.entropy_eq, h2Y_ident.entropy_eq]
_ ≤ H[Y'₁ - Y'₂ ; μA] + 2 * d[X ; μ # Y ; μ'] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by linarith
_ = d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := by
have H2Y : H[2 • Y ; μ'] = H[Y ; μ'] := by
let f (g : G) := 2 • g
exact entropy_comp_of_injective μ' hY f (fun _ _ ↦ by simp [f, smul_right_inj])
have : d[Y'₁ ; μA # Y'₂ ; μA] = H[Y'₁ - Y'₂ ; μA] - H[Y'₁ ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 1 ≠ 2 by decide)).rdist_eq hY'₁_meas hY'₂_meas
rw [this, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, H2Y]
group
have : d[Y'₁ ; μA # Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] := by
rw [two_mul]
convert rdist_triangle hY'₁_meas hX'_meas hY'₂_meas (μ := μA) (μ' := μA) (μ'' := μA)
· exact rdist_symm.trans (hY'₁_ident.rdist_eq hX'_ident).symm
· exact (hX'_ident.rdist_eq hY'₂_ident).symm
rw [← two_nsmul]
linarith [abs_le.mp <| diff_ent_le_rdist hX hY (μ := μ) (μ' := μ')]
/-- If $G$ is a torsion-free group and $X,Y$ are $G$-valued random variables and
$\phi : G\to \mathbb{F}_2^d$ is a homomorphism then
\[\mathbb{H}(\phi(X))\leq 10d[X;Y].\] -/
lemma torsion_dist_shrinking {H : Type u} [FiniteRange X] [FiniteRange Y] (hX : Measurable X)
(hY : Measurable Y) [AddCommGroup H] [ElementaryAddCommGroup H 2]
[MeasurableSpace H] [MeasurableSingletonClass H] [Countable H]
(hG : AddMonoid.IsTorsionFree G) (φ : G →+ H) :
H[φ ∘ X ; μ] ≤ 10 * d[X; μ # Y ; μ'] := by
have :=
calc d[φ ∘ X ; μ # φ ∘ (Y + Y); μ'] ≤ d[X; μ # (Y + Y) ; μ'] := rdist_of_hom_le φ hX (Measurable.add hY hY)
_ ≤ 5 * d[X; μ # Y ; μ'] := torsion_free_doubling X Y μ μ' hX hY hG
have eq_zero : φ ∘ (Y + Y) = fun _ ↦ 0 := by ext x ; simp only [Function.comp_apply, Pi.add_apply,
map_add, ElementaryAddCommGroup.add_self]
rwa [eq_zero, rdist_zero_eq_half_ent, div_le_iff zero_lt_two, mul_assoc, mul_comm _ 2, ←mul_assoc,
show (5*2 : ℝ) = 10 by norm_num] at this
end Torsion
instance {G : Type u} [AddCommGroup G] [Fintype G] [MeasurableSpace G] [MeasurableSingletonClass G] (H : AddSubgroup G)
: MeasurableSingletonClass (G ⧸ H) :=
⟨λ _ ↦ by { rw [measurableSet_quotient]; simp [measurableSet_discrete] }⟩
section F2_projection
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [ElementaryAddCommGroup G 2] [Fintype G] [MeasurableSpace G]
[MeasurableSingletonClass G] {Ω Ω' : Type*}
/-- Let $G=\mathbb{F}_2^n$ and $X,Y$ be $G$-valued random variables such that
\[\mathbb{H}(X)+\mathbb{H}(Y)> (20/\alpha) d[X;Y],\]
for some $\alpha > 0$.
There is a non-trivial subgroup $H\leq G$ such that
\[\log \lvert H\rvert <(1+\alpha)/2 (\mathbb{H}(X)+\mathbb{H}(Y))\] and
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))< \alpha (\mathbb{H}(X)+\mathbb{H}(Y))\]
where $\psi:G\to G/H$ is the natural projection homomorphism.
-/
lemma app_ent_PFR' [MeasureSpace Ω] [MeasureSpace Ω'] (X : Ω → G) (Y : Ω' → G)
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
{α : ℝ} (hent : 20 * d[X # Y] < α * (H[X] + H[Y])) (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X] + H[Y]) ∧
H[(QuotientAddGroup.mk' H) ∘ X] + H[(QuotientAddGroup.mk' H) ∘ Y] < α * (H[X] + H[Y]) := by
let p : refPackage Ω Ω' G := {
X₀₁ := X
X₀₂ := Y
hmeas1 := hX
hmeas2 := hY
η := 1/8
hη := by norm_num
hη' := by norm_num }
obtain ⟨H, Ω'', hΩ'', U, _, hUmeas, hUunif, ineq⟩ := entropic_PFR_conjecture_improv p rfl
let ψ := (QuotientAddGroup.mk' H)
use H
haveI : Finite H := Subtype.finite
-- Note that H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y]
have ent_le : H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y] := calc
H[ψ ∘ X] + H[ψ ∘ Y] ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· exact ent_of_proj_le hX hUmeas hUunif
· exact ent_of_proj_le hY hUmeas hUunif
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- Note that (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y]
have log_sub_le : (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y] := calc
(log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) =
(H[U] - H[X]) + (H[U] - H[Y]) := by
rw [IsUniform.entropy_eq' hUunif hUmeas, SetLike.coe_sort_coe]
_ ≤ |(H[U] - H[X])| + |(H[U] - H[Y])| := by gcongr <;> exact le_abs_self _
_ ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hX
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hY
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- then the conclusion follows from the assumption `hent` and basic inequality manipulations
exact ⟨by linarith, by linarith⟩
variable [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ' : Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
lemma app_ent_PFR (α : ℝ) (hent: 20 * d[X;μ # Y;μ'] < α * (H[X; μ] + H[Y; μ'])) (hX : Measurable X)
(hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ']
< α * (H[ X; μ] + H[Y; μ']) :=
@app_ent_PFR' _ _ _ _ _ _ _ _ (MeasureSpace.mk μ) (MeasureSpace.mk μ') _ _ _ _ α hent hX hY
set_option maxHeartbeats 300000 in
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables and $\alpha < 1$ then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq (1 + α) / (2 * (1 - α)) * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 20/\alpha * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection'
(α : ℝ) (hX : Measurable X) (hY : Measurable Y) (αpos : 0 < α) (αone : α < 1) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (H[X ; μ] + H[Y ; μ']) ∧
α * (H[(QuotientAddGroup.mk' H) ∘ X ; μ] + H[(QuotientAddGroup.mk' H) ∘ Y ; μ']) ≤
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] := by
let S := { H : AddSubgroup G | (∃ (c : ℝ), 0 ≤ c ∧
log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (1 - c) * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
c * (H[X; μ] + H[Y;μ'])) ∧
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] <
α * (H[ (QuotientAddGroup.mk' H) ∘ X; μ ] + H[ (QuotientAddGroup.mk' H) ∘ Y; μ']) }
have : 0 ≤ H[X ; μ] + H[Y ; μ'] := by linarith [entropy_nonneg X μ, entropy_nonneg Y μ']
have : 0 < 1 - α := sub_pos.mpr αone
by_cases hE : (⊥ : AddSubgroup G) ∈ S
· classical
obtain ⟨H, ⟨⟨c, hc, hlog, hup⟩, hent⟩, hMaxl⟩ :=
S.toFinite.exists_maximal_wrt id S (Set.nonempty_of_mem hE)
set ψ : G →+ G ⧸ H := QuotientAddGroup.mk' H
have surj : Function.Surjective ψ := QuotientAddGroup.mk'_surjective H
set G' := G ⧸ H
have : ElementaryAddCommGroup G' 2 := ElementaryAddCommGroup.quotient_group (by decide)
(by simp [AddSubgroup.zero_mem])
obtain ⟨H', hlog', hup'⟩ := app_ent_PFR _ _ _ _ α hent ((measurable_discrete _).comp hX)
((measurable_discrete _).comp hY)
have H_ne_bot: H' ≠ ⊥ := by
by_contra!
rcases this with rfl
have inj : Function.Injective (QuotientAddGroup.mk' (⊥ : AddSubgroup G')) :=
(QuotientAddGroup.quotientBot : (G' ⧸ ⊥) ≃+ G').symm.injective
rw [entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ inj,
entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ inj] at hup'
nlinarith [entropy_nonneg (ψ ∘ X) μ, entropy_nonneg (ψ ∘ Y) μ']
let H'' := H'.comap ψ
use H''
rw [← (AddSubgroup.map_comap_eq_self_of_surjective surj _ : H''.map ψ = H')] at hup' hlog'
set H' := H''.map ψ
have Hlt : H < H'' := by
have : H = (⊥ : AddSubgroup G').comap ψ := by
simp only [ψ, AddMonoidHom.comap_bot, QuotientAddGroup.ker_mk']
rw [this, AddSubgroup.comap_lt_comap_of_surjective surj]
exact Ne.bot_lt H_ne_bot
let φ : G' ⧸ H' ≃+ G ⧸ H'' := QuotientAddGroup.quotientQuotientEquivQuotient H H'' Hlt.le
set ψ' : G' →+ G' ⧸ H' := QuotientAddGroup.mk' H'
set ψ'' : G →+ G ⧸ H'' := QuotientAddGroup.mk' H''
have diag : ψ' ∘ ψ = φ.symm ∘ ψ'' := rfl
rw [← Function.comp.assoc, ← Function.comp.assoc, diag, Function.comp.assoc,
Function.comp.assoc] at hup'
have cond : log (Nat.card H'') ≤
(1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := by
have cardprod : Nat.card H'' = Nat.card H' * Nat.card H := by
have hcard₀ := Nat.card_congr <| (AddSubgroup.addSubgroupOfEquivOfLe Hlt.le).toEquiv
have hcard₁ := Nat.card_congr <|
(QuotientAddGroup.quotientKerEquivRange (ψ.restrict H'')).toEquiv
have hcard₂ := AddSubgroup.card_eq_card_quotient_mul_card_addSubgroup (H.addSubgroupOf H'')
rw [ψ.ker_restrict H'', QuotientAddGroup.ker_mk', ψ.restrict_range H''] at hcard₁
simpa only [← Nat.card_eq_fintype_card, hcard₀, hcard₁] using hcard₂
calc
log (Nat.card H'')
_ = log ((Nat.card H' : ℝ) * (Nat.card H : ℝ)) := by rw [cardprod]; norm_cast
_ = log (Nat.card H') + log (Nat.card H) := by
rw [Real.log_mul (Nat.cast_ne_zero.2 (@Nat.card_pos H').ne')
(Nat.cast_ne_zero.2 (@Nat.card_pos H).ne')]
_ ≤ (1 + α) / 2 * (H[⇑ψ ∘ X ; μ] + H[⇑ψ ∘ Y ; μ']) + log (Nat.card H) := by gcongr
_ ≤ (1 + α) / 2 * (c * (H[X; μ] + H[Y;μ'])) +
(1 + α) / (2 * (1 - α)) * (1 - c) * (H[X ; μ] + H[Y ; μ']) := by gcongr
_ = (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X ; μ] + H[Y ; μ']) := by
field_simp; ring
have HS : H'' ∉ S := λ Hs => Hlt.ne (hMaxl H'' Hs Hlt.le)
simp only [S, Set.mem_setOf_eq, not_and, not_lt] at HS
refine ⟨?_, HS ⟨α * c, by positivity, cond, ?_⟩⟩
· calc
log (Nat.card H'')
_ ≤ (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := cond
_ ≤ (1 + α) / (2 * (1 - α)) * 1 * (H[X; μ] + H[Y;μ']) := by gcongr; simp; positivity
_ = (1 + α) / (2 * (1 - α)) * (H[X; μ] + H[Y;μ']) := by simp only [mul_one]
· calc
H[ ψ'' ∘ X; μ ] + H[ ψ'' ∘ Y; μ' ]
_ = H[ φ.symm ∘ ψ'' ∘ X; μ ] + H[ φ.symm ∘ ψ'' ∘ Y; μ' ] := by
simp_rw [← entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ φ.symm.injective,
← entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ φ.symm.injective]
_ ≤ α * (H[ ψ ∘ X; μ ] + H[ ψ ∘ Y; μ' ]) := hup'.le
_ ≤ α * (c * (H[X ; μ] + H[Y ; μ'])) := by gcongr
_ = (α * c) * (H[X ; μ] + H[Y ; μ']) := by ring
· use ⊥
constructor
· simp only [AddSubgroup.mem_bot, Nat.card_eq_fintype_card, Fintype.card_ofSubsingleton,
Nat.cast_one, log_one]
positivity
· simp only [S, Set.mem_setOf_eq, not_and, not_lt] at hE
exact hE ⟨1, by norm_num, by
norm_num; exact add_le_add (entropy_comp_le μ hX _) (entropy_comp_le μ' hY _)⟩
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq 2 * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 34 * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
34 * d[(QuotientAddGroup.mk' H) ∘ X;μ # (QuotientAddGroup.mk' H) ∘ Y;μ'] := by
rcases PFR_projection' X Y μ μ' ((3 : ℝ) / 5) hX hY (by norm_num) (by norm_num) with ⟨H, h, h'⟩
refine ⟨H, ?_, ?_⟩
· convert h
norm_num
· have : 0 ≤ d[⇑(QuotientAddGroup.mk' H) ∘ X ; μ # ⇑(QuotientAddGroup.mk' H) ∘ Y ; μ'] :=
rdist_nonneg ((measurable_discrete _).comp hX) ((measurable_discrete _).comp hY)
linarith
end F2_projection
open MeasureTheory ProbabilityTheory Real Set
open scoped BigOperators
lemma four_logs {a b c d : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) (hd : 0 < d) :
log ((a*b)/(c*d)) = log a + log b - log c - log d := by
rw [log_div, log_mul, log_mul, sub_sub] <;> positivity
| lemma sum_prob_preimage {G H : Type*} {X : Finset H} {A : Set G} [Finite A] {φ : A → X}
{A_ : H → Set G} (hA : A.Nonempty) (hφ : ∀ x : X, A_ x = Subtype.val '' (φ ⁻¹' {x})) :
∑ x in X, (Nat.card (A_ x) : ℝ) / (Nat.card A) = 1 | sum_prob_preimage | 25309ad 20231211 | c0c547a 20240116 | pfr/PFR/WeakPFR.lean | {
"lineInFile": 424,
"tokenPositionInFile": 23253,
"theoremPositionInFile": 13
} | {
"inFilePremises": false,
"repositoryPremises": false
} | {
"hasProof": true,
"proof": "by\n rw [← Finset.sum_div]\n apply (div_eq_one_iff_eq <| Nat.cast_ne_zero.mpr <| Nat.pos_iff_ne_zero.mp (@Nat.card_pos _ hA.to_subtype _)).mpr\n classical\n haveI := Fintype.ofFinite A\n rewrite [Nat.card_eq_fintype_card, ← Finset.card_univ, Finset.card_eq_sum_card_fiberwise\n <| fun a _ ↦ Finset.mem_univ (φ a), ← Finset.sum_coe_sort]\n norm_cast\n congr; ext\n rewrite [← Set.Finite.toFinset_setOf, (Set.toFinite _).card_toFinset, ← Nat.card_eq_fintype_card,\n hφ, Nat.card_image_of_injective Subtype.val_injective]; rfl",
"proofType": "tactic",
"proofLengthLines": 11,
"proofLengthTokens": 527
} | pfr |
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Quotient
import Mathlib.GroupTheory.Torsion
import Mathlib.GroupTheory.Torsion
import Mathlib.LinearAlgebra.FreeModule.PID
import PFR.Mathlib.Data.Set.Pointwise.SMul
import PFR.EntropyPFR
import PFR.ImprovedPFR
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Mathlib.GroupTheory.Torsion
/-!
# Weak PFR over the integers
Here we use the entropic form of PFR to deduce a weak form of PFR over the integers.
## Main statement
* `weak_PFR_int`: Let $A\subseteq \mathbb{Z}^d$ and $\lvert A+A\rvert\leq K\lvert A\rvert$.
There exists $A'\subseteq A$ such that $\lvert A'\rvert \geq K^{-17}\lvert A\rvert$ and
$\dim A' \leq (40/\log 2)\log K$.
-/
section AddCommGroup
variable {G : Type*} [AddCommGroup G] {A B : Set G}
open Set
open scoped Pointwise
def IsShift (A B : Set G) : Prop := ∃ x : G, A = x +ᵥ B
lemma IsShift.sub_self_congr : IsShift A B → A - A = B - B := by
rintro ⟨x, rfl⟩; simp [vadd_sub_vadd_comm, singleton_zero]
lemma IsShift.card_congr : IsShift A B → Nat.card A = Nat.card B := by rintro ⟨x, rfl⟩; simp
/-- The property of two sets A, B of a group G not being contained in cosets of the same proper
subgroup -/
def NotInCoset (A B : Set G) : Prop := AddSubgroup.closure ((A - A) ∪ (B - B)) = ⊤
/-- Without loss of generality, one can move (up to translation and embedding) any pair A, B of non-empty sets into a subgroup where they are not in a coset. -/
lemma wlog_notInCoset (hA : A.Nonempty) (hB : B.Nonempty) :
∃ (G' : AddSubgroup G) (A' B' : Set G'), IsShift A A' ∧ IsShift B B' ∧ NotInCoset A' B' := by
obtain ⟨x, hx⟩ := hA
obtain ⟨y, hy⟩ := hB
set G' := AddSubgroup.closure ((A - A) ∪ (B - B))
set A' : Set G' := (↑) ⁻¹' ((-x) +ᵥ A)
set B' : Set G' := (↑) ⁻¹' ((-y) +ᵥ B)
have hxA : -x +ᵥ A ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hx).trans $ (subset_union_left ..).trans
AddSubgroup.subset_closure
have hyB : -y +ᵥ B ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hy).trans $ (subset_union_right ..).trans
AddSubgroup.subset_closure
have hA : IsShift A A' := ⟨x, by rw [Set.image_preimage_eq_of_subset hxA, vadd_neg_vadd]⟩
have hB : IsShift B B' := ⟨y, by rw [Set.image_preimage_eq_of_subset hyB, vadd_neg_vadd]⟩
refine ⟨G', A', B', hA, hB, ?_⟩
unfold NotInCoset
convert AddSubgroup.closure_preimage_eq_top ((A - A) ∪ (B - B))
simp_rw [preimage_union, hA.sub_self_congr, hB.sub_self_congr]
rw [preimage_sub, preimage_sub]
simp [A', B', preimage_image_preimage]
all_goals apply_rules [Subtype.coe_injective, (image_preimage_subset ..).trans, hxA, hyB]
end AddCommGroup
section Torsion
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [MeasurableSpace G] [MeasurableSingletonClass G]
[Countable G] {Ω Ω' : Type u} [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ': Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
/-- If $G$ is torsion-free and $X,Y$ are $G$-valued random variables then $d[X;2Y]\leq 5d[X;Y]$. -/
lemma torsion_free_doubling [FiniteRange X] [FiniteRange Y]
(hX : Measurable X) (hY : Measurable Y) (hG : AddMonoid.IsTorsionFree G) :
d[X ; μ # (Y + Y) ; μ'] ≤ 5 * d[X; μ # Y ; μ'] := by
obtain ⟨A, mA, μA, X', Y'₁, Y'₂, hμA, h_indep, hX'_meas, hY'₁_meas, hY'₂_meas, hX'_ident,
hY'₁_ident, hY'₂_ident, _, _, _⟩ := independent_copies3_nondep_finiteRange hX hY hY μ μ' μ'
have h_meas (i : Fin 3) : Measurable (![X', Y'₁, Y'₂] i) := by fin_cases i <;> assumption
haveI : NoZeroSMulDivisors ℕ G := hG.noZeroNsmulDivisors
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨x, y₁, y₂⟩ ↦ (x, y₁ - y₂, x - 2 • y₁)
show H[f ∘ ⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] = _
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hX'_meas <| Measurable.prod hY'₁_meas hY'₂_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun X' (prod Y'₁ Y'₂) μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 1 2 0 (by decide) (by decide)
rw [this.entropy_pair_eq_add hX'_meas (by exact Measurable.prod hY'₁_meas hY'₂_meas),
IndepFun.entropy_pair_eq_add hY'₁_meas hY'₂_meas (h_indep.indepFun (show 1 ≠ 2 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, two_mul]
have : H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[X ; μ] + H[Y ; μ'] := calc
H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[⟨X', Y'₁⟩ ; μA] := by
let f : G × G → G × G := fun ⟨x, y₁⟩ ↦ (x, x - 2 • y₁)
show H[f ∘ ⟨X', Y'₁⟩ ; μA] = _
apply entropy_comp_of_injective μA (by exact Measurable.prod hX'_meas hY'₁_meas) f
exact fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + H[Y ; μ'] := by
rw [IndepFun.entropy_pair_eq_add hX'_meas hY'₁_meas (h_indep.indepFun (show 0 ≠ 1 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq]
let f : G × G → G × G := fun ⟨x, y⟩ ↦ (x, y - x)
have hf : f.Injective := fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all
have : H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] := calc
H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] = H[f ∘ ⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
show _ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂ - (Y'₁ - Y'₂)⟩ ; μA]
rw [sub_sub_sub_cancel_right, ← sub_add_eq_sub_sub, two_nsmul]
_ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
refine entropy_comp_of_injective μA (Measurable.prod ?_ ?_) f hf
· exact Measurable.sub hY'₁_meas hY'₂_meas
· exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
_ ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] :=
entropy_pair_le_add (hY'₁_meas.sub' hY'₂_meas) (hX'_meas.sub' hY'₁_meas |>.sub' hY'₂_meas) μA
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] + H[X' - 2 • Y'₁ ; μA] ≤
H[⟨X', X' - 2 • Y'₁⟩ ; μA] + H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] := by
haveI : FiniteRange (Y'₁ - Y'₂) := FiniteRange.sub Y'₁ Y'₂
haveI : FiniteRange (2 • Y'₁) := by show FiniteRange ((fun x ↦ 2 • x) ∘ Y'₁); infer_instance
apply entropy_triple_add_entropy_le μA hX'_meas (Measurable.sub hY'₁_meas hY'₂_meas)
exact Measurable.sub' hX'_meas <| Measurable.const_smul hY'₁_meas 2
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨y₁, y₂, x⟩ ↦ (y₁, y₂, x - y₁ - y₂)
show H[f ∘ ⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA]
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hY'₁_meas <| Measurable.prod hY'₂_meas hX'_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun Y'₁ (prod Y'₂ X') μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 2 0 1 (by decide) (by decide)
rw [this.entropy_pair_eq_add hY'₁_meas (by exact Measurable.prod hY'₂_meas hX'_meas),
IndepFun.entropy_pair_eq_add hY'₂_meas hX'_meas (h_indep.indepFun (show 2 ≠ 0 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq]
group
have : H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₂ ; μA] := calc
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₁, X' - Y'₂⟩ ; μA] := by rw [sub_right_comm] ; rfl
_ = H[⟨Y'₁, X' - Y'₂⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₁_meas <| Measurable.sub hX'_meas hY'₂_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₂ ; μA] := by
haveI : FiniteRange (X' - Y'₂) := FiniteRange.sub X' Y'₂
convert IndepFun.entropy_pair_eq_add hY'₁_meas (hX'_meas.sub hY'₂_meas)
<| h_indep.indepFun_sub_right h_meas 1 0 2 (by decide) (by decide)
exact hY'₁_ident.entropy_eq.symm
have : H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₁ ; μA] := calc
H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₂, X' - Y'₁⟩ ; μA] := rfl
_ = H[⟨Y'₂, X' - Y'₁⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₂_meas <| Measurable.sub hX'_meas hY'₁_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₁ ; μA] := by
haveI : FiniteRange (X' - Y'₁) := FiniteRange.sub X' Y'₁
convert IndepFun.entropy_pair_eq_add hY'₂_meas (hX'_meas.sub hY'₁_meas)
<| h_indep.indepFun_sub_right h_meas 2 0 1 (by decide) (by decide)
exact hY'₂_ident.entropy_eq.symm
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] ≤
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] + H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
apply entropy_triple_add_entropy_le μA hY'₁_meas hY'₂_meas
exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
have : H[X' - Y'₁ - Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := calc
H[X' - Y'₁ - Y'₂ ; μA] ≤ H[X' - Y'₁ ; μA] + H[X' - Y'₂ ; μA] - H[X ; μ] := by linarith
_ = 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := by
nth_rw 1 [two_mul, ← hX'_ident.rdist_eq hY'₁_ident, ← hX'_ident.rdist_eq hY'₂_ident]
have h1 : d[X' ; μA # Y'₁ ; μA] = H[X' - Y'₁ ; μA] - H[X' ; μA] / 2 - H[Y'₁ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 1 by decide)).rdist_eq hX'_meas hY'₁_meas
have h2 : d[X' ; μA # Y'₂ ; μA] = H[X' - Y'₂ ; μA] - H[X' ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 2 by decide)).rdist_eq hX'_meas hY'₂_meas
rw [h1, h2, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, hX'_ident.entropy_eq]
group
have : d[X ; μ # 2 • Y ; μ'] ≤
d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := calc
d[X ; μ # 2 • Y ; μ'] = H[X' - 2 • Y'₁ ; μA] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by
have h2Y_ident : IdentDistrib (2 • Y'₁) (2 • Y) (μ := μA) (ν := μ') := by
convert hY'₁_ident.comp <| measurable_discrete <| fun g ↦ 2 • g
have h2Y_indep : IndepFun X' (2 • Y'₁) (μ := μA) := by
convert (h_indep.indepFun (show 0 ≠ 1 by decide)).comp measurable_id
(measurable_const_smul 2)
rw [← hX'_ident.rdist_eq h2Y_ident,
h2Y_indep.rdist_eq hX'_meas <| Measurable.const_smul hY'₁_meas 2,
hX'_ident.entropy_eq, h2Y_ident.entropy_eq]
_ ≤ H[Y'₁ - Y'₂ ; μA] + 2 * d[X ; μ # Y ; μ'] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by linarith
_ = d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := by
have H2Y : H[2 • Y ; μ'] = H[Y ; μ'] := by
let f (g : G) := 2 • g
exact entropy_comp_of_injective μ' hY f (fun _ _ ↦ by simp [f, smul_right_inj])
have : d[Y'₁ ; μA # Y'₂ ; μA] = H[Y'₁ - Y'₂ ; μA] - H[Y'₁ ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 1 ≠ 2 by decide)).rdist_eq hY'₁_meas hY'₂_meas
rw [this, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, H2Y]
group
have : d[Y'₁ ; μA # Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] := by
rw [two_mul]
convert rdist_triangle hY'₁_meas hX'_meas hY'₂_meas (μ := μA) (μ' := μA) (μ'' := μA)
· exact rdist_symm.trans (hY'₁_ident.rdist_eq hX'_ident).symm
· exact (hX'_ident.rdist_eq hY'₂_ident).symm
rw [← two_nsmul]
linarith [abs_le.mp <| diff_ent_le_rdist hX hY (μ := μ) (μ' := μ')]
/-- If $G$ is a torsion-free group and $X,Y$ are $G$-valued random variables and
$\phi : G\to \mathbb{F}_2^d$ is a homomorphism then
\[\mathbb{H}(\phi(X))\leq 10d[X;Y].\] -/
lemma torsion_dist_shrinking {H : Type u} [FiniteRange X] [FiniteRange Y] (hX : Measurable X)
(hY : Measurable Y) [AddCommGroup H] [ElementaryAddCommGroup H 2]
[MeasurableSpace H] [MeasurableSingletonClass H] [Countable H]
(hG : AddMonoid.IsTorsionFree G) (φ : G →+ H) :
H[φ ∘ X ; μ] ≤ 10 * d[X; μ # Y ; μ'] := by
have :=
calc d[φ ∘ X ; μ # φ ∘ (Y + Y); μ'] ≤ d[X; μ # (Y + Y) ; μ'] := rdist_of_hom_le φ hX (Measurable.add hY hY)
_ ≤ 5 * d[X; μ # Y ; μ'] := torsion_free_doubling X Y μ μ' hX hY hG
have eq_zero : φ ∘ (Y + Y) = fun _ ↦ 0 := by ext x ; simp only [Function.comp_apply, Pi.add_apply,
map_add, ElementaryAddCommGroup.add_self]
rwa [eq_zero, rdist_zero_eq_half_ent, div_le_iff zero_lt_two, mul_assoc, mul_comm _ 2, ←mul_assoc,
show (5*2 : ℝ) = 10 by norm_num] at this
end Torsion
instance {G : Type u} [AddCommGroup G] [Fintype G] [MeasurableSpace G] [MeasurableSingletonClass G] (H : AddSubgroup G)
: MeasurableSingletonClass (G ⧸ H) :=
⟨λ _ ↦ by { rw [measurableSet_quotient]; simp [measurableSet_discrete] }⟩
section F2_projection
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [ElementaryAddCommGroup G 2] [Fintype G] [MeasurableSpace G]
[MeasurableSingletonClass G] {Ω Ω' : Type*}
/-- Let $G=\mathbb{F}_2^n$ and $X,Y$ be $G$-valued random variables such that
\[\mathbb{H}(X)+\mathbb{H}(Y)> (20/\alpha) d[X;Y],\]
for some $\alpha > 0$.
There is a non-trivial subgroup $H\leq G$ such that
\[\log \lvert H\rvert <(1+\alpha)/2 (\mathbb{H}(X)+\mathbb{H}(Y))\] and
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))< \alpha (\mathbb{H}(X)+\mathbb{H}(Y))\]
where $\psi:G\to G/H$ is the natural projection homomorphism.
-/
lemma app_ent_PFR' [MeasureSpace Ω] [MeasureSpace Ω'] (X : Ω → G) (Y : Ω' → G)
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
{α : ℝ} (hent : 20 * d[X # Y] < α * (H[X] + H[Y])) (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X] + H[Y]) ∧
H[(QuotientAddGroup.mk' H) ∘ X] + H[(QuotientAddGroup.mk' H) ∘ Y] < α * (H[X] + H[Y]) := by
let p : refPackage Ω Ω' G := {
X₀₁ := X
X₀₂ := Y
hmeas1 := hX
hmeas2 := hY
η := 1/8
hη := by norm_num
hη' := by norm_num }
obtain ⟨H, Ω'', hΩ'', U, _, hUmeas, hUunif, ineq⟩ := entropic_PFR_conjecture_improv p rfl
let ψ := (QuotientAddGroup.mk' H)
use H
haveI : Finite H := Subtype.finite
-- Note that H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y]
have ent_le : H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y] := calc
H[ψ ∘ X] + H[ψ ∘ Y] ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· exact ent_of_proj_le hX hUmeas hUunif
· exact ent_of_proj_le hY hUmeas hUunif
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- Note that (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y]
have log_sub_le : (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y] := calc
(log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) =
(H[U] - H[X]) + (H[U] - H[Y]) := by
rw [IsUniform.entropy_eq' hUunif hUmeas, SetLike.coe_sort_coe]
_ ≤ |(H[U] - H[X])| + |(H[U] - H[Y])| := by gcongr <;> exact le_abs_self _
_ ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hX
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hY
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- then the conclusion follows from the assumption `hent` and basic inequality manipulations
exact ⟨by linarith, by linarith⟩
variable [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ' : Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
lemma app_ent_PFR (α : ℝ) (hent: 20 * d[X;μ # Y;μ'] < α * (H[X; μ] + H[Y; μ'])) (hX : Measurable X)
(hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ']
< α * (H[ X; μ] + H[Y; μ']) :=
@app_ent_PFR' _ _ _ _ _ _ _ _ (MeasureSpace.mk μ) (MeasureSpace.mk μ') _ _ _ _ α hent hX hY
set_option maxHeartbeats 300000 in
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables and $\alpha < 1$ then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq (1 + α) / (2 * (1 - α)) * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 20/\alpha * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection'
(α : ℝ) (hX : Measurable X) (hY : Measurable Y) (αpos : 0 < α) (αone : α < 1) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (H[X ; μ] + H[Y ; μ']) ∧
α * (H[(QuotientAddGroup.mk' H) ∘ X ; μ] + H[(QuotientAddGroup.mk' H) ∘ Y ; μ']) ≤
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] := by
let S := { H : AddSubgroup G | (∃ (c : ℝ), 0 ≤ c ∧
log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (1 - c) * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
c * (H[X; μ] + H[Y;μ'])) ∧
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] <
α * (H[ (QuotientAddGroup.mk' H) ∘ X; μ ] + H[ (QuotientAddGroup.mk' H) ∘ Y; μ']) }
have : 0 ≤ H[X ; μ] + H[Y ; μ'] := by linarith [entropy_nonneg X μ, entropy_nonneg Y μ']
have : 0 < 1 - α := sub_pos.mpr αone
by_cases hE : (⊥ : AddSubgroup G) ∈ S
· classical
obtain ⟨H, ⟨⟨c, hc, hlog, hup⟩, hent⟩, hMaxl⟩ :=
S.toFinite.exists_maximal_wrt id S (Set.nonempty_of_mem hE)
set ψ : G →+ G ⧸ H := QuotientAddGroup.mk' H
have surj : Function.Surjective ψ := QuotientAddGroup.mk'_surjective H
set G' := G ⧸ H
have : ElementaryAddCommGroup G' 2 := ElementaryAddCommGroup.quotient_group (by decide)
(by simp [AddSubgroup.zero_mem])
obtain ⟨H', hlog', hup'⟩ := app_ent_PFR _ _ _ _ α hent ((measurable_discrete _).comp hX)
((measurable_discrete _).comp hY)
have H_ne_bot: H' ≠ ⊥ := by
by_contra!
rcases this with rfl
have inj : Function.Injective (QuotientAddGroup.mk' (⊥ : AddSubgroup G')) :=
(QuotientAddGroup.quotientBot : (G' ⧸ ⊥) ≃+ G').symm.injective
rw [entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ inj,
entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ inj] at hup'
nlinarith [entropy_nonneg (ψ ∘ X) μ, entropy_nonneg (ψ ∘ Y) μ']
let H'' := H'.comap ψ
use H''
rw [← (AddSubgroup.map_comap_eq_self_of_surjective surj _ : H''.map ψ = H')] at hup' hlog'
set H' := H''.map ψ
have Hlt : H < H'' := by
have : H = (⊥ : AddSubgroup G').comap ψ := by
simp only [ψ, AddMonoidHom.comap_bot, QuotientAddGroup.ker_mk']
rw [this, AddSubgroup.comap_lt_comap_of_surjective surj]
exact Ne.bot_lt H_ne_bot
let φ : G' ⧸ H' ≃+ G ⧸ H'' := QuotientAddGroup.quotientQuotientEquivQuotient H H'' Hlt.le
set ψ' : G' →+ G' ⧸ H' := QuotientAddGroup.mk' H'
set ψ'' : G →+ G ⧸ H'' := QuotientAddGroup.mk' H''
have diag : ψ' ∘ ψ = φ.symm ∘ ψ'' := rfl
rw [← Function.comp.assoc, ← Function.comp.assoc, diag, Function.comp.assoc,
Function.comp.assoc] at hup'
have cond : log (Nat.card H'') ≤
(1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := by
have cardprod : Nat.card H'' = Nat.card H' * Nat.card H := by
have hcard₀ := Nat.card_congr <| (AddSubgroup.addSubgroupOfEquivOfLe Hlt.le).toEquiv
have hcard₁ := Nat.card_congr <|
(QuotientAddGroup.quotientKerEquivRange (ψ.restrict H'')).toEquiv
have hcard₂ := AddSubgroup.card_eq_card_quotient_mul_card_addSubgroup (H.addSubgroupOf H'')
rw [ψ.ker_restrict H'', QuotientAddGroup.ker_mk', ψ.restrict_range H''] at hcard₁
simpa only [← Nat.card_eq_fintype_card, hcard₀, hcard₁] using hcard₂
calc
log (Nat.card H'')
_ = log ((Nat.card H' : ℝ) * (Nat.card H : ℝ)) := by rw [cardprod]; norm_cast
_ = log (Nat.card H') + log (Nat.card H) := by
rw [Real.log_mul (Nat.cast_ne_zero.2 (@Nat.card_pos H').ne')
(Nat.cast_ne_zero.2 (@Nat.card_pos H).ne')]
_ ≤ (1 + α) / 2 * (H[⇑ψ ∘ X ; μ] + H[⇑ψ ∘ Y ; μ']) + log (Nat.card H) := by gcongr
_ ≤ (1 + α) / 2 * (c * (H[X; μ] + H[Y;μ'])) +
(1 + α) / (2 * (1 - α)) * (1 - c) * (H[X ; μ] + H[Y ; μ']) := by gcongr
_ = (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X ; μ] + H[Y ; μ']) := by
field_simp; ring
have HS : H'' ∉ S := λ Hs => Hlt.ne (hMaxl H'' Hs Hlt.le)
simp only [S, Set.mem_setOf_eq, not_and, not_lt] at HS
refine ⟨?_, HS ⟨α * c, by positivity, cond, ?_⟩⟩
· calc
log (Nat.card H'')
_ ≤ (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := cond
_ ≤ (1 + α) / (2 * (1 - α)) * 1 * (H[X; μ] + H[Y;μ']) := by gcongr; simp; positivity
_ = (1 + α) / (2 * (1 - α)) * (H[X; μ] + H[Y;μ']) := by simp only [mul_one]
· calc
H[ ψ'' ∘ X; μ ] + H[ ψ'' ∘ Y; μ' ]
_ = H[ φ.symm ∘ ψ'' ∘ X; μ ] + H[ φ.symm ∘ ψ'' ∘ Y; μ' ] := by
simp_rw [← entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ φ.symm.injective,
← entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ φ.symm.injective]
_ ≤ α * (H[ ψ ∘ X; μ ] + H[ ψ ∘ Y; μ' ]) := hup'.le
_ ≤ α * (c * (H[X ; μ] + H[Y ; μ'])) := by gcongr
_ = (α * c) * (H[X ; μ] + H[Y ; μ']) := by ring
· use ⊥
constructor
· simp only [AddSubgroup.mem_bot, Nat.card_eq_fintype_card, Fintype.card_ofSubsingleton,
Nat.cast_one, log_one]
positivity
· simp only [S, Set.mem_setOf_eq, not_and, not_lt] at hE
exact hE ⟨1, by norm_num, by
norm_num; exact add_le_add (entropy_comp_le μ hX _) (entropy_comp_le μ' hY _)⟩
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq 2 * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 34 * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
34 * d[(QuotientAddGroup.mk' H) ∘ X;μ # (QuotientAddGroup.mk' H) ∘ Y;μ'] := by
rcases PFR_projection' X Y μ μ' ((3 : ℝ) / 5) hX hY (by norm_num) (by norm_num) with ⟨H, h, h'⟩
refine ⟨H, ?_, ?_⟩
· convert h
norm_num
· have : 0 ≤ d[⇑(QuotientAddGroup.mk' H) ∘ X ; μ # ⇑(QuotientAddGroup.mk' H) ∘ Y ; μ'] :=
rdist_nonneg ((measurable_discrete _).comp hX) ((measurable_discrete _).comp hY)
linarith
end F2_projection
open MeasureTheory ProbabilityTheory Real Set
open scoped BigOperators
lemma four_logs {a b c d : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) (hd : 0 < d) :
log ((a*b)/(c*d)) = log a + log b - log c - log d := by
rw [log_div, log_mul, log_mul, sub_sub] <;> positivity
lemma sum_prob_preimage {G H : Type*} {X : Finset H} {A : Set G} [Finite A] {φ : A → X}
{A_ : H → Set G} (hA : A.Nonempty) (hφ : ∀ x : X, A_ x = Subtype.val '' (φ ⁻¹' {x})) :
∑ x in X, (Nat.card (A_ x) : ℝ) / (Nat.card A) = 1 := by
rw [← Finset.sum_div]
apply (div_eq_one_iff_eq <| Nat.cast_ne_zero.mpr <| Nat.pos_iff_ne_zero.mp (@Nat.card_pos _ hA.to_subtype _)).mpr
classical
haveI := Fintype.ofFinite A
rewrite [Nat.card_eq_fintype_card, ← Finset.card_univ, Finset.card_eq_sum_card_fiberwise
<| fun a _ ↦ Finset.mem_univ (φ a), ← Finset.sum_coe_sort]
norm_cast
congr; ext
rewrite [← Set.Finite.toFinset_setOf, (Set.toFinite _).card_toFinset, ← Nat.card_eq_fintype_card,
hφ, Nat.card_image_of_injective Subtype.val_injective]; rfl
/-- Let $\phi : G\to H$ be a homomorphism and $A,B\subseteq G$ be finite subsets. If $x,y\in H$ then let $A_x=A\cap \phi^{-1}(x)$ and $B_y=B\cap \phi^{-1}(y)$. There exist $x,y\in H$ such that $A_x,B_y$ are both non-empty and
\[d[\phi(U_A);\phi(U_B)]\log \frac{\lvert A\rvert\lvert B\rvert}{\lvert A_x\rvert\lvert B_y\rvert}\leq (\mathbb{H}(\phi(U_A))+\mathbb{H}(\phi(U_B)))(d(U_A,U_B)-d(U_{A_x},U_{B_y}).\] -/
| lemma single_fibres {G H Ω Ω': Type u}
[AddCommGroup G] [Countable G] [MeasurableSpace G] [MeasurableSingletonClass G]
[AddCommGroup H] [Countable H] [MeasurableSpace H] [MeasurableSingletonClass H]
[MeasureSpace Ω] [MeasureSpace Ω']
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
(φ : G →+ H)
{A B : Set G} [Finite A] [Finite B] {UA : Ω → G} {UB: Ω' → G} (hA : A.Nonempty) (hB : B.Nonempty)
(hUA': Measurable UA) (hUB': Measurable UB) (hUA: IsUniform A UA) (hUB: IsUniform B UB)
(hUA_mem : ∀ ω, UA ω ∈ A) (hUB_mem : ∀ ω, UB ω ∈ B) :
∃ (x y : H) (Ax By: Set G),
Ax = A ∩ φ.toFun ⁻¹' {x} ∧ By = B ∩ φ.toFun ⁻¹' {y} ∧ Ax.Nonempty ∧ By.Nonempty ∧
d[φ.toFun ∘ UA # φ.toFun ∘ UB]
* log ((Nat.card A) * (Nat.card B) / ((Nat.card Ax) * (Nat.card By))) ≤
(H[φ.toFun ∘ UA] + H[φ.toFun ∘ UB]) * (d[UA # UB] - dᵤ[Ax # By]) | single_fibres | 25309ad 20231211 | 58758d0 20240119 | pfr/PFR/WeakPFR.lean | {
"lineInFile": 440,
"tokenPositionInFile": 24430,
"theoremPositionInFile": 14
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n have : Nonempty A := hA.to_subtype\n have : Nonempty B := hB.to_subtype\n haveI : FiniteRange UA := finiteRange_of_finset UA A.toFinite.toFinset (by simpa)\n haveI : FiniteRange UB := finiteRange_of_finset UB B.toFinite.toFinset (by simpa)\n have hUA_coe : IsUniform A.toFinite.toFinset.toSet UA := by rwa [Set.Finite.coe_toFinset]\n have hUB_coe : IsUniform B.toFinite.toFinset.toSet UB := by rwa [Set.Finite.coe_toFinset]\n\n let A_ (x : H) : Set G := A ∩ φ.toFun ⁻¹' {x}\n let B_ (y : H) : Set G := B ∩ φ.toFun ⁻¹' {y}\n let X : Finset H := FiniteRange.toFinset (φ.toFun ∘ UA)\n let Y : Finset H := FiniteRange.toFinset (φ.toFun ∘ UB)\n\n haveI h_Ax (x : X) : Nonempty (A_ x.val) := by\n obtain ⟨ω, hω⟩ := (FiniteRange.mem_iff _ _).mp x.property\n use UA ω; exact Set.mem_inter (hUA_mem ω) (by exact hω)\n haveI h_By (y : Y) : Nonempty (B_ y.val) := by\n obtain ⟨ω, hω⟩ := (FiniteRange.mem_iff _ _).mp y.property\n use UB ω; exact Set.mem_inter (hUB_mem ω) (by exact hω)\n have h_AX (a : A) : φ.toFun a.val ∈ X := by\n obtain ⟨ω, hω⟩ := hUA_coe.nonempty_preimage_of_mem hUA' (A.toFinite.mem_toFinset.mpr a.property)\n exact (FiniteRange.mem_iff _ (φ.toFun a.val)).mpr ⟨ω, congr_arg _ hω⟩\n have h_BY (b : B) : φ.toFun b.val ∈ Y := by\n obtain ⟨ω, hω⟩ := hUB_coe.nonempty_preimage_of_mem hUB' (B.toFinite.mem_toFinset.mpr b.property)\n exact (FiniteRange.mem_iff _ (φ.toFun b.val)).mpr ⟨ω, congr_arg _ hω⟩\n\n let φ_AX (a : A) : X := by use φ.toFun a.val; exact h_AX a\n let φ_BY (b : B) : Y := by use φ.toFun b.val; exact h_BY b\n have h_φ_AX (x : X) : A_ x.val = φ_AX ⁻¹' {x} := by ext; simp [A_, φ_AX]; simp [Subtype.ext_iff]\n have h_φ_BY (y : Y) : B_ y.val = φ_BY ⁻¹' {y} := by ext; simp [B_, φ_BY]; simp [Subtype.ext_iff]\n\n let p (x : H) (y : H) : ℝ :=\n (Nat.card (A_ x).Elem) * (Nat.card (B_ y).Elem) / ((Nat.card A.Elem) * (Nat.card B.Elem))\n have :\n ∑ x in X, ∑ y in Y, (p x y) * dᵤ[A_ x # B_ y] ≤ d[UA # UB] - d[φ.toFun ∘ UA # φ.toFun ∘ UB] :=\n calc\n _ = d[UA | φ.toFun ∘ UA # UB | φ.toFun ∘ UB] := by\n rewrite [condRuzsaDist_eq_sum hUA' ((measurable_discrete _).comp hUA')\n hUB' ((measurable_discrete _).comp hUB')]\n refine Finset.sum_congr rfl <| fun x hx ↦ Finset.sum_congr rfl <| fun y hy ↦ ?_\n haveI : Nonempty (A_ x) := h_Ax ⟨x, hx⟩\n haveI : Nonempty (B_ y) := h_By ⟨y, hy⟩\n let μx := (ℙ : Measure Ω)[|(φ.toFun ∘ UA) ⁻¹' {x}]\n let μy := (ℙ : Measure Ω')[|(φ.toFun ∘ UB) ⁻¹' {y}]\n have h_μ_p : IsProbabilityMeasure μx ∧ IsProbabilityMeasure μy := by\n constructor <;> apply ProbabilityTheory.cond_isProbabilityMeasure <;> rw [Set.preimage_comp]\n refine @IsUniform.measure_preimage_ne_zero _ _ _ _ _ _ _ _ _ _ hUA_coe hUA' _ ?_\n swap; refine @IsUniform.measure_preimage_ne_zero _ _ _ _ _ _ _ _ _ _ hUB_coe hUB' _ ?_\n all_goals rwa [Set.inter_comm, Set.Finite.coe_toFinset]\n have h_μ_unif : IsUniform (A_ x) UA μx ∧ IsUniform (B_ y) UB μy := by\n have : _ ∧ _ := ⟨hUA.restrict hUA' (φ.toFun ⁻¹' {x}), hUB.restrict hUB' (φ.toFun ⁻¹' {y})⟩\n rwa [Set.inter_comm _ A, Set.inter_comm _ B] at this\n rewrite [rdist_set_eq_rdist h_μ_p.1 h_μ_p.2 h_μ_unif.1 h_μ_unif.2 hUA' hUB']\n show _ = (Measure.real _ (UA ⁻¹' (_ ⁻¹' _))) * (Measure.real _ (UB ⁻¹' (_ ⁻¹' _))) * _\n rewrite [hUA_coe.measureReal_preimage hUA', hUB_coe.measureReal_preimage hUB']\n simp_rw [p, A_, B_, IsProbabilityMeasure.measureReal_univ, one_mul]\n rewrite [mul_div_mul_comm, Set.inter_comm A, Set.inter_comm B]\n simp only [Set.Finite.coe_toFinset, Set.Finite.mem_toFinset, Finset.mem_val]; rfl\n _ ≤ d[UA # UB] - d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by\n rewrite [ZeroHom.toFun_eq_coe, AddMonoidHom.toZeroHom_coe]\n linarith only [rdist_le_sum_fibre φ hUA' hUB' (μ := ℙ) (μ' := ℙ)]\n let M := H[φ.toFun ∘ UA] + H[φ.toFun ∘ UB]\n have hM : M = ∑ x in X, ∑ y in Y, Real.negMulLog (p x y) := by\n have h_compl {x y} (h_notin : (x, y) ∉ X ×ˢ Y) : Real.negMulLog (p x y) = 0 := by\n unfold_let p; beta_reduce\n rewrite [Finset.mem_product, not_and_or] at h_notin\n suffices A_ x = ∅ ∨ B_ y = ∅ by obtain h | h := this <;> rw [h] <;> simp\n refine h_notin.imp ?_ ?_\n · rw [← not_nonempty_iff_eq_empty]\n rintro h ⟨a, ha, rfl⟩\n exact h (h_AX ⟨a, ha⟩)\n · rw [← not_nonempty_iff_eq_empty]\n rintro h ⟨a, ha, rfl⟩\n exact h (h_BY ⟨a, ha⟩)\n unfold_let M\n unfold entropy\n haveI := isProbabilityMeasure_map (μ := ℙ) ((measurable_discrete φ).comp hUA').aemeasurable\n haveI := isProbabilityMeasure_map (μ := ℙ) ((measurable_discrete φ).comp hUB').aemeasurable\n rewrite [← Finset.sum_product', ← tsum_eq_sum fun _ ↦ h_compl, ← measureEntropy_prod]\n apply tsum_congr; intro; congr\n rewrite [← Set.singleton_prod_singleton, Measure.smul_apply, Measure.prod_prod,\n Measure.map_apply ((measurable_discrete _).comp hUA') (MeasurableSet.singleton _),\n Measure.map_apply ((measurable_discrete _).comp hUB') (MeasurableSet.singleton _),\n Set.preimage_comp, hUA_coe.measure_preimage hUA',\n Set.preimage_comp, hUB_coe.measure_preimage hUB']\n simp [p, A_, B_, mul_div_mul_comm, Set.inter_comm, ENNReal.toReal_div]\n have h_sum : ∑ x in X, ∑ y in Y,\n (p x y) * (M * dᵤ[A_ x # B_ y] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p x y)) ≤\n M * d[UA # UB] :=\n calc\n _ = ∑ x in X, ∑ y in Y, (p x y) * M * dᵤ[A_ x # B_ y] + M * d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by\n simp_rw [hM, Finset.sum_mul, ← Finset.sum_add_distrib]\n refine Finset.sum_congr rfl <| fun _ _ ↦ Finset.sum_congr rfl <| fun _ _ ↦ ?_\n simp only [negMulLog, left_distrib, mul_assoc, Finset.sum_mul]\n exact congrArg (HAdd.hAdd _) (by group)\n _ = M * ∑ x in X, ∑ y in Y, (p x y) * dᵤ[A_ x # B_ y] + M * d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by\n simp_rw [Finset.mul_sum]\n congr; ext; congr; ext; group\n _ ≤ M * d[UA # UB] := by\n rewrite [← left_distrib]\n apply mul_le_mul_of_nonneg_left\n · linarith\n · unfold_let M\n linarith only [entropy_nonneg (φ.toFun ∘ UA) ℙ, entropy_nonneg (φ.toFun ∘ UB) ℙ]\n have : ∃ x : X, ∃ y : Y,\n M * dᵤ[A_ x.val # B_ y.val] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p x.val y.val) ≤\n M * d[UA # UB] := by\n let f (xy : H × H) := (p xy.1 xy.2) * (M * d[UA # UB])\n let g (xy : H × H) := (p xy.1 xy.2) *\n (M * dᵤ[A_ xy.1 # B_ xy.2] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p xy.1 xy.2))\n by_contra hc; push_neg at hc\n replace hc : ∀ xy ∈ X ×ˢ Y, f xy < g xy := by\n refine fun xy h ↦ mul_lt_mul_of_pos_left ?_ ?_\n · exact hc ⟨xy.1, (Finset.mem_product.mp h).1⟩ ⟨xy.2, (Finset.mem_product.mp h).2⟩\n · haveI : Nonempty _ := h_Ax ⟨xy.1, (Finset.mem_product.mp h).1⟩\n haveI : Nonempty _ := h_By ⟨xy.2, (Finset.mem_product.mp h).2⟩\n simp only [p, div_pos, mul_pos, Nat.cast_pos, Nat.card_pos]\n have h_nonempty : Finset.Nonempty (X ×ˢ Y) := by\n use ⟨φ.toFun <| UA <| Classical.choice <| ProbabilityMeasure.nonempty ⟨ℙ, inferInstance⟩,\n φ.toFun <| UB <| Classical.choice <| ProbabilityMeasure.nonempty ⟨ℙ, inferInstance⟩⟩\n exact Finset.mem_product.mpr ⟨FiniteRange.mem _ _, FiniteRange.mem _ _⟩\n replace hc := Finset.sum_lt_sum_of_nonempty h_nonempty hc\n have h_p_one : ∑ x in X ×ˢ Y, p x.1 x.2 = 1 := by\n simp_rw [Finset.sum_product, p, mul_div_mul_comm, ← Finset.mul_sum,\n ← sum_prob_preimage hA h_φ_AX, sum_prob_preimage hB h_φ_BY, mul_one]\n rewrite [← Finset.sum_mul, h_p_one, one_mul, Finset.sum_product] at hc\n exact not_le_of_gt hc h_sum\n obtain ⟨x, y, hxy⟩ := this\n refine ⟨x, y, A_ x.val, B_ y.val, rfl, rfl, @nonempty_of_nonempty_subtype _ _ (h_Ax x), @nonempty_of_nonempty_subtype _ _ (h_By y), ?_⟩\n rewrite [← inv_div, Real.log_inv]\n show _ * -log (p x.val y.val) ≤ M * _\n linarith only [hxy]",
"proofType": "tactic",
"proofLengthLines": 132,
"proofLengthTokens": 7864
} | pfr |
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Quotient
import Mathlib.GroupTheory.Torsion
import Mathlib.GroupTheory.Torsion
import Mathlib.LinearAlgebra.FreeModule.PID
import PFR.Mathlib.Data.Set.Pointwise.SMul
import PFR.EntropyPFR
import PFR.ImprovedPFR
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Mathlib.GroupTheory.Torsion
/-!
# Weak PFR over the integers
Here we use the entropic form of PFR to deduce a weak form of PFR over the integers.
## Main statement
* `weak_PFR_int`: Let $A\subseteq \mathbb{Z}^d$ and $\lvert A+A\rvert\leq K\lvert A\rvert$.
There exists $A'\subseteq A$ such that $\lvert A'\rvert \geq K^{-17}\lvert A\rvert$ and
$\dim A' \leq (40/\log 2)\log K$.
-/
section AddCommGroup
variable {G : Type*} [AddCommGroup G] {A B : Set G}
open Set
open scoped Pointwise
def IsShift (A B : Set G) : Prop := ∃ x : G, A = x +ᵥ B
lemma IsShift.sub_self_congr : IsShift A B → A - A = B - B := by
rintro ⟨x, rfl⟩; simp [vadd_sub_vadd_comm, singleton_zero]
lemma IsShift.card_congr : IsShift A B → Nat.card A = Nat.card B := by rintro ⟨x, rfl⟩; simp
/-- The property of two sets A, B of a group G not being contained in cosets of the same proper
subgroup -/
def NotInCoset (A B : Set G) : Prop := AddSubgroup.closure ((A - A) ∪ (B - B)) = ⊤
/-- Without loss of generality, one can move (up to translation and embedding) any pair A, B of non-empty sets into a subgroup where they are not in a coset. -/
lemma wlog_notInCoset (hA : A.Nonempty) (hB : B.Nonempty) :
∃ (G' : AddSubgroup G) (A' B' : Set G'), IsShift A A' ∧ IsShift B B' ∧ NotInCoset A' B' := by
obtain ⟨x, hx⟩ := hA
obtain ⟨y, hy⟩ := hB
set G' := AddSubgroup.closure ((A - A) ∪ (B - B))
set A' : Set G' := (↑) ⁻¹' ((-x) +ᵥ A)
set B' : Set G' := (↑) ⁻¹' ((-y) +ᵥ B)
have hxA : -x +ᵥ A ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hx).trans $ (subset_union_left ..).trans
AddSubgroup.subset_closure
have hyB : -y +ᵥ B ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hy).trans $ (subset_union_right ..).trans
AddSubgroup.subset_closure
have hA : IsShift A A' := ⟨x, by rw [Set.image_preimage_eq_of_subset hxA, vadd_neg_vadd]⟩
have hB : IsShift B B' := ⟨y, by rw [Set.image_preimage_eq_of_subset hyB, vadd_neg_vadd]⟩
refine ⟨G', A', B', hA, hB, ?_⟩
unfold NotInCoset
convert AddSubgroup.closure_preimage_eq_top ((A - A) ∪ (B - B))
simp_rw [preimage_union, hA.sub_self_congr, hB.sub_self_congr]
rw [preimage_sub, preimage_sub]
simp [A', B', preimage_image_preimage]
all_goals apply_rules [Subtype.coe_injective, (image_preimage_subset ..).trans, hxA, hyB]
end AddCommGroup
section Torsion
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [MeasurableSpace G] [MeasurableSingletonClass G]
[Countable G] {Ω Ω' : Type u} [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ': Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
/-- If $G$ is torsion-free and $X,Y$ are $G$-valued random variables then $d[X;2Y]\leq 5d[X;Y]$. -/
lemma torsion_free_doubling [FiniteRange X] [FiniteRange Y]
(hX : Measurable X) (hY : Measurable Y) (hG : AddMonoid.IsTorsionFree G) :
d[X ; μ # (Y + Y) ; μ'] ≤ 5 * d[X; μ # Y ; μ'] := by
obtain ⟨A, mA, μA, X', Y'₁, Y'₂, hμA, h_indep, hX'_meas, hY'₁_meas, hY'₂_meas, hX'_ident,
hY'₁_ident, hY'₂_ident, _, _, _⟩ := independent_copies3_nondep_finiteRange hX hY hY μ μ' μ'
have h_meas (i : Fin 3) : Measurable (![X', Y'₁, Y'₂] i) := by fin_cases i <;> assumption
haveI : NoZeroSMulDivisors ℕ G := hG.noZeroNsmulDivisors
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨x, y₁, y₂⟩ ↦ (x, y₁ - y₂, x - 2 • y₁)
show H[f ∘ ⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] = _
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hX'_meas <| Measurable.prod hY'₁_meas hY'₂_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun X' (prod Y'₁ Y'₂) μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 1 2 0 (by decide) (by decide)
rw [this.entropy_pair_eq_add hX'_meas (by exact Measurable.prod hY'₁_meas hY'₂_meas),
IndepFun.entropy_pair_eq_add hY'₁_meas hY'₂_meas (h_indep.indepFun (show 1 ≠ 2 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, two_mul]
have : H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[X ; μ] + H[Y ; μ'] := calc
H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[⟨X', Y'₁⟩ ; μA] := by
let f : G × G → G × G := fun ⟨x, y₁⟩ ↦ (x, x - 2 • y₁)
show H[f ∘ ⟨X', Y'₁⟩ ; μA] = _
apply entropy_comp_of_injective μA (by exact Measurable.prod hX'_meas hY'₁_meas) f
exact fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + H[Y ; μ'] := by
rw [IndepFun.entropy_pair_eq_add hX'_meas hY'₁_meas (h_indep.indepFun (show 0 ≠ 1 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq]
let f : G × G → G × G := fun ⟨x, y⟩ ↦ (x, y - x)
have hf : f.Injective := fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all
have : H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] := calc
H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] = H[f ∘ ⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
show _ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂ - (Y'₁ - Y'₂)⟩ ; μA]
rw [sub_sub_sub_cancel_right, ← sub_add_eq_sub_sub, two_nsmul]
_ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
refine entropy_comp_of_injective μA (Measurable.prod ?_ ?_) f hf
· exact Measurable.sub hY'₁_meas hY'₂_meas
· exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
_ ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] :=
entropy_pair_le_add (hY'₁_meas.sub' hY'₂_meas) (hX'_meas.sub' hY'₁_meas |>.sub' hY'₂_meas) μA
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] + H[X' - 2 • Y'₁ ; μA] ≤
H[⟨X', X' - 2 • Y'₁⟩ ; μA] + H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] := by
haveI : FiniteRange (Y'₁ - Y'₂) := FiniteRange.sub Y'₁ Y'₂
haveI : FiniteRange (2 • Y'₁) := by show FiniteRange ((fun x ↦ 2 • x) ∘ Y'₁); infer_instance
apply entropy_triple_add_entropy_le μA hX'_meas (Measurable.sub hY'₁_meas hY'₂_meas)
exact Measurable.sub' hX'_meas <| Measurable.const_smul hY'₁_meas 2
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨y₁, y₂, x⟩ ↦ (y₁, y₂, x - y₁ - y₂)
show H[f ∘ ⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA]
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hY'₁_meas <| Measurable.prod hY'₂_meas hX'_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun Y'₁ (prod Y'₂ X') μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 2 0 1 (by decide) (by decide)
rw [this.entropy_pair_eq_add hY'₁_meas (by exact Measurable.prod hY'₂_meas hX'_meas),
IndepFun.entropy_pair_eq_add hY'₂_meas hX'_meas (h_indep.indepFun (show 2 ≠ 0 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq]
group
have : H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₂ ; μA] := calc
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₁, X' - Y'₂⟩ ; μA] := by rw [sub_right_comm] ; rfl
_ = H[⟨Y'₁, X' - Y'₂⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₁_meas <| Measurable.sub hX'_meas hY'₂_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₂ ; μA] := by
haveI : FiniteRange (X' - Y'₂) := FiniteRange.sub X' Y'₂
convert IndepFun.entropy_pair_eq_add hY'₁_meas (hX'_meas.sub hY'₂_meas)
<| h_indep.indepFun_sub_right h_meas 1 0 2 (by decide) (by decide)
exact hY'₁_ident.entropy_eq.symm
have : H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₁ ; μA] := calc
H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₂, X' - Y'₁⟩ ; μA] := rfl
_ = H[⟨Y'₂, X' - Y'₁⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₂_meas <| Measurable.sub hX'_meas hY'₁_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₁ ; μA] := by
haveI : FiniteRange (X' - Y'₁) := FiniteRange.sub X' Y'₁
convert IndepFun.entropy_pair_eq_add hY'₂_meas (hX'_meas.sub hY'₁_meas)
<| h_indep.indepFun_sub_right h_meas 2 0 1 (by decide) (by decide)
exact hY'₂_ident.entropy_eq.symm
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] ≤
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] + H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
apply entropy_triple_add_entropy_le μA hY'₁_meas hY'₂_meas
exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
have : H[X' - Y'₁ - Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := calc
H[X' - Y'₁ - Y'₂ ; μA] ≤ H[X' - Y'₁ ; μA] + H[X' - Y'₂ ; μA] - H[X ; μ] := by linarith
_ = 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := by
nth_rw 1 [two_mul, ← hX'_ident.rdist_eq hY'₁_ident, ← hX'_ident.rdist_eq hY'₂_ident]
have h1 : d[X' ; μA # Y'₁ ; μA] = H[X' - Y'₁ ; μA] - H[X' ; μA] / 2 - H[Y'₁ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 1 by decide)).rdist_eq hX'_meas hY'₁_meas
have h2 : d[X' ; μA # Y'₂ ; μA] = H[X' - Y'₂ ; μA] - H[X' ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 2 by decide)).rdist_eq hX'_meas hY'₂_meas
rw [h1, h2, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, hX'_ident.entropy_eq]
group
have : d[X ; μ # 2 • Y ; μ'] ≤
d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := calc
d[X ; μ # 2 • Y ; μ'] = H[X' - 2 • Y'₁ ; μA] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by
have h2Y_ident : IdentDistrib (2 • Y'₁) (2 • Y) (μ := μA) (ν := μ') := by
convert hY'₁_ident.comp <| measurable_discrete <| fun g ↦ 2 • g
have h2Y_indep : IndepFun X' (2 • Y'₁) (μ := μA) := by
convert (h_indep.indepFun (show 0 ≠ 1 by decide)).comp measurable_id
(measurable_const_smul 2)
rw [← hX'_ident.rdist_eq h2Y_ident,
h2Y_indep.rdist_eq hX'_meas <| Measurable.const_smul hY'₁_meas 2,
hX'_ident.entropy_eq, h2Y_ident.entropy_eq]
_ ≤ H[Y'₁ - Y'₂ ; μA] + 2 * d[X ; μ # Y ; μ'] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by linarith
_ = d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := by
have H2Y : H[2 • Y ; μ'] = H[Y ; μ'] := by
let f (g : G) := 2 • g
exact entropy_comp_of_injective μ' hY f (fun _ _ ↦ by simp [f, smul_right_inj])
have : d[Y'₁ ; μA # Y'₂ ; μA] = H[Y'₁ - Y'₂ ; μA] - H[Y'₁ ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 1 ≠ 2 by decide)).rdist_eq hY'₁_meas hY'₂_meas
rw [this, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, H2Y]
group
have : d[Y'₁ ; μA # Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] := by
rw [two_mul]
convert rdist_triangle hY'₁_meas hX'_meas hY'₂_meas (μ := μA) (μ' := μA) (μ'' := μA)
· exact rdist_symm.trans (hY'₁_ident.rdist_eq hX'_ident).symm
· exact (hX'_ident.rdist_eq hY'₂_ident).symm
rw [← two_nsmul]
linarith [abs_le.mp <| diff_ent_le_rdist hX hY (μ := μ) (μ' := μ')]
/-- If $G$ is a torsion-free group and $X,Y$ are $G$-valued random variables and
$\phi : G\to \mathbb{F}_2^d$ is a homomorphism then
\[\mathbb{H}(\phi(X))\leq 10d[X;Y].\] -/
lemma torsion_dist_shrinking {H : Type u} [FiniteRange X] [FiniteRange Y] (hX : Measurable X)
(hY : Measurable Y) [AddCommGroup H] [ElementaryAddCommGroup H 2]
[MeasurableSpace H] [MeasurableSingletonClass H] [Countable H]
(hG : AddMonoid.IsTorsionFree G) (φ : G →+ H) :
H[φ ∘ X ; μ] ≤ 10 * d[X; μ # Y ; μ'] := by
have :=
calc d[φ ∘ X ; μ # φ ∘ (Y + Y); μ'] ≤ d[X; μ # (Y + Y) ; μ'] := rdist_of_hom_le φ hX (Measurable.add hY hY)
_ ≤ 5 * d[X; μ # Y ; μ'] := torsion_free_doubling X Y μ μ' hX hY hG
have eq_zero : φ ∘ (Y + Y) = fun _ ↦ 0 := by ext x ; simp only [Function.comp_apply, Pi.add_apply,
map_add, ElementaryAddCommGroup.add_self]
rwa [eq_zero, rdist_zero_eq_half_ent, div_le_iff zero_lt_two, mul_assoc, mul_comm _ 2, ←mul_assoc,
show (5*2 : ℝ) = 10 by norm_num] at this
end Torsion
instance {G : Type u} [AddCommGroup G] [Fintype G] [MeasurableSpace G] [MeasurableSingletonClass G] (H : AddSubgroup G)
: MeasurableSingletonClass (G ⧸ H) :=
⟨λ _ ↦ by { rw [measurableSet_quotient]; simp [measurableSet_discrete] }⟩
section F2_projection
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [ElementaryAddCommGroup G 2] [Fintype G] [MeasurableSpace G]
[MeasurableSingletonClass G] {Ω Ω' : Type*}
/-- Let $G=\mathbb{F}_2^n$ and $X,Y$ be $G$-valued random variables such that
\[\mathbb{H}(X)+\mathbb{H}(Y)> (20/\alpha) d[X;Y],\]
for some $\alpha > 0$.
There is a non-trivial subgroup $H\leq G$ such that
\[\log \lvert H\rvert <(1+\alpha)/2 (\mathbb{H}(X)+\mathbb{H}(Y))\] and
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))< \alpha (\mathbb{H}(X)+\mathbb{H}(Y))\]
where $\psi:G\to G/H$ is the natural projection homomorphism.
-/
lemma app_ent_PFR' [MeasureSpace Ω] [MeasureSpace Ω'] (X : Ω → G) (Y : Ω' → G)
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
{α : ℝ} (hent : 20 * d[X # Y] < α * (H[X] + H[Y])) (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X] + H[Y]) ∧
H[(QuotientAddGroup.mk' H) ∘ X] + H[(QuotientAddGroup.mk' H) ∘ Y] < α * (H[X] + H[Y]) := by
let p : refPackage Ω Ω' G := {
X₀₁ := X
X₀₂ := Y
hmeas1 := hX
hmeas2 := hY
η := 1/8
hη := by norm_num
hη' := by norm_num }
obtain ⟨H, Ω'', hΩ'', U, _, hUmeas, hUunif, ineq⟩ := entropic_PFR_conjecture_improv p rfl
let ψ := (QuotientAddGroup.mk' H)
use H
haveI : Finite H := Subtype.finite
-- Note that H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y]
have ent_le : H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y] := calc
H[ψ ∘ X] + H[ψ ∘ Y] ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· exact ent_of_proj_le hX hUmeas hUunif
· exact ent_of_proj_le hY hUmeas hUunif
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- Note that (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y]
have log_sub_le : (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y] := calc
(log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) =
(H[U] - H[X]) + (H[U] - H[Y]) := by
rw [IsUniform.entropy_eq' hUunif hUmeas, SetLike.coe_sort_coe]
_ ≤ |(H[U] - H[X])| + |(H[U] - H[Y])| := by gcongr <;> exact le_abs_self _
_ ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hX
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hY
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- then the conclusion follows from the assumption `hent` and basic inequality manipulations
exact ⟨by linarith, by linarith⟩
variable [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ' : Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
lemma app_ent_PFR (α : ℝ) (hent: 20 * d[X;μ # Y;μ'] < α * (H[X; μ] + H[Y; μ'])) (hX : Measurable X)
(hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ']
< α * (H[ X; μ] + H[Y; μ']) :=
@app_ent_PFR' _ _ _ _ _ _ _ _ (MeasureSpace.mk μ) (MeasureSpace.mk μ') _ _ _ _ α hent hX hY
set_option maxHeartbeats 300000 in
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables and $\alpha < 1$ then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq (1 + α) / (2 * (1 - α)) * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 20/\alpha * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection'
(α : ℝ) (hX : Measurable X) (hY : Measurable Y) (αpos : 0 < α) (αone : α < 1) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (H[X ; μ] + H[Y ; μ']) ∧
α * (H[(QuotientAddGroup.mk' H) ∘ X ; μ] + H[(QuotientAddGroup.mk' H) ∘ Y ; μ']) ≤
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] := by
let S := { H : AddSubgroup G | (∃ (c : ℝ), 0 ≤ c ∧
log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (1 - c) * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
c * (H[X; μ] + H[Y;μ'])) ∧
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] <
α * (H[ (QuotientAddGroup.mk' H) ∘ X; μ ] + H[ (QuotientAddGroup.mk' H) ∘ Y; μ']) }
have : 0 ≤ H[X ; μ] + H[Y ; μ'] := by linarith [entropy_nonneg X μ, entropy_nonneg Y μ']
have : 0 < 1 - α := sub_pos.mpr αone
by_cases hE : (⊥ : AddSubgroup G) ∈ S
· classical
obtain ⟨H, ⟨⟨c, hc, hlog, hup⟩, hent⟩, hMaxl⟩ :=
S.toFinite.exists_maximal_wrt id S (Set.nonempty_of_mem hE)
set ψ : G →+ G ⧸ H := QuotientAddGroup.mk' H
have surj : Function.Surjective ψ := QuotientAddGroup.mk'_surjective H
set G' := G ⧸ H
have : ElementaryAddCommGroup G' 2 := ElementaryAddCommGroup.quotient_group (by decide)
(by simp [AddSubgroup.zero_mem])
obtain ⟨H', hlog', hup'⟩ := app_ent_PFR _ _ _ _ α hent ((measurable_discrete _).comp hX)
((measurable_discrete _).comp hY)
have H_ne_bot: H' ≠ ⊥ := by
by_contra!
rcases this with rfl
have inj : Function.Injective (QuotientAddGroup.mk' (⊥ : AddSubgroup G')) :=
(QuotientAddGroup.quotientBot : (G' ⧸ ⊥) ≃+ G').symm.injective
rw [entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ inj,
entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ inj] at hup'
nlinarith [entropy_nonneg (ψ ∘ X) μ, entropy_nonneg (ψ ∘ Y) μ']
let H'' := H'.comap ψ
use H''
rw [← (AddSubgroup.map_comap_eq_self_of_surjective surj _ : H''.map ψ = H')] at hup' hlog'
set H' := H''.map ψ
have Hlt : H < H'' := by
have : H = (⊥ : AddSubgroup G').comap ψ := by
simp only [ψ, AddMonoidHom.comap_bot, QuotientAddGroup.ker_mk']
rw [this, AddSubgroup.comap_lt_comap_of_surjective surj]
exact Ne.bot_lt H_ne_bot
let φ : G' ⧸ H' ≃+ G ⧸ H'' := QuotientAddGroup.quotientQuotientEquivQuotient H H'' Hlt.le
set ψ' : G' →+ G' ⧸ H' := QuotientAddGroup.mk' H'
set ψ'' : G →+ G ⧸ H'' := QuotientAddGroup.mk' H''
have diag : ψ' ∘ ψ = φ.symm ∘ ψ'' := rfl
rw [← Function.comp.assoc, ← Function.comp.assoc, diag, Function.comp.assoc,
Function.comp.assoc] at hup'
have cond : log (Nat.card H'') ≤
(1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := by
have cardprod : Nat.card H'' = Nat.card H' * Nat.card H := by
have hcard₀ := Nat.card_congr <| (AddSubgroup.addSubgroupOfEquivOfLe Hlt.le).toEquiv
have hcard₁ := Nat.card_congr <|
(QuotientAddGroup.quotientKerEquivRange (ψ.restrict H'')).toEquiv
have hcard₂ := AddSubgroup.card_eq_card_quotient_mul_card_addSubgroup (H.addSubgroupOf H'')
rw [ψ.ker_restrict H'', QuotientAddGroup.ker_mk', ψ.restrict_range H''] at hcard₁
simpa only [← Nat.card_eq_fintype_card, hcard₀, hcard₁] using hcard₂
calc
log (Nat.card H'')
_ = log ((Nat.card H' : ℝ) * (Nat.card H : ℝ)) := by rw [cardprod]; norm_cast
_ = log (Nat.card H') + log (Nat.card H) := by
rw [Real.log_mul (Nat.cast_ne_zero.2 (@Nat.card_pos H').ne')
(Nat.cast_ne_zero.2 (@Nat.card_pos H).ne')]
_ ≤ (1 + α) / 2 * (H[⇑ψ ∘ X ; μ] + H[⇑ψ ∘ Y ; μ']) + log (Nat.card H) := by gcongr
_ ≤ (1 + α) / 2 * (c * (H[X; μ] + H[Y;μ'])) +
(1 + α) / (2 * (1 - α)) * (1 - c) * (H[X ; μ] + H[Y ; μ']) := by gcongr
_ = (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X ; μ] + H[Y ; μ']) := by
field_simp; ring
have HS : H'' ∉ S := λ Hs => Hlt.ne (hMaxl H'' Hs Hlt.le)
simp only [S, Set.mem_setOf_eq, not_and, not_lt] at HS
refine ⟨?_, HS ⟨α * c, by positivity, cond, ?_⟩⟩
· calc
log (Nat.card H'')
_ ≤ (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := cond
_ ≤ (1 + α) / (2 * (1 - α)) * 1 * (H[X; μ] + H[Y;μ']) := by gcongr; simp; positivity
_ = (1 + α) / (2 * (1 - α)) * (H[X; μ] + H[Y;μ']) := by simp only [mul_one]
· calc
H[ ψ'' ∘ X; μ ] + H[ ψ'' ∘ Y; μ' ]
_ = H[ φ.symm ∘ ψ'' ∘ X; μ ] + H[ φ.symm ∘ ψ'' ∘ Y; μ' ] := by
simp_rw [← entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ φ.symm.injective,
← entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ φ.symm.injective]
_ ≤ α * (H[ ψ ∘ X; μ ] + H[ ψ ∘ Y; μ' ]) := hup'.le
_ ≤ α * (c * (H[X ; μ] + H[Y ; μ'])) := by gcongr
_ = (α * c) * (H[X ; μ] + H[Y ; μ']) := by ring
· use ⊥
constructor
· simp only [AddSubgroup.mem_bot, Nat.card_eq_fintype_card, Fintype.card_ofSubsingleton,
Nat.cast_one, log_one]
positivity
· simp only [S, Set.mem_setOf_eq, not_and, not_lt] at hE
exact hE ⟨1, by norm_num, by
norm_num; exact add_le_add (entropy_comp_le μ hX _) (entropy_comp_le μ' hY _)⟩
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq 2 * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 34 * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
34 * d[(QuotientAddGroup.mk' H) ∘ X;μ # (QuotientAddGroup.mk' H) ∘ Y;μ'] := by
rcases PFR_projection' X Y μ μ' ((3 : ℝ) / 5) hX hY (by norm_num) (by norm_num) with ⟨H, h, h'⟩
refine ⟨H, ?_, ?_⟩
· convert h
norm_num
· have : 0 ≤ d[⇑(QuotientAddGroup.mk' H) ∘ X ; μ # ⇑(QuotientAddGroup.mk' H) ∘ Y ; μ'] :=
rdist_nonneg ((measurable_discrete _).comp hX) ((measurable_discrete _).comp hY)
linarith
end F2_projection
open MeasureTheory ProbabilityTheory Real Set
open scoped BigOperators
lemma four_logs {a b c d : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) (hd : 0 < d) :
log ((a*b)/(c*d)) = log a + log b - log c - log d := by
rw [log_div, log_mul, log_mul, sub_sub] <;> positivity
lemma sum_prob_preimage {G H : Type*} {X : Finset H} {A : Set G} [Finite A] {φ : A → X}
{A_ : H → Set G} (hA : A.Nonempty) (hφ : ∀ x : X, A_ x = Subtype.val '' (φ ⁻¹' {x})) :
∑ x in X, (Nat.card (A_ x) : ℝ) / (Nat.card A) = 1 := by
rw [← Finset.sum_div]
apply (div_eq_one_iff_eq <| Nat.cast_ne_zero.mpr <| Nat.pos_iff_ne_zero.mp (@Nat.card_pos _ hA.to_subtype _)).mpr
classical
haveI := Fintype.ofFinite A
rewrite [Nat.card_eq_fintype_card, ← Finset.card_univ, Finset.card_eq_sum_card_fiberwise
<| fun a _ ↦ Finset.mem_univ (φ a), ← Finset.sum_coe_sort]
norm_cast
congr; ext
rewrite [← Set.Finite.toFinset_setOf, (Set.toFinite _).card_toFinset, ← Nat.card_eq_fintype_card,
hφ, Nat.card_image_of_injective Subtype.val_injective]; rfl
/-- Let $\phi : G\to H$ be a homomorphism and $A,B\subseteq G$ be finite subsets. If $x,y\in H$ then let $A_x=A\cap \phi^{-1}(x)$ and $B_y=B\cap \phi^{-1}(y)$. There exist $x,y\in H$ such that $A_x,B_y$ are both non-empty and
\[d[\phi(U_A);\phi(U_B)]\log \frac{\lvert A\rvert\lvert B\rvert}{\lvert A_x\rvert\lvert B_y\rvert}\leq (\mathbb{H}(\phi(U_A))+\mathbb{H}(\phi(U_B)))(d(U_A,U_B)-d(U_{A_x},U_{B_y}).\] -/
lemma single_fibres {G H Ω Ω': Type u}
[AddCommGroup G] [Countable G] [MeasurableSpace G] [MeasurableSingletonClass G]
[AddCommGroup H] [Countable H] [MeasurableSpace H] [MeasurableSingletonClass H]
[MeasureSpace Ω] [MeasureSpace Ω']
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
(φ : G →+ H)
{A B : Set G} [Finite A] [Finite B] {UA : Ω → G} {UB: Ω' → G} (hA : A.Nonempty) (hB : B.Nonempty)
(hUA': Measurable UA) (hUB': Measurable UB) (hUA: IsUniform A UA) (hUB: IsUniform B UB)
(hUA_mem : ∀ ω, UA ω ∈ A) (hUB_mem : ∀ ω, UB ω ∈ B) :
∃ (x y : H) (Ax By: Set G),
Ax = A ∩ φ.toFun ⁻¹' {x} ∧ By = B ∩ φ.toFun ⁻¹' {y} ∧ Ax.Nonempty ∧ By.Nonempty ∧
d[φ.toFun ∘ UA # φ.toFun ∘ UB]
* log ((Nat.card A) * (Nat.card B) / ((Nat.card Ax) * (Nat.card By))) ≤
(H[φ.toFun ∘ UA] + H[φ.toFun ∘ UB]) * (d[UA # UB] - dᵤ[Ax # By]) := by
have : Nonempty A := hA.to_subtype
have : Nonempty B := hB.to_subtype
haveI : FiniteRange UA := finiteRange_of_finset UA A.toFinite.toFinset (by simpa)
haveI : FiniteRange UB := finiteRange_of_finset UB B.toFinite.toFinset (by simpa)
have hUA_coe : IsUniform A.toFinite.toFinset.toSet UA := by rwa [Set.Finite.coe_toFinset]
have hUB_coe : IsUniform B.toFinite.toFinset.toSet UB := by rwa [Set.Finite.coe_toFinset]
let A_ (x : H) : Set G := A ∩ φ.toFun ⁻¹' {x}
let B_ (y : H) : Set G := B ∩ φ.toFun ⁻¹' {y}
let X : Finset H := FiniteRange.toFinset (φ.toFun ∘ UA)
let Y : Finset H := FiniteRange.toFinset (φ.toFun ∘ UB)
haveI h_Ax (x : X) : Nonempty (A_ x.val) := by
obtain ⟨ω, hω⟩ := (FiniteRange.mem_iff _ _).mp x.property
use UA ω; exact Set.mem_inter (hUA_mem ω) (by exact hω)
haveI h_By (y : Y) : Nonempty (B_ y.val) := by
obtain ⟨ω, hω⟩ := (FiniteRange.mem_iff _ _).mp y.property
use UB ω; exact Set.mem_inter (hUB_mem ω) (by exact hω)
have h_AX (a : A) : φ.toFun a.val ∈ X := by
obtain ⟨ω, hω⟩ := hUA_coe.nonempty_preimage_of_mem hUA' (A.toFinite.mem_toFinset.mpr a.property)
exact (FiniteRange.mem_iff _ (φ.toFun a.val)).mpr ⟨ω, congr_arg _ hω⟩
have h_BY (b : B) : φ.toFun b.val ∈ Y := by
obtain ⟨ω, hω⟩ := hUB_coe.nonempty_preimage_of_mem hUB' (B.toFinite.mem_toFinset.mpr b.property)
exact (FiniteRange.mem_iff _ (φ.toFun b.val)).mpr ⟨ω, congr_arg _ hω⟩
let φ_AX (a : A) : X := by use φ.toFun a.val; exact h_AX a
let φ_BY (b : B) : Y := by use φ.toFun b.val; exact h_BY b
have h_φ_AX (x : X) : A_ x.val = φ_AX ⁻¹' {x} := by ext; simp [A_, φ_AX]; simp [Subtype.ext_iff]
have h_φ_BY (y : Y) : B_ y.val = φ_BY ⁻¹' {y} := by ext; simp [B_, φ_BY]; simp [Subtype.ext_iff]
let p (x : H) (y : H) : ℝ :=
(Nat.card (A_ x).Elem) * (Nat.card (B_ y).Elem) / ((Nat.card A.Elem) * (Nat.card B.Elem))
have :
∑ x in X, ∑ y in Y, (p x y) * dᵤ[A_ x # B_ y] ≤ d[UA # UB] - d[φ.toFun ∘ UA # φ.toFun ∘ UB] :=
calc
_ = d[UA | φ.toFun ∘ UA # UB | φ.toFun ∘ UB] := by
rewrite [condRuzsaDist_eq_sum hUA' ((measurable_discrete _).comp hUA')
hUB' ((measurable_discrete _).comp hUB')]
refine Finset.sum_congr rfl <| fun x hx ↦ Finset.sum_congr rfl <| fun y hy ↦ ?_
haveI : Nonempty (A_ x) := h_Ax ⟨x, hx⟩
haveI : Nonempty (B_ y) := h_By ⟨y, hy⟩
let μx := (ℙ : Measure Ω)[|(φ.toFun ∘ UA) ⁻¹' {x}]
let μy := (ℙ : Measure Ω')[|(φ.toFun ∘ UB) ⁻¹' {y}]
have h_μ_p : IsProbabilityMeasure μx ∧ IsProbabilityMeasure μy := by
constructor <;> apply ProbabilityTheory.cond_isProbabilityMeasure <;> rw [Set.preimage_comp]
refine @IsUniform.measure_preimage_ne_zero _ _ _ _ _ _ _ _ _ _ hUA_coe hUA' _ ?_
swap; refine @IsUniform.measure_preimage_ne_zero _ _ _ _ _ _ _ _ _ _ hUB_coe hUB' _ ?_
all_goals rwa [Set.inter_comm, Set.Finite.coe_toFinset]
have h_μ_unif : IsUniform (A_ x) UA μx ∧ IsUniform (B_ y) UB μy := by
have : _ ∧ _ := ⟨hUA.restrict hUA' (φ.toFun ⁻¹' {x}), hUB.restrict hUB' (φ.toFun ⁻¹' {y})⟩
rwa [Set.inter_comm _ A, Set.inter_comm _ B] at this
rewrite [rdist_set_eq_rdist h_μ_p.1 h_μ_p.2 h_μ_unif.1 h_μ_unif.2 hUA' hUB']
show _ = (Measure.real _ (UA ⁻¹' (_ ⁻¹' _))) * (Measure.real _ (UB ⁻¹' (_ ⁻¹' _))) * _
rewrite [hUA_coe.measureReal_preimage hUA', hUB_coe.measureReal_preimage hUB']
simp_rw [p, A_, B_, IsProbabilityMeasure.measureReal_univ, one_mul]
rewrite [mul_div_mul_comm, Set.inter_comm A, Set.inter_comm B]
simp only [Set.Finite.coe_toFinset, Set.Finite.mem_toFinset, Finset.mem_val]; rfl
_ ≤ d[UA # UB] - d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
rewrite [ZeroHom.toFun_eq_coe, AddMonoidHom.toZeroHom_coe]
linarith only [rdist_le_sum_fibre φ hUA' hUB' (μ := ℙ) (μ' := ℙ)]
let M := H[φ.toFun ∘ UA] + H[φ.toFun ∘ UB]
have hM : M = ∑ x in X, ∑ y in Y, Real.negMulLog (p x y) := by
have h_compl {x y} (h_notin : (x, y) ∉ X ×ˢ Y) : Real.negMulLog (p x y) = 0 := by
unfold_let p; beta_reduce
rewrite [Finset.mem_product, not_and_or] at h_notin
suffices A_ x = ∅ ∨ B_ y = ∅ by obtain h | h := this <;> rw [h] <;> simp
refine h_notin.imp ?_ ?_
· rw [← not_nonempty_iff_eq_empty]
rintro h ⟨a, ha, rfl⟩
exact h (h_AX ⟨a, ha⟩)
· rw [← not_nonempty_iff_eq_empty]
rintro h ⟨a, ha, rfl⟩
exact h (h_BY ⟨a, ha⟩)
unfold_let M
unfold entropy
haveI := isProbabilityMeasure_map (μ := ℙ) ((measurable_discrete φ).comp hUA').aemeasurable
haveI := isProbabilityMeasure_map (μ := ℙ) ((measurable_discrete φ).comp hUB').aemeasurable
rewrite [← Finset.sum_product', ← tsum_eq_sum fun _ ↦ h_compl, ← measureEntropy_prod]
apply tsum_congr; intro; congr
rewrite [← Set.singleton_prod_singleton, Measure.smul_apply, Measure.prod_prod,
Measure.map_apply ((measurable_discrete _).comp hUA') (MeasurableSet.singleton _),
Measure.map_apply ((measurable_discrete _).comp hUB') (MeasurableSet.singleton _),
Set.preimage_comp, hUA_coe.measure_preimage hUA',
Set.preimage_comp, hUB_coe.measure_preimage hUB']
simp [p, A_, B_, mul_div_mul_comm, Set.inter_comm, ENNReal.toReal_div]
have h_sum : ∑ x in X, ∑ y in Y,
(p x y) * (M * dᵤ[A_ x # B_ y] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p x y)) ≤
M * d[UA # UB] :=
calc
_ = ∑ x in X, ∑ y in Y, (p x y) * M * dᵤ[A_ x # B_ y] + M * d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
simp_rw [hM, Finset.sum_mul, ← Finset.sum_add_distrib]
refine Finset.sum_congr rfl <| fun _ _ ↦ Finset.sum_congr rfl <| fun _ _ ↦ ?_
simp only [negMulLog, left_distrib, mul_assoc, Finset.sum_mul]
exact congrArg (HAdd.hAdd _) (by group)
_ = M * ∑ x in X, ∑ y in Y, (p x y) * dᵤ[A_ x # B_ y] + M * d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
simp_rw [Finset.mul_sum]
congr; ext; congr; ext; group
_ ≤ M * d[UA # UB] := by
rewrite [← left_distrib]
apply mul_le_mul_of_nonneg_left
· linarith
· unfold_let M
linarith only [entropy_nonneg (φ.toFun ∘ UA) ℙ, entropy_nonneg (φ.toFun ∘ UB) ℙ]
have : ∃ x : X, ∃ y : Y,
M * dᵤ[A_ x.val # B_ y.val] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p x.val y.val) ≤
M * d[UA # UB] := by
let f (xy : H × H) := (p xy.1 xy.2) * (M * d[UA # UB])
let g (xy : H × H) := (p xy.1 xy.2) *
(M * dᵤ[A_ xy.1 # B_ xy.2] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p xy.1 xy.2))
by_contra hc; push_neg at hc
replace hc : ∀ xy ∈ X ×ˢ Y, f xy < g xy := by
refine fun xy h ↦ mul_lt_mul_of_pos_left ?_ ?_
· exact hc ⟨xy.1, (Finset.mem_product.mp h).1⟩ ⟨xy.2, (Finset.mem_product.mp h).2⟩
· haveI : Nonempty _ := h_Ax ⟨xy.1, (Finset.mem_product.mp h).1⟩
haveI : Nonempty _ := h_By ⟨xy.2, (Finset.mem_product.mp h).2⟩
simp only [p, div_pos, mul_pos, Nat.cast_pos, Nat.card_pos]
have h_nonempty : Finset.Nonempty (X ×ˢ Y) := by
use ⟨φ.toFun <| UA <| Classical.choice <| ProbabilityMeasure.nonempty ⟨ℙ, inferInstance⟩,
φ.toFun <| UB <| Classical.choice <| ProbabilityMeasure.nonempty ⟨ℙ, inferInstance⟩⟩
exact Finset.mem_product.mpr ⟨FiniteRange.mem _ _, FiniteRange.mem _ _⟩
replace hc := Finset.sum_lt_sum_of_nonempty h_nonempty hc
have h_p_one : ∑ x in X ×ˢ Y, p x.1 x.2 = 1 := by
simp_rw [Finset.sum_product, p, mul_div_mul_comm, ← Finset.mul_sum,
← sum_prob_preimage hA h_φ_AX, sum_prob_preimage hB h_φ_BY, mul_one]
rewrite [← Finset.sum_mul, h_p_one, one_mul, Finset.sum_product] at hc
exact not_le_of_gt hc h_sum
obtain ⟨x, y, hxy⟩ := this
refine ⟨x, y, A_ x.val, B_ y.val, rfl, rfl, @nonempty_of_nonempty_subtype _ _ (h_Ax x), @nonempty_of_nonempty_subtype _ _ (h_By y), ?_⟩
rewrite [← inv_div, Real.log_inv]
show _ * -log (p x.val y.val) ≤ M * _
linarith only [hxy]
section dim
open Classical
variable {G : Type*} [AddCommGroup G]
/- If G ≅ ℤᵈ then there is a subgroup H of G such that A lies in a coset of H. This is helpful to
give the equivalent definition of `dimension`. Here this is stated in greated generality since the
proof carries over automatically-/
| lemma exists_coset_cover (A : Set G) :
∃ (d : ℕ), ∃ (S : Submodule ℤ G) (v : G),
FiniteDimensional.finrank ℤ S = d ∧ ∀ a ∈ A, a - v ∈ S | exists_coset_cover | 25309ad 20231211 | b43acd3 20231224 | pfr/PFR/WeakPFR.lean | {
"lineInFile": 595,
"tokenPositionInFile": 33499,
"theoremPositionInFile": 15
} | {
"inFilePremises": false,
"repositoryPremises": false
} | {
"hasProof": true,
"proof": "by\n existsi FiniteDimensional.finrank ℤ (⊤ : Submodule ℤ G), ⊤, 0\n refine ⟨rfl, fun a _ ↦ trivial⟩",
"proofType": "tactic",
"proofLengthLines": 3,
"proofLengthTokens": 100
} | pfr |
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Quotient
import Mathlib.GroupTheory.Torsion
import Mathlib.GroupTheory.Torsion
import Mathlib.LinearAlgebra.FreeModule.PID
import PFR.Mathlib.Data.Set.Pointwise.SMul
import PFR.EntropyPFR
import PFR.ImprovedPFR
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Mathlib.GroupTheory.Torsion
/-!
# Weak PFR over the integers
Here we use the entropic form of PFR to deduce a weak form of PFR over the integers.
## Main statement
* `weak_PFR_int`: Let $A\subseteq \mathbb{Z}^d$ and $\lvert A+A\rvert\leq K\lvert A\rvert$.
There exists $A'\subseteq A$ such that $\lvert A'\rvert \geq K^{-17}\lvert A\rvert$ and
$\dim A' \leq (40/\log 2)\log K$.
-/
section AddCommGroup
variable {G : Type*} [AddCommGroup G] {A B : Set G}
open Set
open scoped Pointwise
def IsShift (A B : Set G) : Prop := ∃ x : G, A = x +ᵥ B
lemma IsShift.sub_self_congr : IsShift A B → A - A = B - B := by
rintro ⟨x, rfl⟩; simp [vadd_sub_vadd_comm, singleton_zero]
lemma IsShift.card_congr : IsShift A B → Nat.card A = Nat.card B := by rintro ⟨x, rfl⟩; simp
/-- The property of two sets A, B of a group G not being contained in cosets of the same proper
subgroup -/
def NotInCoset (A B : Set G) : Prop := AddSubgroup.closure ((A - A) ∪ (B - B)) = ⊤
/-- Without loss of generality, one can move (up to translation and embedding) any pair A, B of non-empty sets into a subgroup where they are not in a coset. -/
lemma wlog_notInCoset (hA : A.Nonempty) (hB : B.Nonempty) :
∃ (G' : AddSubgroup G) (A' B' : Set G'), IsShift A A' ∧ IsShift B B' ∧ NotInCoset A' B' := by
obtain ⟨x, hx⟩ := hA
obtain ⟨y, hy⟩ := hB
set G' := AddSubgroup.closure ((A - A) ∪ (B - B))
set A' : Set G' := (↑) ⁻¹' ((-x) +ᵥ A)
set B' : Set G' := (↑) ⁻¹' ((-y) +ᵥ B)
have hxA : -x +ᵥ A ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hx).trans $ (subset_union_left ..).trans
AddSubgroup.subset_closure
have hyB : -y +ᵥ B ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hy).trans $ (subset_union_right ..).trans
AddSubgroup.subset_closure
have hA : IsShift A A' := ⟨x, by rw [Set.image_preimage_eq_of_subset hxA, vadd_neg_vadd]⟩
have hB : IsShift B B' := ⟨y, by rw [Set.image_preimage_eq_of_subset hyB, vadd_neg_vadd]⟩
refine ⟨G', A', B', hA, hB, ?_⟩
unfold NotInCoset
convert AddSubgroup.closure_preimage_eq_top ((A - A) ∪ (B - B))
simp_rw [preimage_union, hA.sub_self_congr, hB.sub_self_congr]
rw [preimage_sub, preimage_sub]
simp [A', B', preimage_image_preimage]
all_goals apply_rules [Subtype.coe_injective, (image_preimage_subset ..).trans, hxA, hyB]
end AddCommGroup
section Torsion
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [MeasurableSpace G] [MeasurableSingletonClass G]
[Countable G] {Ω Ω' : Type u} [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ': Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
/-- If $G$ is torsion-free and $X,Y$ are $G$-valued random variables then $d[X;2Y]\leq 5d[X;Y]$. -/
lemma torsion_free_doubling [FiniteRange X] [FiniteRange Y]
(hX : Measurable X) (hY : Measurable Y) (hG : AddMonoid.IsTorsionFree G) :
d[X ; μ # (Y + Y) ; μ'] ≤ 5 * d[X; μ # Y ; μ'] := by
obtain ⟨A, mA, μA, X', Y'₁, Y'₂, hμA, h_indep, hX'_meas, hY'₁_meas, hY'₂_meas, hX'_ident,
hY'₁_ident, hY'₂_ident, _, _, _⟩ := independent_copies3_nondep_finiteRange hX hY hY μ μ' μ'
have h_meas (i : Fin 3) : Measurable (![X', Y'₁, Y'₂] i) := by fin_cases i <;> assumption
haveI : NoZeroSMulDivisors ℕ G := hG.noZeroNsmulDivisors
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨x, y₁, y₂⟩ ↦ (x, y₁ - y₂, x - 2 • y₁)
show H[f ∘ ⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] = _
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hX'_meas <| Measurable.prod hY'₁_meas hY'₂_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun X' (prod Y'₁ Y'₂) μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 1 2 0 (by decide) (by decide)
rw [this.entropy_pair_eq_add hX'_meas (by exact Measurable.prod hY'₁_meas hY'₂_meas),
IndepFun.entropy_pair_eq_add hY'₁_meas hY'₂_meas (h_indep.indepFun (show 1 ≠ 2 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, two_mul]
have : H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[X ; μ] + H[Y ; μ'] := calc
H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[⟨X', Y'₁⟩ ; μA] := by
let f : G × G → G × G := fun ⟨x, y₁⟩ ↦ (x, x - 2 • y₁)
show H[f ∘ ⟨X', Y'₁⟩ ; μA] = _
apply entropy_comp_of_injective μA (by exact Measurable.prod hX'_meas hY'₁_meas) f
exact fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + H[Y ; μ'] := by
rw [IndepFun.entropy_pair_eq_add hX'_meas hY'₁_meas (h_indep.indepFun (show 0 ≠ 1 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq]
let f : G × G → G × G := fun ⟨x, y⟩ ↦ (x, y - x)
have hf : f.Injective := fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all
have : H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] := calc
H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] = H[f ∘ ⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
show _ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂ - (Y'₁ - Y'₂)⟩ ; μA]
rw [sub_sub_sub_cancel_right, ← sub_add_eq_sub_sub, two_nsmul]
_ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
refine entropy_comp_of_injective μA (Measurable.prod ?_ ?_) f hf
· exact Measurable.sub hY'₁_meas hY'₂_meas
· exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
_ ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] :=
entropy_pair_le_add (hY'₁_meas.sub' hY'₂_meas) (hX'_meas.sub' hY'₁_meas |>.sub' hY'₂_meas) μA
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] + H[X' - 2 • Y'₁ ; μA] ≤
H[⟨X', X' - 2 • Y'₁⟩ ; μA] + H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] := by
haveI : FiniteRange (Y'₁ - Y'₂) := FiniteRange.sub Y'₁ Y'₂
haveI : FiniteRange (2 • Y'₁) := by show FiniteRange ((fun x ↦ 2 • x) ∘ Y'₁); infer_instance
apply entropy_triple_add_entropy_le μA hX'_meas (Measurable.sub hY'₁_meas hY'₂_meas)
exact Measurable.sub' hX'_meas <| Measurable.const_smul hY'₁_meas 2
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨y₁, y₂, x⟩ ↦ (y₁, y₂, x - y₁ - y₂)
show H[f ∘ ⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA]
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hY'₁_meas <| Measurable.prod hY'₂_meas hX'_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun Y'₁ (prod Y'₂ X') μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 2 0 1 (by decide) (by decide)
rw [this.entropy_pair_eq_add hY'₁_meas (by exact Measurable.prod hY'₂_meas hX'_meas),
IndepFun.entropy_pair_eq_add hY'₂_meas hX'_meas (h_indep.indepFun (show 2 ≠ 0 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq]
group
have : H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₂ ; μA] := calc
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₁, X' - Y'₂⟩ ; μA] := by rw [sub_right_comm] ; rfl
_ = H[⟨Y'₁, X' - Y'₂⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₁_meas <| Measurable.sub hX'_meas hY'₂_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₂ ; μA] := by
haveI : FiniteRange (X' - Y'₂) := FiniteRange.sub X' Y'₂
convert IndepFun.entropy_pair_eq_add hY'₁_meas (hX'_meas.sub hY'₂_meas)
<| h_indep.indepFun_sub_right h_meas 1 0 2 (by decide) (by decide)
exact hY'₁_ident.entropy_eq.symm
have : H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₁ ; μA] := calc
H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₂, X' - Y'₁⟩ ; μA] := rfl
_ = H[⟨Y'₂, X' - Y'₁⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₂_meas <| Measurable.sub hX'_meas hY'₁_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₁ ; μA] := by
haveI : FiniteRange (X' - Y'₁) := FiniteRange.sub X' Y'₁
convert IndepFun.entropy_pair_eq_add hY'₂_meas (hX'_meas.sub hY'₁_meas)
<| h_indep.indepFun_sub_right h_meas 2 0 1 (by decide) (by decide)
exact hY'₂_ident.entropy_eq.symm
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] ≤
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] + H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
apply entropy_triple_add_entropy_le μA hY'₁_meas hY'₂_meas
exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
have : H[X' - Y'₁ - Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := calc
H[X' - Y'₁ - Y'₂ ; μA] ≤ H[X' - Y'₁ ; μA] + H[X' - Y'₂ ; μA] - H[X ; μ] := by linarith
_ = 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := by
nth_rw 1 [two_mul, ← hX'_ident.rdist_eq hY'₁_ident, ← hX'_ident.rdist_eq hY'₂_ident]
have h1 : d[X' ; μA # Y'₁ ; μA] = H[X' - Y'₁ ; μA] - H[X' ; μA] / 2 - H[Y'₁ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 1 by decide)).rdist_eq hX'_meas hY'₁_meas
have h2 : d[X' ; μA # Y'₂ ; μA] = H[X' - Y'₂ ; μA] - H[X' ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 2 by decide)).rdist_eq hX'_meas hY'₂_meas
rw [h1, h2, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, hX'_ident.entropy_eq]
group
have : d[X ; μ # 2 • Y ; μ'] ≤
d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := calc
d[X ; μ # 2 • Y ; μ'] = H[X' - 2 • Y'₁ ; μA] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by
have h2Y_ident : IdentDistrib (2 • Y'₁) (2 • Y) (μ := μA) (ν := μ') := by
convert hY'₁_ident.comp <| measurable_discrete <| fun g ↦ 2 • g
have h2Y_indep : IndepFun X' (2 • Y'₁) (μ := μA) := by
convert (h_indep.indepFun (show 0 ≠ 1 by decide)).comp measurable_id
(measurable_const_smul 2)
rw [← hX'_ident.rdist_eq h2Y_ident,
h2Y_indep.rdist_eq hX'_meas <| Measurable.const_smul hY'₁_meas 2,
hX'_ident.entropy_eq, h2Y_ident.entropy_eq]
_ ≤ H[Y'₁ - Y'₂ ; μA] + 2 * d[X ; μ # Y ; μ'] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by linarith
_ = d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := by
have H2Y : H[2 • Y ; μ'] = H[Y ; μ'] := by
let f (g : G) := 2 • g
exact entropy_comp_of_injective μ' hY f (fun _ _ ↦ by simp [f, smul_right_inj])
have : d[Y'₁ ; μA # Y'₂ ; μA] = H[Y'₁ - Y'₂ ; μA] - H[Y'₁ ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 1 ≠ 2 by decide)).rdist_eq hY'₁_meas hY'₂_meas
rw [this, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, H2Y]
group
have : d[Y'₁ ; μA # Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] := by
rw [two_mul]
convert rdist_triangle hY'₁_meas hX'_meas hY'₂_meas (μ := μA) (μ' := μA) (μ'' := μA)
· exact rdist_symm.trans (hY'₁_ident.rdist_eq hX'_ident).symm
· exact (hX'_ident.rdist_eq hY'₂_ident).symm
rw [← two_nsmul]
linarith [abs_le.mp <| diff_ent_le_rdist hX hY (μ := μ) (μ' := μ')]
/-- If $G$ is a torsion-free group and $X,Y$ are $G$-valued random variables and
$\phi : G\to \mathbb{F}_2^d$ is a homomorphism then
\[\mathbb{H}(\phi(X))\leq 10d[X;Y].\] -/
lemma torsion_dist_shrinking {H : Type u} [FiniteRange X] [FiniteRange Y] (hX : Measurable X)
(hY : Measurable Y) [AddCommGroup H] [ElementaryAddCommGroup H 2]
[MeasurableSpace H] [MeasurableSingletonClass H] [Countable H]
(hG : AddMonoid.IsTorsionFree G) (φ : G →+ H) :
H[φ ∘ X ; μ] ≤ 10 * d[X; μ # Y ; μ'] := by
have :=
calc d[φ ∘ X ; μ # φ ∘ (Y + Y); μ'] ≤ d[X; μ # (Y + Y) ; μ'] := rdist_of_hom_le φ hX (Measurable.add hY hY)
_ ≤ 5 * d[X; μ # Y ; μ'] := torsion_free_doubling X Y μ μ' hX hY hG
have eq_zero : φ ∘ (Y + Y) = fun _ ↦ 0 := by ext x ; simp only [Function.comp_apply, Pi.add_apply,
map_add, ElementaryAddCommGroup.add_self]
rwa [eq_zero, rdist_zero_eq_half_ent, div_le_iff zero_lt_two, mul_assoc, mul_comm _ 2, ←mul_assoc,
show (5*2 : ℝ) = 10 by norm_num] at this
end Torsion
instance {G : Type u} [AddCommGroup G] [Fintype G] [MeasurableSpace G] [MeasurableSingletonClass G] (H : AddSubgroup G)
: MeasurableSingletonClass (G ⧸ H) :=
⟨λ _ ↦ by { rw [measurableSet_quotient]; simp [measurableSet_discrete] }⟩
section F2_projection
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [ElementaryAddCommGroup G 2] [Fintype G] [MeasurableSpace G]
[MeasurableSingletonClass G] {Ω Ω' : Type*}
/-- Let $G=\mathbb{F}_2^n$ and $X,Y$ be $G$-valued random variables such that
\[\mathbb{H}(X)+\mathbb{H}(Y)> (20/\alpha) d[X;Y],\]
for some $\alpha > 0$.
There is a non-trivial subgroup $H\leq G$ such that
\[\log \lvert H\rvert <(1+\alpha)/2 (\mathbb{H}(X)+\mathbb{H}(Y))\] and
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))< \alpha (\mathbb{H}(X)+\mathbb{H}(Y))\]
where $\psi:G\to G/H$ is the natural projection homomorphism.
-/
lemma app_ent_PFR' [MeasureSpace Ω] [MeasureSpace Ω'] (X : Ω → G) (Y : Ω' → G)
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
{α : ℝ} (hent : 20 * d[X # Y] < α * (H[X] + H[Y])) (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X] + H[Y]) ∧
H[(QuotientAddGroup.mk' H) ∘ X] + H[(QuotientAddGroup.mk' H) ∘ Y] < α * (H[X] + H[Y]) := by
let p : refPackage Ω Ω' G := {
X₀₁ := X
X₀₂ := Y
hmeas1 := hX
hmeas2 := hY
η := 1/8
hη := by norm_num
hη' := by norm_num }
obtain ⟨H, Ω'', hΩ'', U, _, hUmeas, hUunif, ineq⟩ := entropic_PFR_conjecture_improv p rfl
let ψ := (QuotientAddGroup.mk' H)
use H
haveI : Finite H := Subtype.finite
-- Note that H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y]
have ent_le : H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y] := calc
H[ψ ∘ X] + H[ψ ∘ Y] ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· exact ent_of_proj_le hX hUmeas hUunif
· exact ent_of_proj_le hY hUmeas hUunif
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- Note that (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y]
have log_sub_le : (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y] := calc
(log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) =
(H[U] - H[X]) + (H[U] - H[Y]) := by
rw [IsUniform.entropy_eq' hUunif hUmeas, SetLike.coe_sort_coe]
_ ≤ |(H[U] - H[X])| + |(H[U] - H[Y])| := by gcongr <;> exact le_abs_self _
_ ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hX
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hY
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- then the conclusion follows from the assumption `hent` and basic inequality manipulations
exact ⟨by linarith, by linarith⟩
variable [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ' : Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
lemma app_ent_PFR (α : ℝ) (hent: 20 * d[X;μ # Y;μ'] < α * (H[X; μ] + H[Y; μ'])) (hX : Measurable X)
(hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ']
< α * (H[ X; μ] + H[Y; μ']) :=
@app_ent_PFR' _ _ _ _ _ _ _ _ (MeasureSpace.mk μ) (MeasureSpace.mk μ') _ _ _ _ α hent hX hY
set_option maxHeartbeats 300000 in
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables and $\alpha < 1$ then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq (1 + α) / (2 * (1 - α)) * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 20/\alpha * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection'
(α : ℝ) (hX : Measurable X) (hY : Measurable Y) (αpos : 0 < α) (αone : α < 1) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (H[X ; μ] + H[Y ; μ']) ∧
α * (H[(QuotientAddGroup.mk' H) ∘ X ; μ] + H[(QuotientAddGroup.mk' H) ∘ Y ; μ']) ≤
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] := by
let S := { H : AddSubgroup G | (∃ (c : ℝ), 0 ≤ c ∧
log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (1 - c) * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
c * (H[X; μ] + H[Y;μ'])) ∧
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] <
α * (H[ (QuotientAddGroup.mk' H) ∘ X; μ ] + H[ (QuotientAddGroup.mk' H) ∘ Y; μ']) }
have : 0 ≤ H[X ; μ] + H[Y ; μ'] := by linarith [entropy_nonneg X μ, entropy_nonneg Y μ']
have : 0 < 1 - α := sub_pos.mpr αone
by_cases hE : (⊥ : AddSubgroup G) ∈ S
· classical
obtain ⟨H, ⟨⟨c, hc, hlog, hup⟩, hent⟩, hMaxl⟩ :=
S.toFinite.exists_maximal_wrt id S (Set.nonempty_of_mem hE)
set ψ : G →+ G ⧸ H := QuotientAddGroup.mk' H
have surj : Function.Surjective ψ := QuotientAddGroup.mk'_surjective H
set G' := G ⧸ H
have : ElementaryAddCommGroup G' 2 := ElementaryAddCommGroup.quotient_group (by decide)
(by simp [AddSubgroup.zero_mem])
obtain ⟨H', hlog', hup'⟩ := app_ent_PFR _ _ _ _ α hent ((measurable_discrete _).comp hX)
((measurable_discrete _).comp hY)
have H_ne_bot: H' ≠ ⊥ := by
by_contra!
rcases this with rfl
have inj : Function.Injective (QuotientAddGroup.mk' (⊥ : AddSubgroup G')) :=
(QuotientAddGroup.quotientBot : (G' ⧸ ⊥) ≃+ G').symm.injective
rw [entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ inj,
entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ inj] at hup'
nlinarith [entropy_nonneg (ψ ∘ X) μ, entropy_nonneg (ψ ∘ Y) μ']
let H'' := H'.comap ψ
use H''
rw [← (AddSubgroup.map_comap_eq_self_of_surjective surj _ : H''.map ψ = H')] at hup' hlog'
set H' := H''.map ψ
have Hlt : H < H'' := by
have : H = (⊥ : AddSubgroup G').comap ψ := by
simp only [ψ, AddMonoidHom.comap_bot, QuotientAddGroup.ker_mk']
rw [this, AddSubgroup.comap_lt_comap_of_surjective surj]
exact Ne.bot_lt H_ne_bot
let φ : G' ⧸ H' ≃+ G ⧸ H'' := QuotientAddGroup.quotientQuotientEquivQuotient H H'' Hlt.le
set ψ' : G' →+ G' ⧸ H' := QuotientAddGroup.mk' H'
set ψ'' : G →+ G ⧸ H'' := QuotientAddGroup.mk' H''
have diag : ψ' ∘ ψ = φ.symm ∘ ψ'' := rfl
rw [← Function.comp.assoc, ← Function.comp.assoc, diag, Function.comp.assoc,
Function.comp.assoc] at hup'
have cond : log (Nat.card H'') ≤
(1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := by
have cardprod : Nat.card H'' = Nat.card H' * Nat.card H := by
have hcard₀ := Nat.card_congr <| (AddSubgroup.addSubgroupOfEquivOfLe Hlt.le).toEquiv
have hcard₁ := Nat.card_congr <|
(QuotientAddGroup.quotientKerEquivRange (ψ.restrict H'')).toEquiv
have hcard₂ := AddSubgroup.card_eq_card_quotient_mul_card_addSubgroup (H.addSubgroupOf H'')
rw [ψ.ker_restrict H'', QuotientAddGroup.ker_mk', ψ.restrict_range H''] at hcard₁
simpa only [← Nat.card_eq_fintype_card, hcard₀, hcard₁] using hcard₂
calc
log (Nat.card H'')
_ = log ((Nat.card H' : ℝ) * (Nat.card H : ℝ)) := by rw [cardprod]; norm_cast
_ = log (Nat.card H') + log (Nat.card H) := by
rw [Real.log_mul (Nat.cast_ne_zero.2 (@Nat.card_pos H').ne')
(Nat.cast_ne_zero.2 (@Nat.card_pos H).ne')]
_ ≤ (1 + α) / 2 * (H[⇑ψ ∘ X ; μ] + H[⇑ψ ∘ Y ; μ']) + log (Nat.card H) := by gcongr
_ ≤ (1 + α) / 2 * (c * (H[X; μ] + H[Y;μ'])) +
(1 + α) / (2 * (1 - α)) * (1 - c) * (H[X ; μ] + H[Y ; μ']) := by gcongr
_ = (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X ; μ] + H[Y ; μ']) := by
field_simp; ring
have HS : H'' ∉ S := λ Hs => Hlt.ne (hMaxl H'' Hs Hlt.le)
simp only [S, Set.mem_setOf_eq, not_and, not_lt] at HS
refine ⟨?_, HS ⟨α * c, by positivity, cond, ?_⟩⟩
· calc
log (Nat.card H'')
_ ≤ (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := cond
_ ≤ (1 + α) / (2 * (1 - α)) * 1 * (H[X; μ] + H[Y;μ']) := by gcongr; simp; positivity
_ = (1 + α) / (2 * (1 - α)) * (H[X; μ] + H[Y;μ']) := by simp only [mul_one]
· calc
H[ ψ'' ∘ X; μ ] + H[ ψ'' ∘ Y; μ' ]
_ = H[ φ.symm ∘ ψ'' ∘ X; μ ] + H[ φ.symm ∘ ψ'' ∘ Y; μ' ] := by
simp_rw [← entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ φ.symm.injective,
← entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ φ.symm.injective]
_ ≤ α * (H[ ψ ∘ X; μ ] + H[ ψ ∘ Y; μ' ]) := hup'.le
_ ≤ α * (c * (H[X ; μ] + H[Y ; μ'])) := by gcongr
_ = (α * c) * (H[X ; μ] + H[Y ; μ']) := by ring
· use ⊥
constructor
· simp only [AddSubgroup.mem_bot, Nat.card_eq_fintype_card, Fintype.card_ofSubsingleton,
Nat.cast_one, log_one]
positivity
· simp only [S, Set.mem_setOf_eq, not_and, not_lt] at hE
exact hE ⟨1, by norm_num, by
norm_num; exact add_le_add (entropy_comp_le μ hX _) (entropy_comp_le μ' hY _)⟩
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq 2 * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 34 * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
34 * d[(QuotientAddGroup.mk' H) ∘ X;μ # (QuotientAddGroup.mk' H) ∘ Y;μ'] := by
rcases PFR_projection' X Y μ μ' ((3 : ℝ) / 5) hX hY (by norm_num) (by norm_num) with ⟨H, h, h'⟩
refine ⟨H, ?_, ?_⟩
· convert h
norm_num
· have : 0 ≤ d[⇑(QuotientAddGroup.mk' H) ∘ X ; μ # ⇑(QuotientAddGroup.mk' H) ∘ Y ; μ'] :=
rdist_nonneg ((measurable_discrete _).comp hX) ((measurable_discrete _).comp hY)
linarith
end F2_projection
open MeasureTheory ProbabilityTheory Real Set
open scoped BigOperators
lemma four_logs {a b c d : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) (hd : 0 < d) :
log ((a*b)/(c*d)) = log a + log b - log c - log d := by
rw [log_div, log_mul, log_mul, sub_sub] <;> positivity
lemma sum_prob_preimage {G H : Type*} {X : Finset H} {A : Set G} [Finite A] {φ : A → X}
{A_ : H → Set G} (hA : A.Nonempty) (hφ : ∀ x : X, A_ x = Subtype.val '' (φ ⁻¹' {x})) :
∑ x in X, (Nat.card (A_ x) : ℝ) / (Nat.card A) = 1 := by
rw [← Finset.sum_div]
apply (div_eq_one_iff_eq <| Nat.cast_ne_zero.mpr <| Nat.pos_iff_ne_zero.mp (@Nat.card_pos _ hA.to_subtype _)).mpr
classical
haveI := Fintype.ofFinite A
rewrite [Nat.card_eq_fintype_card, ← Finset.card_univ, Finset.card_eq_sum_card_fiberwise
<| fun a _ ↦ Finset.mem_univ (φ a), ← Finset.sum_coe_sort]
norm_cast
congr; ext
rewrite [← Set.Finite.toFinset_setOf, (Set.toFinite _).card_toFinset, ← Nat.card_eq_fintype_card,
hφ, Nat.card_image_of_injective Subtype.val_injective]; rfl
/-- Let $\phi : G\to H$ be a homomorphism and $A,B\subseteq G$ be finite subsets. If $x,y\in H$ then let $A_x=A\cap \phi^{-1}(x)$ and $B_y=B\cap \phi^{-1}(y)$. There exist $x,y\in H$ such that $A_x,B_y$ are both non-empty and
\[d[\phi(U_A);\phi(U_B)]\log \frac{\lvert A\rvert\lvert B\rvert}{\lvert A_x\rvert\lvert B_y\rvert}\leq (\mathbb{H}(\phi(U_A))+\mathbb{H}(\phi(U_B)))(d(U_A,U_B)-d(U_{A_x},U_{B_y}).\] -/
lemma single_fibres {G H Ω Ω': Type u}
[AddCommGroup G] [Countable G] [MeasurableSpace G] [MeasurableSingletonClass G]
[AddCommGroup H] [Countable H] [MeasurableSpace H] [MeasurableSingletonClass H]
[MeasureSpace Ω] [MeasureSpace Ω']
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
(φ : G →+ H)
{A B : Set G} [Finite A] [Finite B] {UA : Ω → G} {UB: Ω' → G} (hA : A.Nonempty) (hB : B.Nonempty)
(hUA': Measurable UA) (hUB': Measurable UB) (hUA: IsUniform A UA) (hUB: IsUniform B UB)
(hUA_mem : ∀ ω, UA ω ∈ A) (hUB_mem : ∀ ω, UB ω ∈ B) :
∃ (x y : H) (Ax By: Set G),
Ax = A ∩ φ.toFun ⁻¹' {x} ∧ By = B ∩ φ.toFun ⁻¹' {y} ∧ Ax.Nonempty ∧ By.Nonempty ∧
d[φ.toFun ∘ UA # φ.toFun ∘ UB]
* log ((Nat.card A) * (Nat.card B) / ((Nat.card Ax) * (Nat.card By))) ≤
(H[φ.toFun ∘ UA] + H[φ.toFun ∘ UB]) * (d[UA # UB] - dᵤ[Ax # By]) := by
have : Nonempty A := hA.to_subtype
have : Nonempty B := hB.to_subtype
haveI : FiniteRange UA := finiteRange_of_finset UA A.toFinite.toFinset (by simpa)
haveI : FiniteRange UB := finiteRange_of_finset UB B.toFinite.toFinset (by simpa)
have hUA_coe : IsUniform A.toFinite.toFinset.toSet UA := by rwa [Set.Finite.coe_toFinset]
have hUB_coe : IsUniform B.toFinite.toFinset.toSet UB := by rwa [Set.Finite.coe_toFinset]
let A_ (x : H) : Set G := A ∩ φ.toFun ⁻¹' {x}
let B_ (y : H) : Set G := B ∩ φ.toFun ⁻¹' {y}
let X : Finset H := FiniteRange.toFinset (φ.toFun ∘ UA)
let Y : Finset H := FiniteRange.toFinset (φ.toFun ∘ UB)
haveI h_Ax (x : X) : Nonempty (A_ x.val) := by
obtain ⟨ω, hω⟩ := (FiniteRange.mem_iff _ _).mp x.property
use UA ω; exact Set.mem_inter (hUA_mem ω) (by exact hω)
haveI h_By (y : Y) : Nonempty (B_ y.val) := by
obtain ⟨ω, hω⟩ := (FiniteRange.mem_iff _ _).mp y.property
use UB ω; exact Set.mem_inter (hUB_mem ω) (by exact hω)
have h_AX (a : A) : φ.toFun a.val ∈ X := by
obtain ⟨ω, hω⟩ := hUA_coe.nonempty_preimage_of_mem hUA' (A.toFinite.mem_toFinset.mpr a.property)
exact (FiniteRange.mem_iff _ (φ.toFun a.val)).mpr ⟨ω, congr_arg _ hω⟩
have h_BY (b : B) : φ.toFun b.val ∈ Y := by
obtain ⟨ω, hω⟩ := hUB_coe.nonempty_preimage_of_mem hUB' (B.toFinite.mem_toFinset.mpr b.property)
exact (FiniteRange.mem_iff _ (φ.toFun b.val)).mpr ⟨ω, congr_arg _ hω⟩
let φ_AX (a : A) : X := by use φ.toFun a.val; exact h_AX a
let φ_BY (b : B) : Y := by use φ.toFun b.val; exact h_BY b
have h_φ_AX (x : X) : A_ x.val = φ_AX ⁻¹' {x} := by ext; simp [A_, φ_AX]; simp [Subtype.ext_iff]
have h_φ_BY (y : Y) : B_ y.val = φ_BY ⁻¹' {y} := by ext; simp [B_, φ_BY]; simp [Subtype.ext_iff]
let p (x : H) (y : H) : ℝ :=
(Nat.card (A_ x).Elem) * (Nat.card (B_ y).Elem) / ((Nat.card A.Elem) * (Nat.card B.Elem))
have :
∑ x in X, ∑ y in Y, (p x y) * dᵤ[A_ x # B_ y] ≤ d[UA # UB] - d[φ.toFun ∘ UA # φ.toFun ∘ UB] :=
calc
_ = d[UA | φ.toFun ∘ UA # UB | φ.toFun ∘ UB] := by
rewrite [condRuzsaDist_eq_sum hUA' ((measurable_discrete _).comp hUA')
hUB' ((measurable_discrete _).comp hUB')]
refine Finset.sum_congr rfl <| fun x hx ↦ Finset.sum_congr rfl <| fun y hy ↦ ?_
haveI : Nonempty (A_ x) := h_Ax ⟨x, hx⟩
haveI : Nonempty (B_ y) := h_By ⟨y, hy⟩
let μx := (ℙ : Measure Ω)[|(φ.toFun ∘ UA) ⁻¹' {x}]
let μy := (ℙ : Measure Ω')[|(φ.toFun ∘ UB) ⁻¹' {y}]
have h_μ_p : IsProbabilityMeasure μx ∧ IsProbabilityMeasure μy := by
constructor <;> apply ProbabilityTheory.cond_isProbabilityMeasure <;> rw [Set.preimage_comp]
refine @IsUniform.measure_preimage_ne_zero _ _ _ _ _ _ _ _ _ _ hUA_coe hUA' _ ?_
swap; refine @IsUniform.measure_preimage_ne_zero _ _ _ _ _ _ _ _ _ _ hUB_coe hUB' _ ?_
all_goals rwa [Set.inter_comm, Set.Finite.coe_toFinset]
have h_μ_unif : IsUniform (A_ x) UA μx ∧ IsUniform (B_ y) UB μy := by
have : _ ∧ _ := ⟨hUA.restrict hUA' (φ.toFun ⁻¹' {x}), hUB.restrict hUB' (φ.toFun ⁻¹' {y})⟩
rwa [Set.inter_comm _ A, Set.inter_comm _ B] at this
rewrite [rdist_set_eq_rdist h_μ_p.1 h_μ_p.2 h_μ_unif.1 h_μ_unif.2 hUA' hUB']
show _ = (Measure.real _ (UA ⁻¹' (_ ⁻¹' _))) * (Measure.real _ (UB ⁻¹' (_ ⁻¹' _))) * _
rewrite [hUA_coe.measureReal_preimage hUA', hUB_coe.measureReal_preimage hUB']
simp_rw [p, A_, B_, IsProbabilityMeasure.measureReal_univ, one_mul]
rewrite [mul_div_mul_comm, Set.inter_comm A, Set.inter_comm B]
simp only [Set.Finite.coe_toFinset, Set.Finite.mem_toFinset, Finset.mem_val]; rfl
_ ≤ d[UA # UB] - d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
rewrite [ZeroHom.toFun_eq_coe, AddMonoidHom.toZeroHom_coe]
linarith only [rdist_le_sum_fibre φ hUA' hUB' (μ := ℙ) (μ' := ℙ)]
let M := H[φ.toFun ∘ UA] + H[φ.toFun ∘ UB]
have hM : M = ∑ x in X, ∑ y in Y, Real.negMulLog (p x y) := by
have h_compl {x y} (h_notin : (x, y) ∉ X ×ˢ Y) : Real.negMulLog (p x y) = 0 := by
unfold_let p; beta_reduce
rewrite [Finset.mem_product, not_and_or] at h_notin
suffices A_ x = ∅ ∨ B_ y = ∅ by obtain h | h := this <;> rw [h] <;> simp
refine h_notin.imp ?_ ?_
· rw [← not_nonempty_iff_eq_empty]
rintro h ⟨a, ha, rfl⟩
exact h (h_AX ⟨a, ha⟩)
· rw [← not_nonempty_iff_eq_empty]
rintro h ⟨a, ha, rfl⟩
exact h (h_BY ⟨a, ha⟩)
unfold_let M
unfold entropy
haveI := isProbabilityMeasure_map (μ := ℙ) ((measurable_discrete φ).comp hUA').aemeasurable
haveI := isProbabilityMeasure_map (μ := ℙ) ((measurable_discrete φ).comp hUB').aemeasurable
rewrite [← Finset.sum_product', ← tsum_eq_sum fun _ ↦ h_compl, ← measureEntropy_prod]
apply tsum_congr; intro; congr
rewrite [← Set.singleton_prod_singleton, Measure.smul_apply, Measure.prod_prod,
Measure.map_apply ((measurable_discrete _).comp hUA') (MeasurableSet.singleton _),
Measure.map_apply ((measurable_discrete _).comp hUB') (MeasurableSet.singleton _),
Set.preimage_comp, hUA_coe.measure_preimage hUA',
Set.preimage_comp, hUB_coe.measure_preimage hUB']
simp [p, A_, B_, mul_div_mul_comm, Set.inter_comm, ENNReal.toReal_div]
have h_sum : ∑ x in X, ∑ y in Y,
(p x y) * (M * dᵤ[A_ x # B_ y] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p x y)) ≤
M * d[UA # UB] :=
calc
_ = ∑ x in X, ∑ y in Y, (p x y) * M * dᵤ[A_ x # B_ y] + M * d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
simp_rw [hM, Finset.sum_mul, ← Finset.sum_add_distrib]
refine Finset.sum_congr rfl <| fun _ _ ↦ Finset.sum_congr rfl <| fun _ _ ↦ ?_
simp only [negMulLog, left_distrib, mul_assoc, Finset.sum_mul]
exact congrArg (HAdd.hAdd _) (by group)
_ = M * ∑ x in X, ∑ y in Y, (p x y) * dᵤ[A_ x # B_ y] + M * d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
simp_rw [Finset.mul_sum]
congr; ext; congr; ext; group
_ ≤ M * d[UA # UB] := by
rewrite [← left_distrib]
apply mul_le_mul_of_nonneg_left
· linarith
· unfold_let M
linarith only [entropy_nonneg (φ.toFun ∘ UA) ℙ, entropy_nonneg (φ.toFun ∘ UB) ℙ]
have : ∃ x : X, ∃ y : Y,
M * dᵤ[A_ x.val # B_ y.val] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p x.val y.val) ≤
M * d[UA # UB] := by
let f (xy : H × H) := (p xy.1 xy.2) * (M * d[UA # UB])
let g (xy : H × H) := (p xy.1 xy.2) *
(M * dᵤ[A_ xy.1 # B_ xy.2] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p xy.1 xy.2))
by_contra hc; push_neg at hc
replace hc : ∀ xy ∈ X ×ˢ Y, f xy < g xy := by
refine fun xy h ↦ mul_lt_mul_of_pos_left ?_ ?_
· exact hc ⟨xy.1, (Finset.mem_product.mp h).1⟩ ⟨xy.2, (Finset.mem_product.mp h).2⟩
· haveI : Nonempty _ := h_Ax ⟨xy.1, (Finset.mem_product.mp h).1⟩
haveI : Nonempty _ := h_By ⟨xy.2, (Finset.mem_product.mp h).2⟩
simp only [p, div_pos, mul_pos, Nat.cast_pos, Nat.card_pos]
have h_nonempty : Finset.Nonempty (X ×ˢ Y) := by
use ⟨φ.toFun <| UA <| Classical.choice <| ProbabilityMeasure.nonempty ⟨ℙ, inferInstance⟩,
φ.toFun <| UB <| Classical.choice <| ProbabilityMeasure.nonempty ⟨ℙ, inferInstance⟩⟩
exact Finset.mem_product.mpr ⟨FiniteRange.mem _ _, FiniteRange.mem _ _⟩
replace hc := Finset.sum_lt_sum_of_nonempty h_nonempty hc
have h_p_one : ∑ x in X ×ˢ Y, p x.1 x.2 = 1 := by
simp_rw [Finset.sum_product, p, mul_div_mul_comm, ← Finset.mul_sum,
← sum_prob_preimage hA h_φ_AX, sum_prob_preimage hB h_φ_BY, mul_one]
rewrite [← Finset.sum_mul, h_p_one, one_mul, Finset.sum_product] at hc
exact not_le_of_gt hc h_sum
obtain ⟨x, y, hxy⟩ := this
refine ⟨x, y, A_ x.val, B_ y.val, rfl, rfl, @nonempty_of_nonempty_subtype _ _ (h_Ax x), @nonempty_of_nonempty_subtype _ _ (h_By y), ?_⟩
rewrite [← inv_div, Real.log_inv]
show _ * -log (p x.val y.val) ≤ M * _
linarith only [hxy]
section dim
open Classical
variable {G : Type*} [AddCommGroup G]
/- If G ≅ ℤᵈ then there is a subgroup H of G such that A lies in a coset of H. This is helpful to
give the equivalent definition of `dimension`. Here this is stated in greated generality since the
proof carries over automatically-/
lemma exists_coset_cover (A : Set G) :
∃ (d : ℕ), ∃ (S : Submodule ℤ G) (v : G),
FiniteDimensional.finrank ℤ S = d ∧ ∀ a ∈ A, a - v ∈ S := by
existsi FiniteDimensional.finrank ℤ (⊤ : Submodule ℤ G), ⊤, 0
refine ⟨rfl, fun a _ ↦ trivial⟩
/-- The dimension of the affine span over `ℤ` of a subset of an additive group. -/
noncomputable def dimension (A : Set G) : ℕ := Nat.find (exists_coset_cover A)
| lemma dimension_le_of_coset_cover (A : Set G) (S : Submodule ℤ G) (v : G)
(hA : ∀ a ∈ A, a - v ∈ S) : dimension A ≤ FiniteDimensional.finrank ℤ S | dimension_le_of_coset_cover | 25309ad 20231211 | c0c547a 20240116 | pfr/PFR/WeakPFR.lean | {
"lineInFile": 604,
"tokenPositionInFile": 33913,
"theoremPositionInFile": 17
} | {
"inFilePremises": false,
"repositoryPremises": false
} | {
"hasProof": true,
"proof": "by\n apply Nat.find_le\n existsi S , v\n exact ⟨rfl, hA⟩",
"proofType": "tactic",
"proofLengthLines": 4,
"proofLengthTokens": 56
} | pfr |
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Quotient
import Mathlib.GroupTheory.Torsion
import Mathlib.GroupTheory.Torsion
import Mathlib.LinearAlgebra.FreeModule.PID
import PFR.Mathlib.Data.Set.Pointwise.SMul
import PFR.EntropyPFR
import PFR.ImprovedPFR
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Mathlib.GroupTheory.Torsion
/-!
# Weak PFR over the integers
Here we use the entropic form of PFR to deduce a weak form of PFR over the integers.
## Main statement
* `weak_PFR_int`: Let $A\subseteq \mathbb{Z}^d$ and $\lvert A+A\rvert\leq K\lvert A\rvert$.
There exists $A'\subseteq A$ such that $\lvert A'\rvert \geq K^{-17}\lvert A\rvert$ and
$\dim A' \leq (40/\log 2)\log K$.
-/
section AddCommGroup
variable {G : Type*} [AddCommGroup G] {A B : Set G}
open Set
open scoped Pointwise
def IsShift (A B : Set G) : Prop := ∃ x : G, A = x +ᵥ B
lemma IsShift.sub_self_congr : IsShift A B → A - A = B - B := by
rintro ⟨x, rfl⟩; simp [vadd_sub_vadd_comm, singleton_zero]
lemma IsShift.card_congr : IsShift A B → Nat.card A = Nat.card B := by rintro ⟨x, rfl⟩; simp
/-- The property of two sets A, B of a group G not being contained in cosets of the same proper
subgroup -/
def NotInCoset (A B : Set G) : Prop := AddSubgroup.closure ((A - A) ∪ (B - B)) = ⊤
/-- Without loss of generality, one can move (up to translation and embedding) any pair A, B of non-empty sets into a subgroup where they are not in a coset. -/
lemma wlog_notInCoset (hA : A.Nonempty) (hB : B.Nonempty) :
∃ (G' : AddSubgroup G) (A' B' : Set G'), IsShift A A' ∧ IsShift B B' ∧ NotInCoset A' B' := by
obtain ⟨x, hx⟩ := hA
obtain ⟨y, hy⟩ := hB
set G' := AddSubgroup.closure ((A - A) ∪ (B - B))
set A' : Set G' := (↑) ⁻¹' ((-x) +ᵥ A)
set B' : Set G' := (↑) ⁻¹' ((-y) +ᵥ B)
have hxA : -x +ᵥ A ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hx).trans $ (subset_union_left ..).trans
AddSubgroup.subset_closure
have hyB : -y +ᵥ B ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hy).trans $ (subset_union_right ..).trans
AddSubgroup.subset_closure
have hA : IsShift A A' := ⟨x, by rw [Set.image_preimage_eq_of_subset hxA, vadd_neg_vadd]⟩
have hB : IsShift B B' := ⟨y, by rw [Set.image_preimage_eq_of_subset hyB, vadd_neg_vadd]⟩
refine ⟨G', A', B', hA, hB, ?_⟩
unfold NotInCoset
convert AddSubgroup.closure_preimage_eq_top ((A - A) ∪ (B - B))
simp_rw [preimage_union, hA.sub_self_congr, hB.sub_self_congr]
rw [preimage_sub, preimage_sub]
simp [A', B', preimage_image_preimage]
all_goals apply_rules [Subtype.coe_injective, (image_preimage_subset ..).trans, hxA, hyB]
end AddCommGroup
section Torsion
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [MeasurableSpace G] [MeasurableSingletonClass G]
[Countable G] {Ω Ω' : Type u} [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ': Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
/-- If $G$ is torsion-free and $X,Y$ are $G$-valued random variables then $d[X;2Y]\leq 5d[X;Y]$. -/
lemma torsion_free_doubling [FiniteRange X] [FiniteRange Y]
(hX : Measurable X) (hY : Measurable Y) (hG : AddMonoid.IsTorsionFree G) :
d[X ; μ # (Y + Y) ; μ'] ≤ 5 * d[X; μ # Y ; μ'] := by
obtain ⟨A, mA, μA, X', Y'₁, Y'₂, hμA, h_indep, hX'_meas, hY'₁_meas, hY'₂_meas, hX'_ident,
hY'₁_ident, hY'₂_ident, _, _, _⟩ := independent_copies3_nondep_finiteRange hX hY hY μ μ' μ'
have h_meas (i : Fin 3) : Measurable (![X', Y'₁, Y'₂] i) := by fin_cases i <;> assumption
haveI : NoZeroSMulDivisors ℕ G := hG.noZeroNsmulDivisors
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨x, y₁, y₂⟩ ↦ (x, y₁ - y₂, x - 2 • y₁)
show H[f ∘ ⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] = _
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hX'_meas <| Measurable.prod hY'₁_meas hY'₂_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun X' (prod Y'₁ Y'₂) μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 1 2 0 (by decide) (by decide)
rw [this.entropy_pair_eq_add hX'_meas (by exact Measurable.prod hY'₁_meas hY'₂_meas),
IndepFun.entropy_pair_eq_add hY'₁_meas hY'₂_meas (h_indep.indepFun (show 1 ≠ 2 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, two_mul]
have : H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[X ; μ] + H[Y ; μ'] := calc
H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[⟨X', Y'₁⟩ ; μA] := by
let f : G × G → G × G := fun ⟨x, y₁⟩ ↦ (x, x - 2 • y₁)
show H[f ∘ ⟨X', Y'₁⟩ ; μA] = _
apply entropy_comp_of_injective μA (by exact Measurable.prod hX'_meas hY'₁_meas) f
exact fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + H[Y ; μ'] := by
rw [IndepFun.entropy_pair_eq_add hX'_meas hY'₁_meas (h_indep.indepFun (show 0 ≠ 1 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq]
let f : G × G → G × G := fun ⟨x, y⟩ ↦ (x, y - x)
have hf : f.Injective := fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all
have : H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] := calc
H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] = H[f ∘ ⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
show _ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂ - (Y'₁ - Y'₂)⟩ ; μA]
rw [sub_sub_sub_cancel_right, ← sub_add_eq_sub_sub, two_nsmul]
_ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
refine entropy_comp_of_injective μA (Measurable.prod ?_ ?_) f hf
· exact Measurable.sub hY'₁_meas hY'₂_meas
· exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
_ ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] :=
entropy_pair_le_add (hY'₁_meas.sub' hY'₂_meas) (hX'_meas.sub' hY'₁_meas |>.sub' hY'₂_meas) μA
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] + H[X' - 2 • Y'₁ ; μA] ≤
H[⟨X', X' - 2 • Y'₁⟩ ; μA] + H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] := by
haveI : FiniteRange (Y'₁ - Y'₂) := FiniteRange.sub Y'₁ Y'₂
haveI : FiniteRange (2 • Y'₁) := by show FiniteRange ((fun x ↦ 2 • x) ∘ Y'₁); infer_instance
apply entropy_triple_add_entropy_le μA hX'_meas (Measurable.sub hY'₁_meas hY'₂_meas)
exact Measurable.sub' hX'_meas <| Measurable.const_smul hY'₁_meas 2
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨y₁, y₂, x⟩ ↦ (y₁, y₂, x - y₁ - y₂)
show H[f ∘ ⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA]
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hY'₁_meas <| Measurable.prod hY'₂_meas hX'_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun Y'₁ (prod Y'₂ X') μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 2 0 1 (by decide) (by decide)
rw [this.entropy_pair_eq_add hY'₁_meas (by exact Measurable.prod hY'₂_meas hX'_meas),
IndepFun.entropy_pair_eq_add hY'₂_meas hX'_meas (h_indep.indepFun (show 2 ≠ 0 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq]
group
have : H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₂ ; μA] := calc
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₁, X' - Y'₂⟩ ; μA] := by rw [sub_right_comm] ; rfl
_ = H[⟨Y'₁, X' - Y'₂⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₁_meas <| Measurable.sub hX'_meas hY'₂_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₂ ; μA] := by
haveI : FiniteRange (X' - Y'₂) := FiniteRange.sub X' Y'₂
convert IndepFun.entropy_pair_eq_add hY'₁_meas (hX'_meas.sub hY'₂_meas)
<| h_indep.indepFun_sub_right h_meas 1 0 2 (by decide) (by decide)
exact hY'₁_ident.entropy_eq.symm
have : H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₁ ; μA] := calc
H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₂, X' - Y'₁⟩ ; μA] := rfl
_ = H[⟨Y'₂, X' - Y'₁⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₂_meas <| Measurable.sub hX'_meas hY'₁_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₁ ; μA] := by
haveI : FiniteRange (X' - Y'₁) := FiniteRange.sub X' Y'₁
convert IndepFun.entropy_pair_eq_add hY'₂_meas (hX'_meas.sub hY'₁_meas)
<| h_indep.indepFun_sub_right h_meas 2 0 1 (by decide) (by decide)
exact hY'₂_ident.entropy_eq.symm
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] ≤
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] + H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
apply entropy_triple_add_entropy_le μA hY'₁_meas hY'₂_meas
exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
have : H[X' - Y'₁ - Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := calc
H[X' - Y'₁ - Y'₂ ; μA] ≤ H[X' - Y'₁ ; μA] + H[X' - Y'₂ ; μA] - H[X ; μ] := by linarith
_ = 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := by
nth_rw 1 [two_mul, ← hX'_ident.rdist_eq hY'₁_ident, ← hX'_ident.rdist_eq hY'₂_ident]
have h1 : d[X' ; μA # Y'₁ ; μA] = H[X' - Y'₁ ; μA] - H[X' ; μA] / 2 - H[Y'₁ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 1 by decide)).rdist_eq hX'_meas hY'₁_meas
have h2 : d[X' ; μA # Y'₂ ; μA] = H[X' - Y'₂ ; μA] - H[X' ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 2 by decide)).rdist_eq hX'_meas hY'₂_meas
rw [h1, h2, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, hX'_ident.entropy_eq]
group
have : d[X ; μ # 2 • Y ; μ'] ≤
d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := calc
d[X ; μ # 2 • Y ; μ'] = H[X' - 2 • Y'₁ ; μA] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by
have h2Y_ident : IdentDistrib (2 • Y'₁) (2 • Y) (μ := μA) (ν := μ') := by
convert hY'₁_ident.comp <| measurable_discrete <| fun g ↦ 2 • g
have h2Y_indep : IndepFun X' (2 • Y'₁) (μ := μA) := by
convert (h_indep.indepFun (show 0 ≠ 1 by decide)).comp measurable_id
(measurable_const_smul 2)
rw [← hX'_ident.rdist_eq h2Y_ident,
h2Y_indep.rdist_eq hX'_meas <| Measurable.const_smul hY'₁_meas 2,
hX'_ident.entropy_eq, h2Y_ident.entropy_eq]
_ ≤ H[Y'₁ - Y'₂ ; μA] + 2 * d[X ; μ # Y ; μ'] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by linarith
_ = d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := by
have H2Y : H[2 • Y ; μ'] = H[Y ; μ'] := by
let f (g : G) := 2 • g
exact entropy_comp_of_injective μ' hY f (fun _ _ ↦ by simp [f, smul_right_inj])
have : d[Y'₁ ; μA # Y'₂ ; μA] = H[Y'₁ - Y'₂ ; μA] - H[Y'₁ ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 1 ≠ 2 by decide)).rdist_eq hY'₁_meas hY'₂_meas
rw [this, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, H2Y]
group
have : d[Y'₁ ; μA # Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] := by
rw [two_mul]
convert rdist_triangle hY'₁_meas hX'_meas hY'₂_meas (μ := μA) (μ' := μA) (μ'' := μA)
· exact rdist_symm.trans (hY'₁_ident.rdist_eq hX'_ident).symm
· exact (hX'_ident.rdist_eq hY'₂_ident).symm
rw [← two_nsmul]
linarith [abs_le.mp <| diff_ent_le_rdist hX hY (μ := μ) (μ' := μ')]
/-- If $G$ is a torsion-free group and $X,Y$ are $G$-valued random variables and
$\phi : G\to \mathbb{F}_2^d$ is a homomorphism then
\[\mathbb{H}(\phi(X))\leq 10d[X;Y].\] -/
lemma torsion_dist_shrinking {H : Type u} [FiniteRange X] [FiniteRange Y] (hX : Measurable X)
(hY : Measurable Y) [AddCommGroup H] [ElementaryAddCommGroup H 2]
[MeasurableSpace H] [MeasurableSingletonClass H] [Countable H]
(hG : AddMonoid.IsTorsionFree G) (φ : G →+ H) :
H[φ ∘ X ; μ] ≤ 10 * d[X; μ # Y ; μ'] := by
have :=
calc d[φ ∘ X ; μ # φ ∘ (Y + Y); μ'] ≤ d[X; μ # (Y + Y) ; μ'] := rdist_of_hom_le φ hX (Measurable.add hY hY)
_ ≤ 5 * d[X; μ # Y ; μ'] := torsion_free_doubling X Y μ μ' hX hY hG
have eq_zero : φ ∘ (Y + Y) = fun _ ↦ 0 := by ext x ; simp only [Function.comp_apply, Pi.add_apply,
map_add, ElementaryAddCommGroup.add_self]
rwa [eq_zero, rdist_zero_eq_half_ent, div_le_iff zero_lt_two, mul_assoc, mul_comm _ 2, ←mul_assoc,
show (5*2 : ℝ) = 10 by norm_num] at this
end Torsion
instance {G : Type u} [AddCommGroup G] [Fintype G] [MeasurableSpace G] [MeasurableSingletonClass G] (H : AddSubgroup G)
: MeasurableSingletonClass (G ⧸ H) :=
⟨λ _ ↦ by { rw [measurableSet_quotient]; simp [measurableSet_discrete] }⟩
section F2_projection
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [ElementaryAddCommGroup G 2] [Fintype G] [MeasurableSpace G]
[MeasurableSingletonClass G] {Ω Ω' : Type*}
/-- Let $G=\mathbb{F}_2^n$ and $X,Y$ be $G$-valued random variables such that
\[\mathbb{H}(X)+\mathbb{H}(Y)> (20/\alpha) d[X;Y],\]
for some $\alpha > 0$.
There is a non-trivial subgroup $H\leq G$ such that
\[\log \lvert H\rvert <(1+\alpha)/2 (\mathbb{H}(X)+\mathbb{H}(Y))\] and
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))< \alpha (\mathbb{H}(X)+\mathbb{H}(Y))\]
where $\psi:G\to G/H$ is the natural projection homomorphism.
-/
lemma app_ent_PFR' [MeasureSpace Ω] [MeasureSpace Ω'] (X : Ω → G) (Y : Ω' → G)
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
{α : ℝ} (hent : 20 * d[X # Y] < α * (H[X] + H[Y])) (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X] + H[Y]) ∧
H[(QuotientAddGroup.mk' H) ∘ X] + H[(QuotientAddGroup.mk' H) ∘ Y] < α * (H[X] + H[Y]) := by
let p : refPackage Ω Ω' G := {
X₀₁ := X
X₀₂ := Y
hmeas1 := hX
hmeas2 := hY
η := 1/8
hη := by norm_num
hη' := by norm_num }
obtain ⟨H, Ω'', hΩ'', U, _, hUmeas, hUunif, ineq⟩ := entropic_PFR_conjecture_improv p rfl
let ψ := (QuotientAddGroup.mk' H)
use H
haveI : Finite H := Subtype.finite
-- Note that H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y]
have ent_le : H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y] := calc
H[ψ ∘ X] + H[ψ ∘ Y] ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· exact ent_of_proj_le hX hUmeas hUunif
· exact ent_of_proj_le hY hUmeas hUunif
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- Note that (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y]
have log_sub_le : (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y] := calc
(log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) =
(H[U] - H[X]) + (H[U] - H[Y]) := by
rw [IsUniform.entropy_eq' hUunif hUmeas, SetLike.coe_sort_coe]
_ ≤ |(H[U] - H[X])| + |(H[U] - H[Y])| := by gcongr <;> exact le_abs_self _
_ ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hX
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hY
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- then the conclusion follows from the assumption `hent` and basic inequality manipulations
exact ⟨by linarith, by linarith⟩
variable [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ' : Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
lemma app_ent_PFR (α : ℝ) (hent: 20 * d[X;μ # Y;μ'] < α * (H[X; μ] + H[Y; μ'])) (hX : Measurable X)
(hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ']
< α * (H[ X; μ] + H[Y; μ']) :=
@app_ent_PFR' _ _ _ _ _ _ _ _ (MeasureSpace.mk μ) (MeasureSpace.mk μ') _ _ _ _ α hent hX hY
set_option maxHeartbeats 300000 in
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables and $\alpha < 1$ then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq (1 + α) / (2 * (1 - α)) * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 20/\alpha * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection'
(α : ℝ) (hX : Measurable X) (hY : Measurable Y) (αpos : 0 < α) (αone : α < 1) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (H[X ; μ] + H[Y ; μ']) ∧
α * (H[(QuotientAddGroup.mk' H) ∘ X ; μ] + H[(QuotientAddGroup.mk' H) ∘ Y ; μ']) ≤
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] := by
let S := { H : AddSubgroup G | (∃ (c : ℝ), 0 ≤ c ∧
log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (1 - c) * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
c * (H[X; μ] + H[Y;μ'])) ∧
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] <
α * (H[ (QuotientAddGroup.mk' H) ∘ X; μ ] + H[ (QuotientAddGroup.mk' H) ∘ Y; μ']) }
have : 0 ≤ H[X ; μ] + H[Y ; μ'] := by linarith [entropy_nonneg X μ, entropy_nonneg Y μ']
have : 0 < 1 - α := sub_pos.mpr αone
by_cases hE : (⊥ : AddSubgroup G) ∈ S
· classical
obtain ⟨H, ⟨⟨c, hc, hlog, hup⟩, hent⟩, hMaxl⟩ :=
S.toFinite.exists_maximal_wrt id S (Set.nonempty_of_mem hE)
set ψ : G →+ G ⧸ H := QuotientAddGroup.mk' H
have surj : Function.Surjective ψ := QuotientAddGroup.mk'_surjective H
set G' := G ⧸ H
have : ElementaryAddCommGroup G' 2 := ElementaryAddCommGroup.quotient_group (by decide)
(by simp [AddSubgroup.zero_mem])
obtain ⟨H', hlog', hup'⟩ := app_ent_PFR _ _ _ _ α hent ((measurable_discrete _).comp hX)
((measurable_discrete _).comp hY)
have H_ne_bot: H' ≠ ⊥ := by
by_contra!
rcases this with rfl
have inj : Function.Injective (QuotientAddGroup.mk' (⊥ : AddSubgroup G')) :=
(QuotientAddGroup.quotientBot : (G' ⧸ ⊥) ≃+ G').symm.injective
rw [entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ inj,
entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ inj] at hup'
nlinarith [entropy_nonneg (ψ ∘ X) μ, entropy_nonneg (ψ ∘ Y) μ']
let H'' := H'.comap ψ
use H''
rw [← (AddSubgroup.map_comap_eq_self_of_surjective surj _ : H''.map ψ = H')] at hup' hlog'
set H' := H''.map ψ
have Hlt : H < H'' := by
have : H = (⊥ : AddSubgroup G').comap ψ := by
simp only [ψ, AddMonoidHom.comap_bot, QuotientAddGroup.ker_mk']
rw [this, AddSubgroup.comap_lt_comap_of_surjective surj]
exact Ne.bot_lt H_ne_bot
let φ : G' ⧸ H' ≃+ G ⧸ H'' := QuotientAddGroup.quotientQuotientEquivQuotient H H'' Hlt.le
set ψ' : G' →+ G' ⧸ H' := QuotientAddGroup.mk' H'
set ψ'' : G →+ G ⧸ H'' := QuotientAddGroup.mk' H''
have diag : ψ' ∘ ψ = φ.symm ∘ ψ'' := rfl
rw [← Function.comp.assoc, ← Function.comp.assoc, diag, Function.comp.assoc,
Function.comp.assoc] at hup'
have cond : log (Nat.card H'') ≤
(1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := by
have cardprod : Nat.card H'' = Nat.card H' * Nat.card H := by
have hcard₀ := Nat.card_congr <| (AddSubgroup.addSubgroupOfEquivOfLe Hlt.le).toEquiv
have hcard₁ := Nat.card_congr <|
(QuotientAddGroup.quotientKerEquivRange (ψ.restrict H'')).toEquiv
have hcard₂ := AddSubgroup.card_eq_card_quotient_mul_card_addSubgroup (H.addSubgroupOf H'')
rw [ψ.ker_restrict H'', QuotientAddGroup.ker_mk', ψ.restrict_range H''] at hcard₁
simpa only [← Nat.card_eq_fintype_card, hcard₀, hcard₁] using hcard₂
calc
log (Nat.card H'')
_ = log ((Nat.card H' : ℝ) * (Nat.card H : ℝ)) := by rw [cardprod]; norm_cast
_ = log (Nat.card H') + log (Nat.card H) := by
rw [Real.log_mul (Nat.cast_ne_zero.2 (@Nat.card_pos H').ne')
(Nat.cast_ne_zero.2 (@Nat.card_pos H).ne')]
_ ≤ (1 + α) / 2 * (H[⇑ψ ∘ X ; μ] + H[⇑ψ ∘ Y ; μ']) + log (Nat.card H) := by gcongr
_ ≤ (1 + α) / 2 * (c * (H[X; μ] + H[Y;μ'])) +
(1 + α) / (2 * (1 - α)) * (1 - c) * (H[X ; μ] + H[Y ; μ']) := by gcongr
_ = (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X ; μ] + H[Y ; μ']) := by
field_simp; ring
have HS : H'' ∉ S := λ Hs => Hlt.ne (hMaxl H'' Hs Hlt.le)
simp only [S, Set.mem_setOf_eq, not_and, not_lt] at HS
refine ⟨?_, HS ⟨α * c, by positivity, cond, ?_⟩⟩
· calc
log (Nat.card H'')
_ ≤ (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := cond
_ ≤ (1 + α) / (2 * (1 - α)) * 1 * (H[X; μ] + H[Y;μ']) := by gcongr; simp; positivity
_ = (1 + α) / (2 * (1 - α)) * (H[X; μ] + H[Y;μ']) := by simp only [mul_one]
· calc
H[ ψ'' ∘ X; μ ] + H[ ψ'' ∘ Y; μ' ]
_ = H[ φ.symm ∘ ψ'' ∘ X; μ ] + H[ φ.symm ∘ ψ'' ∘ Y; μ' ] := by
simp_rw [← entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ φ.symm.injective,
← entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ φ.symm.injective]
_ ≤ α * (H[ ψ ∘ X; μ ] + H[ ψ ∘ Y; μ' ]) := hup'.le
_ ≤ α * (c * (H[X ; μ] + H[Y ; μ'])) := by gcongr
_ = (α * c) * (H[X ; μ] + H[Y ; μ']) := by ring
· use ⊥
constructor
· simp only [AddSubgroup.mem_bot, Nat.card_eq_fintype_card, Fintype.card_ofSubsingleton,
Nat.cast_one, log_one]
positivity
· simp only [S, Set.mem_setOf_eq, not_and, not_lt] at hE
exact hE ⟨1, by norm_num, by
norm_num; exact add_le_add (entropy_comp_le μ hX _) (entropy_comp_le μ' hY _)⟩
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq 2 * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 34 * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
34 * d[(QuotientAddGroup.mk' H) ∘ X;μ # (QuotientAddGroup.mk' H) ∘ Y;μ'] := by
rcases PFR_projection' X Y μ μ' ((3 : ℝ) / 5) hX hY (by norm_num) (by norm_num) with ⟨H, h, h'⟩
refine ⟨H, ?_, ?_⟩
· convert h
norm_num
· have : 0 ≤ d[⇑(QuotientAddGroup.mk' H) ∘ X ; μ # ⇑(QuotientAddGroup.mk' H) ∘ Y ; μ'] :=
rdist_nonneg ((measurable_discrete _).comp hX) ((measurable_discrete _).comp hY)
linarith
end F2_projection
open MeasureTheory ProbabilityTheory Real Set
open scoped BigOperators
lemma four_logs {a b c d : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) (hd : 0 < d) :
log ((a*b)/(c*d)) = log a + log b - log c - log d := by
rw [log_div, log_mul, log_mul, sub_sub] <;> positivity
lemma sum_prob_preimage {G H : Type*} {X : Finset H} {A : Set G} [Finite A] {φ : A → X}
{A_ : H → Set G} (hA : A.Nonempty) (hφ : ∀ x : X, A_ x = Subtype.val '' (φ ⁻¹' {x})) :
∑ x in X, (Nat.card (A_ x) : ℝ) / (Nat.card A) = 1 := by
rw [← Finset.sum_div]
apply (div_eq_one_iff_eq <| Nat.cast_ne_zero.mpr <| Nat.pos_iff_ne_zero.mp (@Nat.card_pos _ hA.to_subtype _)).mpr
classical
haveI := Fintype.ofFinite A
rewrite [Nat.card_eq_fintype_card, ← Finset.card_univ, Finset.card_eq_sum_card_fiberwise
<| fun a _ ↦ Finset.mem_univ (φ a), ← Finset.sum_coe_sort]
norm_cast
congr; ext
rewrite [← Set.Finite.toFinset_setOf, (Set.toFinite _).card_toFinset, ← Nat.card_eq_fintype_card,
hφ, Nat.card_image_of_injective Subtype.val_injective]; rfl
/-- Let $\phi : G\to H$ be a homomorphism and $A,B\subseteq G$ be finite subsets. If $x,y\in H$ then let $A_x=A\cap \phi^{-1}(x)$ and $B_y=B\cap \phi^{-1}(y)$. There exist $x,y\in H$ such that $A_x,B_y$ are both non-empty and
\[d[\phi(U_A);\phi(U_B)]\log \frac{\lvert A\rvert\lvert B\rvert}{\lvert A_x\rvert\lvert B_y\rvert}\leq (\mathbb{H}(\phi(U_A))+\mathbb{H}(\phi(U_B)))(d(U_A,U_B)-d(U_{A_x},U_{B_y}).\] -/
lemma single_fibres {G H Ω Ω': Type u}
[AddCommGroup G] [Countable G] [MeasurableSpace G] [MeasurableSingletonClass G]
[AddCommGroup H] [Countable H] [MeasurableSpace H] [MeasurableSingletonClass H]
[MeasureSpace Ω] [MeasureSpace Ω']
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
(φ : G →+ H)
{A B : Set G} [Finite A] [Finite B] {UA : Ω → G} {UB: Ω' → G} (hA : A.Nonempty) (hB : B.Nonempty)
(hUA': Measurable UA) (hUB': Measurable UB) (hUA: IsUniform A UA) (hUB: IsUniform B UB)
(hUA_mem : ∀ ω, UA ω ∈ A) (hUB_mem : ∀ ω, UB ω ∈ B) :
∃ (x y : H) (Ax By: Set G),
Ax = A ∩ φ.toFun ⁻¹' {x} ∧ By = B ∩ φ.toFun ⁻¹' {y} ∧ Ax.Nonempty ∧ By.Nonempty ∧
d[φ.toFun ∘ UA # φ.toFun ∘ UB]
* log ((Nat.card A) * (Nat.card B) / ((Nat.card Ax) * (Nat.card By))) ≤
(H[φ.toFun ∘ UA] + H[φ.toFun ∘ UB]) * (d[UA # UB] - dᵤ[Ax # By]) := by
have : Nonempty A := hA.to_subtype
have : Nonempty B := hB.to_subtype
haveI : FiniteRange UA := finiteRange_of_finset UA A.toFinite.toFinset (by simpa)
haveI : FiniteRange UB := finiteRange_of_finset UB B.toFinite.toFinset (by simpa)
have hUA_coe : IsUniform A.toFinite.toFinset.toSet UA := by rwa [Set.Finite.coe_toFinset]
have hUB_coe : IsUniform B.toFinite.toFinset.toSet UB := by rwa [Set.Finite.coe_toFinset]
let A_ (x : H) : Set G := A ∩ φ.toFun ⁻¹' {x}
let B_ (y : H) : Set G := B ∩ φ.toFun ⁻¹' {y}
let X : Finset H := FiniteRange.toFinset (φ.toFun ∘ UA)
let Y : Finset H := FiniteRange.toFinset (φ.toFun ∘ UB)
haveI h_Ax (x : X) : Nonempty (A_ x.val) := by
obtain ⟨ω, hω⟩ := (FiniteRange.mem_iff _ _).mp x.property
use UA ω; exact Set.mem_inter (hUA_mem ω) (by exact hω)
haveI h_By (y : Y) : Nonempty (B_ y.val) := by
obtain ⟨ω, hω⟩ := (FiniteRange.mem_iff _ _).mp y.property
use UB ω; exact Set.mem_inter (hUB_mem ω) (by exact hω)
have h_AX (a : A) : φ.toFun a.val ∈ X := by
obtain ⟨ω, hω⟩ := hUA_coe.nonempty_preimage_of_mem hUA' (A.toFinite.mem_toFinset.mpr a.property)
exact (FiniteRange.mem_iff _ (φ.toFun a.val)).mpr ⟨ω, congr_arg _ hω⟩
have h_BY (b : B) : φ.toFun b.val ∈ Y := by
obtain ⟨ω, hω⟩ := hUB_coe.nonempty_preimage_of_mem hUB' (B.toFinite.mem_toFinset.mpr b.property)
exact (FiniteRange.mem_iff _ (φ.toFun b.val)).mpr ⟨ω, congr_arg _ hω⟩
let φ_AX (a : A) : X := by use φ.toFun a.val; exact h_AX a
let φ_BY (b : B) : Y := by use φ.toFun b.val; exact h_BY b
have h_φ_AX (x : X) : A_ x.val = φ_AX ⁻¹' {x} := by ext; simp [A_, φ_AX]; simp [Subtype.ext_iff]
have h_φ_BY (y : Y) : B_ y.val = φ_BY ⁻¹' {y} := by ext; simp [B_, φ_BY]; simp [Subtype.ext_iff]
let p (x : H) (y : H) : ℝ :=
(Nat.card (A_ x).Elem) * (Nat.card (B_ y).Elem) / ((Nat.card A.Elem) * (Nat.card B.Elem))
have :
∑ x in X, ∑ y in Y, (p x y) * dᵤ[A_ x # B_ y] ≤ d[UA # UB] - d[φ.toFun ∘ UA # φ.toFun ∘ UB] :=
calc
_ = d[UA | φ.toFun ∘ UA # UB | φ.toFun ∘ UB] := by
rewrite [condRuzsaDist_eq_sum hUA' ((measurable_discrete _).comp hUA')
hUB' ((measurable_discrete _).comp hUB')]
refine Finset.sum_congr rfl <| fun x hx ↦ Finset.sum_congr rfl <| fun y hy ↦ ?_
haveI : Nonempty (A_ x) := h_Ax ⟨x, hx⟩
haveI : Nonempty (B_ y) := h_By ⟨y, hy⟩
let μx := (ℙ : Measure Ω)[|(φ.toFun ∘ UA) ⁻¹' {x}]
let μy := (ℙ : Measure Ω')[|(φ.toFun ∘ UB) ⁻¹' {y}]
have h_μ_p : IsProbabilityMeasure μx ∧ IsProbabilityMeasure μy := by
constructor <;> apply ProbabilityTheory.cond_isProbabilityMeasure <;> rw [Set.preimage_comp]
refine @IsUniform.measure_preimage_ne_zero _ _ _ _ _ _ _ _ _ _ hUA_coe hUA' _ ?_
swap; refine @IsUniform.measure_preimage_ne_zero _ _ _ _ _ _ _ _ _ _ hUB_coe hUB' _ ?_
all_goals rwa [Set.inter_comm, Set.Finite.coe_toFinset]
have h_μ_unif : IsUniform (A_ x) UA μx ∧ IsUniform (B_ y) UB μy := by
have : _ ∧ _ := ⟨hUA.restrict hUA' (φ.toFun ⁻¹' {x}), hUB.restrict hUB' (φ.toFun ⁻¹' {y})⟩
rwa [Set.inter_comm _ A, Set.inter_comm _ B] at this
rewrite [rdist_set_eq_rdist h_μ_p.1 h_μ_p.2 h_μ_unif.1 h_μ_unif.2 hUA' hUB']
show _ = (Measure.real _ (UA ⁻¹' (_ ⁻¹' _))) * (Measure.real _ (UB ⁻¹' (_ ⁻¹' _))) * _
rewrite [hUA_coe.measureReal_preimage hUA', hUB_coe.measureReal_preimage hUB']
simp_rw [p, A_, B_, IsProbabilityMeasure.measureReal_univ, one_mul]
rewrite [mul_div_mul_comm, Set.inter_comm A, Set.inter_comm B]
simp only [Set.Finite.coe_toFinset, Set.Finite.mem_toFinset, Finset.mem_val]; rfl
_ ≤ d[UA # UB] - d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
rewrite [ZeroHom.toFun_eq_coe, AddMonoidHom.toZeroHom_coe]
linarith only [rdist_le_sum_fibre φ hUA' hUB' (μ := ℙ) (μ' := ℙ)]
let M := H[φ.toFun ∘ UA] + H[φ.toFun ∘ UB]
have hM : M = ∑ x in X, ∑ y in Y, Real.negMulLog (p x y) := by
have h_compl {x y} (h_notin : (x, y) ∉ X ×ˢ Y) : Real.negMulLog (p x y) = 0 := by
unfold_let p; beta_reduce
rewrite [Finset.mem_product, not_and_or] at h_notin
suffices A_ x = ∅ ∨ B_ y = ∅ by obtain h | h := this <;> rw [h] <;> simp
refine h_notin.imp ?_ ?_
· rw [← not_nonempty_iff_eq_empty]
rintro h ⟨a, ha, rfl⟩
exact h (h_AX ⟨a, ha⟩)
· rw [← not_nonempty_iff_eq_empty]
rintro h ⟨a, ha, rfl⟩
exact h (h_BY ⟨a, ha⟩)
unfold_let M
unfold entropy
haveI := isProbabilityMeasure_map (μ := ℙ) ((measurable_discrete φ).comp hUA').aemeasurable
haveI := isProbabilityMeasure_map (μ := ℙ) ((measurable_discrete φ).comp hUB').aemeasurable
rewrite [← Finset.sum_product', ← tsum_eq_sum fun _ ↦ h_compl, ← measureEntropy_prod]
apply tsum_congr; intro; congr
rewrite [← Set.singleton_prod_singleton, Measure.smul_apply, Measure.prod_prod,
Measure.map_apply ((measurable_discrete _).comp hUA') (MeasurableSet.singleton _),
Measure.map_apply ((measurable_discrete _).comp hUB') (MeasurableSet.singleton _),
Set.preimage_comp, hUA_coe.measure_preimage hUA',
Set.preimage_comp, hUB_coe.measure_preimage hUB']
simp [p, A_, B_, mul_div_mul_comm, Set.inter_comm, ENNReal.toReal_div]
have h_sum : ∑ x in X, ∑ y in Y,
(p x y) * (M * dᵤ[A_ x # B_ y] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p x y)) ≤
M * d[UA # UB] :=
calc
_ = ∑ x in X, ∑ y in Y, (p x y) * M * dᵤ[A_ x # B_ y] + M * d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
simp_rw [hM, Finset.sum_mul, ← Finset.sum_add_distrib]
refine Finset.sum_congr rfl <| fun _ _ ↦ Finset.sum_congr rfl <| fun _ _ ↦ ?_
simp only [negMulLog, left_distrib, mul_assoc, Finset.sum_mul]
exact congrArg (HAdd.hAdd _) (by group)
_ = M * ∑ x in X, ∑ y in Y, (p x y) * dᵤ[A_ x # B_ y] + M * d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
simp_rw [Finset.mul_sum]
congr; ext; congr; ext; group
_ ≤ M * d[UA # UB] := by
rewrite [← left_distrib]
apply mul_le_mul_of_nonneg_left
· linarith
· unfold_let M
linarith only [entropy_nonneg (φ.toFun ∘ UA) ℙ, entropy_nonneg (φ.toFun ∘ UB) ℙ]
have : ∃ x : X, ∃ y : Y,
M * dᵤ[A_ x.val # B_ y.val] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p x.val y.val) ≤
M * d[UA # UB] := by
let f (xy : H × H) := (p xy.1 xy.2) * (M * d[UA # UB])
let g (xy : H × H) := (p xy.1 xy.2) *
(M * dᵤ[A_ xy.1 # B_ xy.2] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p xy.1 xy.2))
by_contra hc; push_neg at hc
replace hc : ∀ xy ∈ X ×ˢ Y, f xy < g xy := by
refine fun xy h ↦ mul_lt_mul_of_pos_left ?_ ?_
· exact hc ⟨xy.1, (Finset.mem_product.mp h).1⟩ ⟨xy.2, (Finset.mem_product.mp h).2⟩
· haveI : Nonempty _ := h_Ax ⟨xy.1, (Finset.mem_product.mp h).1⟩
haveI : Nonempty _ := h_By ⟨xy.2, (Finset.mem_product.mp h).2⟩
simp only [p, div_pos, mul_pos, Nat.cast_pos, Nat.card_pos]
have h_nonempty : Finset.Nonempty (X ×ˢ Y) := by
use ⟨φ.toFun <| UA <| Classical.choice <| ProbabilityMeasure.nonempty ⟨ℙ, inferInstance⟩,
φ.toFun <| UB <| Classical.choice <| ProbabilityMeasure.nonempty ⟨ℙ, inferInstance⟩⟩
exact Finset.mem_product.mpr ⟨FiniteRange.mem _ _, FiniteRange.mem _ _⟩
replace hc := Finset.sum_lt_sum_of_nonempty h_nonempty hc
have h_p_one : ∑ x in X ×ˢ Y, p x.1 x.2 = 1 := by
simp_rw [Finset.sum_product, p, mul_div_mul_comm, ← Finset.mul_sum,
← sum_prob_preimage hA h_φ_AX, sum_prob_preimage hB h_φ_BY, mul_one]
rewrite [← Finset.sum_mul, h_p_one, one_mul, Finset.sum_product] at hc
exact not_le_of_gt hc h_sum
obtain ⟨x, y, hxy⟩ := this
refine ⟨x, y, A_ x.val, B_ y.val, rfl, rfl, @nonempty_of_nonempty_subtype _ _ (h_Ax x), @nonempty_of_nonempty_subtype _ _ (h_By y), ?_⟩
rewrite [← inv_div, Real.log_inv]
show _ * -log (p x.val y.val) ≤ M * _
linarith only [hxy]
section dim
open Classical
variable {G : Type*} [AddCommGroup G]
/- If G ≅ ℤᵈ then there is a subgroup H of G such that A lies in a coset of H. This is helpful to
give the equivalent definition of `dimension`. Here this is stated in greated generality since the
proof carries over automatically-/
lemma exists_coset_cover (A : Set G) :
∃ (d : ℕ), ∃ (S : Submodule ℤ G) (v : G),
FiniteDimensional.finrank ℤ S = d ∧ ∀ a ∈ A, a - v ∈ S := by
existsi FiniteDimensional.finrank ℤ (⊤ : Submodule ℤ G), ⊤, 0
refine ⟨rfl, fun a _ ↦ trivial⟩
/-- The dimension of the affine span over `ℤ` of a subset of an additive group. -/
noncomputable def dimension (A : Set G) : ℕ := Nat.find (exists_coset_cover A)
lemma dimension_le_of_coset_cover (A : Set G) (S : Submodule ℤ G) (v : G)
(hA : ∀ a ∈ A, a - v ∈ S) : dimension A ≤ FiniteDimensional.finrank ℤ S := by
apply Nat.find_le
existsi S , v
exact ⟨rfl, hA⟩
| lemma dimension_le_rank [Module.Finite ℤ G] (A : Set G) :
dimension A ≤ FiniteDimensional.finrank ℤ G | dimension_le_rank | 25309ad 20231211 | f86b5a6 20231231 | pfr/PFR/WeakPFR.lean | {
"lineInFile": 610,
"tokenPositionInFile": 34124,
"theoremPositionInFile": 18
} | {
"inFilePremises": true,
"repositoryPremises": false
} | {
"hasProof": true,
"proof": "by\n obtain ⟨S, v, hs, _⟩ := Nat.find_spec (exists_coset_cover A)\n rw [dimension, ←hs]\n apply Submodule.finrank_le S",
"proofType": "tactic",
"proofLengthLines": 4,
"proofLengthTokens": 118
} | pfr |
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Quotient
import Mathlib.GroupTheory.Torsion
import Mathlib.GroupTheory.Torsion
import Mathlib.LinearAlgebra.FreeModule.PID
import PFR.Mathlib.Data.Set.Pointwise.SMul
import PFR.EntropyPFR
import PFR.ImprovedPFR
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Mathlib.GroupTheory.Torsion
/-!
# Weak PFR over the integers
Here we use the entropic form of PFR to deduce a weak form of PFR over the integers.
## Main statement
* `weak_PFR_int`: Let $A\subseteq \mathbb{Z}^d$ and $\lvert A+A\rvert\leq K\lvert A\rvert$.
There exists $A'\subseteq A$ such that $\lvert A'\rvert \geq K^{-17}\lvert A\rvert$ and
$\dim A' \leq (40/\log 2)\log K$.
-/
section AddCommGroup
variable {G : Type*} [AddCommGroup G] {A B : Set G}
open Set
open scoped Pointwise
def IsShift (A B : Set G) : Prop := ∃ x : G, A = x +ᵥ B
lemma IsShift.sub_self_congr : IsShift A B → A - A = B - B := by
rintro ⟨x, rfl⟩; simp [vadd_sub_vadd_comm, singleton_zero]
lemma IsShift.card_congr : IsShift A B → Nat.card A = Nat.card B := by rintro ⟨x, rfl⟩; simp
/-- The property of two sets A, B of a group G not being contained in cosets of the same proper
subgroup -/
def NotInCoset (A B : Set G) : Prop := AddSubgroup.closure ((A - A) ∪ (B - B)) = ⊤
/-- Without loss of generality, one can move (up to translation and embedding) any pair A, B of non-empty sets into a subgroup where they are not in a coset. -/
lemma wlog_notInCoset (hA : A.Nonempty) (hB : B.Nonempty) :
∃ (G' : AddSubgroup G) (A' B' : Set G'), IsShift A A' ∧ IsShift B B' ∧ NotInCoset A' B' := by
obtain ⟨x, hx⟩ := hA
obtain ⟨y, hy⟩ := hB
set G' := AddSubgroup.closure ((A - A) ∪ (B - B))
set A' : Set G' := (↑) ⁻¹' ((-x) +ᵥ A)
set B' : Set G' := (↑) ⁻¹' ((-y) +ᵥ B)
have hxA : -x +ᵥ A ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hx).trans $ (subset_union_left ..).trans
AddSubgroup.subset_closure
have hyB : -y +ᵥ B ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hy).trans $ (subset_union_right ..).trans
AddSubgroup.subset_closure
have hA : IsShift A A' := ⟨x, by rw [Set.image_preimage_eq_of_subset hxA, vadd_neg_vadd]⟩
have hB : IsShift B B' := ⟨y, by rw [Set.image_preimage_eq_of_subset hyB, vadd_neg_vadd]⟩
refine ⟨G', A', B', hA, hB, ?_⟩
unfold NotInCoset
convert AddSubgroup.closure_preimage_eq_top ((A - A) ∪ (B - B))
simp_rw [preimage_union, hA.sub_self_congr, hB.sub_self_congr]
rw [preimage_sub, preimage_sub]
simp [A', B', preimage_image_preimage]
all_goals apply_rules [Subtype.coe_injective, (image_preimage_subset ..).trans, hxA, hyB]
end AddCommGroup
section Torsion
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [MeasurableSpace G] [MeasurableSingletonClass G]
[Countable G] {Ω Ω' : Type u} [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ': Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
/-- If $G$ is torsion-free and $X,Y$ are $G$-valued random variables then $d[X;2Y]\leq 5d[X;Y]$. -/
lemma torsion_free_doubling [FiniteRange X] [FiniteRange Y]
(hX : Measurable X) (hY : Measurable Y) (hG : AddMonoid.IsTorsionFree G) :
d[X ; μ # (Y + Y) ; μ'] ≤ 5 * d[X; μ # Y ; μ'] := by
obtain ⟨A, mA, μA, X', Y'₁, Y'₂, hμA, h_indep, hX'_meas, hY'₁_meas, hY'₂_meas, hX'_ident,
hY'₁_ident, hY'₂_ident, _, _, _⟩ := independent_copies3_nondep_finiteRange hX hY hY μ μ' μ'
have h_meas (i : Fin 3) : Measurable (![X', Y'₁, Y'₂] i) := by fin_cases i <;> assumption
haveI : NoZeroSMulDivisors ℕ G := hG.noZeroNsmulDivisors
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨x, y₁, y₂⟩ ↦ (x, y₁ - y₂, x - 2 • y₁)
show H[f ∘ ⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] = _
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hX'_meas <| Measurable.prod hY'₁_meas hY'₂_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun X' (prod Y'₁ Y'₂) μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 1 2 0 (by decide) (by decide)
rw [this.entropy_pair_eq_add hX'_meas (by exact Measurable.prod hY'₁_meas hY'₂_meas),
IndepFun.entropy_pair_eq_add hY'₁_meas hY'₂_meas (h_indep.indepFun (show 1 ≠ 2 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, two_mul]
have : H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[X ; μ] + H[Y ; μ'] := calc
H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[⟨X', Y'₁⟩ ; μA] := by
let f : G × G → G × G := fun ⟨x, y₁⟩ ↦ (x, x - 2 • y₁)
show H[f ∘ ⟨X', Y'₁⟩ ; μA] = _
apply entropy_comp_of_injective μA (by exact Measurable.prod hX'_meas hY'₁_meas) f
exact fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + H[Y ; μ'] := by
rw [IndepFun.entropy_pair_eq_add hX'_meas hY'₁_meas (h_indep.indepFun (show 0 ≠ 1 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq]
let f : G × G → G × G := fun ⟨x, y⟩ ↦ (x, y - x)
have hf : f.Injective := fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all
have : H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] := calc
H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] = H[f ∘ ⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
show _ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂ - (Y'₁ - Y'₂)⟩ ; μA]
rw [sub_sub_sub_cancel_right, ← sub_add_eq_sub_sub, two_nsmul]
_ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
refine entropy_comp_of_injective μA (Measurable.prod ?_ ?_) f hf
· exact Measurable.sub hY'₁_meas hY'₂_meas
· exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
_ ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] :=
entropy_pair_le_add (hY'₁_meas.sub' hY'₂_meas) (hX'_meas.sub' hY'₁_meas |>.sub' hY'₂_meas) μA
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] + H[X' - 2 • Y'₁ ; μA] ≤
H[⟨X', X' - 2 • Y'₁⟩ ; μA] + H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] := by
haveI : FiniteRange (Y'₁ - Y'₂) := FiniteRange.sub Y'₁ Y'₂
haveI : FiniteRange (2 • Y'₁) := by show FiniteRange ((fun x ↦ 2 • x) ∘ Y'₁); infer_instance
apply entropy_triple_add_entropy_le μA hX'_meas (Measurable.sub hY'₁_meas hY'₂_meas)
exact Measurable.sub' hX'_meas <| Measurable.const_smul hY'₁_meas 2
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨y₁, y₂, x⟩ ↦ (y₁, y₂, x - y₁ - y₂)
show H[f ∘ ⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA]
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hY'₁_meas <| Measurable.prod hY'₂_meas hX'_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun Y'₁ (prod Y'₂ X') μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 2 0 1 (by decide) (by decide)
rw [this.entropy_pair_eq_add hY'₁_meas (by exact Measurable.prod hY'₂_meas hX'_meas),
IndepFun.entropy_pair_eq_add hY'₂_meas hX'_meas (h_indep.indepFun (show 2 ≠ 0 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq]
group
have : H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₂ ; μA] := calc
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₁, X' - Y'₂⟩ ; μA] := by rw [sub_right_comm] ; rfl
_ = H[⟨Y'₁, X' - Y'₂⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₁_meas <| Measurable.sub hX'_meas hY'₂_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₂ ; μA] := by
haveI : FiniteRange (X' - Y'₂) := FiniteRange.sub X' Y'₂
convert IndepFun.entropy_pair_eq_add hY'₁_meas (hX'_meas.sub hY'₂_meas)
<| h_indep.indepFun_sub_right h_meas 1 0 2 (by decide) (by decide)
exact hY'₁_ident.entropy_eq.symm
have : H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₁ ; μA] := calc
H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₂, X' - Y'₁⟩ ; μA] := rfl
_ = H[⟨Y'₂, X' - Y'₁⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₂_meas <| Measurable.sub hX'_meas hY'₁_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₁ ; μA] := by
haveI : FiniteRange (X' - Y'₁) := FiniteRange.sub X' Y'₁
convert IndepFun.entropy_pair_eq_add hY'₂_meas (hX'_meas.sub hY'₁_meas)
<| h_indep.indepFun_sub_right h_meas 2 0 1 (by decide) (by decide)
exact hY'₂_ident.entropy_eq.symm
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] ≤
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] + H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
apply entropy_triple_add_entropy_le μA hY'₁_meas hY'₂_meas
exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
have : H[X' - Y'₁ - Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := calc
H[X' - Y'₁ - Y'₂ ; μA] ≤ H[X' - Y'₁ ; μA] + H[X' - Y'₂ ; μA] - H[X ; μ] := by linarith
_ = 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := by
nth_rw 1 [two_mul, ← hX'_ident.rdist_eq hY'₁_ident, ← hX'_ident.rdist_eq hY'₂_ident]
have h1 : d[X' ; μA # Y'₁ ; μA] = H[X' - Y'₁ ; μA] - H[X' ; μA] / 2 - H[Y'₁ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 1 by decide)).rdist_eq hX'_meas hY'₁_meas
have h2 : d[X' ; μA # Y'₂ ; μA] = H[X' - Y'₂ ; μA] - H[X' ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 2 by decide)).rdist_eq hX'_meas hY'₂_meas
rw [h1, h2, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, hX'_ident.entropy_eq]
group
have : d[X ; μ # 2 • Y ; μ'] ≤
d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := calc
d[X ; μ # 2 • Y ; μ'] = H[X' - 2 • Y'₁ ; μA] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by
have h2Y_ident : IdentDistrib (2 • Y'₁) (2 • Y) (μ := μA) (ν := μ') := by
convert hY'₁_ident.comp <| measurable_discrete <| fun g ↦ 2 • g
have h2Y_indep : IndepFun X' (2 • Y'₁) (μ := μA) := by
convert (h_indep.indepFun (show 0 ≠ 1 by decide)).comp measurable_id
(measurable_const_smul 2)
rw [← hX'_ident.rdist_eq h2Y_ident,
h2Y_indep.rdist_eq hX'_meas <| Measurable.const_smul hY'₁_meas 2,
hX'_ident.entropy_eq, h2Y_ident.entropy_eq]
_ ≤ H[Y'₁ - Y'₂ ; μA] + 2 * d[X ; μ # Y ; μ'] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by linarith
_ = d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := by
have H2Y : H[2 • Y ; μ'] = H[Y ; μ'] := by
let f (g : G) := 2 • g
exact entropy_comp_of_injective μ' hY f (fun _ _ ↦ by simp [f, smul_right_inj])
have : d[Y'₁ ; μA # Y'₂ ; μA] = H[Y'₁ - Y'₂ ; μA] - H[Y'₁ ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 1 ≠ 2 by decide)).rdist_eq hY'₁_meas hY'₂_meas
rw [this, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, H2Y]
group
have : d[Y'₁ ; μA # Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] := by
rw [two_mul]
convert rdist_triangle hY'₁_meas hX'_meas hY'₂_meas (μ := μA) (μ' := μA) (μ'' := μA)
· exact rdist_symm.trans (hY'₁_ident.rdist_eq hX'_ident).symm
· exact (hX'_ident.rdist_eq hY'₂_ident).symm
rw [← two_nsmul]
linarith [abs_le.mp <| diff_ent_le_rdist hX hY (μ := μ) (μ' := μ')]
/-- If $G$ is a torsion-free group and $X,Y$ are $G$-valued random variables and
$\phi : G\to \mathbb{F}_2^d$ is a homomorphism then
\[\mathbb{H}(\phi(X))\leq 10d[X;Y].\] -/
lemma torsion_dist_shrinking {H : Type u} [FiniteRange X] [FiniteRange Y] (hX : Measurable X)
(hY : Measurable Y) [AddCommGroup H] [ElementaryAddCommGroup H 2]
[MeasurableSpace H] [MeasurableSingletonClass H] [Countable H]
(hG : AddMonoid.IsTorsionFree G) (φ : G →+ H) :
H[φ ∘ X ; μ] ≤ 10 * d[X; μ # Y ; μ'] := by
have :=
calc d[φ ∘ X ; μ # φ ∘ (Y + Y); μ'] ≤ d[X; μ # (Y + Y) ; μ'] := rdist_of_hom_le φ hX (Measurable.add hY hY)
_ ≤ 5 * d[X; μ # Y ; μ'] := torsion_free_doubling X Y μ μ' hX hY hG
have eq_zero : φ ∘ (Y + Y) = fun _ ↦ 0 := by ext x ; simp only [Function.comp_apply, Pi.add_apply,
map_add, ElementaryAddCommGroup.add_self]
rwa [eq_zero, rdist_zero_eq_half_ent, div_le_iff zero_lt_two, mul_assoc, mul_comm _ 2, ←mul_assoc,
show (5*2 : ℝ) = 10 by norm_num] at this
end Torsion
instance {G : Type u} [AddCommGroup G] [Fintype G] [MeasurableSpace G] [MeasurableSingletonClass G] (H : AddSubgroup G)
: MeasurableSingletonClass (G ⧸ H) :=
⟨λ _ ↦ by { rw [measurableSet_quotient]; simp [measurableSet_discrete] }⟩
section F2_projection
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [ElementaryAddCommGroup G 2] [Fintype G] [MeasurableSpace G]
[MeasurableSingletonClass G] {Ω Ω' : Type*}
/-- Let $G=\mathbb{F}_2^n$ and $X,Y$ be $G$-valued random variables such that
\[\mathbb{H}(X)+\mathbb{H}(Y)> (20/\alpha) d[X;Y],\]
for some $\alpha > 0$.
There is a non-trivial subgroup $H\leq G$ such that
\[\log \lvert H\rvert <(1+\alpha)/2 (\mathbb{H}(X)+\mathbb{H}(Y))\] and
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))< \alpha (\mathbb{H}(X)+\mathbb{H}(Y))\]
where $\psi:G\to G/H$ is the natural projection homomorphism.
-/
lemma app_ent_PFR' [MeasureSpace Ω] [MeasureSpace Ω'] (X : Ω → G) (Y : Ω' → G)
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
{α : ℝ} (hent : 20 * d[X # Y] < α * (H[X] + H[Y])) (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X] + H[Y]) ∧
H[(QuotientAddGroup.mk' H) ∘ X] + H[(QuotientAddGroup.mk' H) ∘ Y] < α * (H[X] + H[Y]) := by
let p : refPackage Ω Ω' G := {
X₀₁ := X
X₀₂ := Y
hmeas1 := hX
hmeas2 := hY
η := 1/8
hη := by norm_num
hη' := by norm_num }
obtain ⟨H, Ω'', hΩ'', U, _, hUmeas, hUunif, ineq⟩ := entropic_PFR_conjecture_improv p rfl
let ψ := (QuotientAddGroup.mk' H)
use H
haveI : Finite H := Subtype.finite
-- Note that H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y]
have ent_le : H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y] := calc
H[ψ ∘ X] + H[ψ ∘ Y] ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· exact ent_of_proj_le hX hUmeas hUunif
· exact ent_of_proj_le hY hUmeas hUunif
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- Note that (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y]
have log_sub_le : (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y] := calc
(log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) =
(H[U] - H[X]) + (H[U] - H[Y]) := by
rw [IsUniform.entropy_eq' hUunif hUmeas, SetLike.coe_sort_coe]
_ ≤ |(H[U] - H[X])| + |(H[U] - H[Y])| := by gcongr <;> exact le_abs_self _
_ ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hX
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hY
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- then the conclusion follows from the assumption `hent` and basic inequality manipulations
exact ⟨by linarith, by linarith⟩
variable [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ' : Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
lemma app_ent_PFR (α : ℝ) (hent: 20 * d[X;μ # Y;μ'] < α * (H[X; μ] + H[Y; μ'])) (hX : Measurable X)
(hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ']
< α * (H[ X; μ] + H[Y; μ']) :=
@app_ent_PFR' _ _ _ _ _ _ _ _ (MeasureSpace.mk μ) (MeasureSpace.mk μ') _ _ _ _ α hent hX hY
set_option maxHeartbeats 300000 in
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables and $\alpha < 1$ then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq (1 + α) / (2 * (1 - α)) * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 20/\alpha * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection'
(α : ℝ) (hX : Measurable X) (hY : Measurable Y) (αpos : 0 < α) (αone : α < 1) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (H[X ; μ] + H[Y ; μ']) ∧
α * (H[(QuotientAddGroup.mk' H) ∘ X ; μ] + H[(QuotientAddGroup.mk' H) ∘ Y ; μ']) ≤
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] := by
let S := { H : AddSubgroup G | (∃ (c : ℝ), 0 ≤ c ∧
log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (1 - c) * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
c * (H[X; μ] + H[Y;μ'])) ∧
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] <
α * (H[ (QuotientAddGroup.mk' H) ∘ X; μ ] + H[ (QuotientAddGroup.mk' H) ∘ Y; μ']) }
have : 0 ≤ H[X ; μ] + H[Y ; μ'] := by linarith [entropy_nonneg X μ, entropy_nonneg Y μ']
have : 0 < 1 - α := sub_pos.mpr αone
by_cases hE : (⊥ : AddSubgroup G) ∈ S
· classical
obtain ⟨H, ⟨⟨c, hc, hlog, hup⟩, hent⟩, hMaxl⟩ :=
S.toFinite.exists_maximal_wrt id S (Set.nonempty_of_mem hE)
set ψ : G →+ G ⧸ H := QuotientAddGroup.mk' H
have surj : Function.Surjective ψ := QuotientAddGroup.mk'_surjective H
set G' := G ⧸ H
have : ElementaryAddCommGroup G' 2 := ElementaryAddCommGroup.quotient_group (by decide)
(by simp [AddSubgroup.zero_mem])
obtain ⟨H', hlog', hup'⟩ := app_ent_PFR _ _ _ _ α hent ((measurable_discrete _).comp hX)
((measurable_discrete _).comp hY)
have H_ne_bot: H' ≠ ⊥ := by
by_contra!
rcases this with rfl
have inj : Function.Injective (QuotientAddGroup.mk' (⊥ : AddSubgroup G')) :=
(QuotientAddGroup.quotientBot : (G' ⧸ ⊥) ≃+ G').symm.injective
rw [entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ inj,
entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ inj] at hup'
nlinarith [entropy_nonneg (ψ ∘ X) μ, entropy_nonneg (ψ ∘ Y) μ']
let H'' := H'.comap ψ
use H''
rw [← (AddSubgroup.map_comap_eq_self_of_surjective surj _ : H''.map ψ = H')] at hup' hlog'
set H' := H''.map ψ
have Hlt : H < H'' := by
have : H = (⊥ : AddSubgroup G').comap ψ := by
simp only [ψ, AddMonoidHom.comap_bot, QuotientAddGroup.ker_mk']
rw [this, AddSubgroup.comap_lt_comap_of_surjective surj]
exact Ne.bot_lt H_ne_bot
let φ : G' ⧸ H' ≃+ G ⧸ H'' := QuotientAddGroup.quotientQuotientEquivQuotient H H'' Hlt.le
set ψ' : G' →+ G' ⧸ H' := QuotientAddGroup.mk' H'
set ψ'' : G →+ G ⧸ H'' := QuotientAddGroup.mk' H''
have diag : ψ' ∘ ψ = φ.symm ∘ ψ'' := rfl
rw [← Function.comp.assoc, ← Function.comp.assoc, diag, Function.comp.assoc,
Function.comp.assoc] at hup'
have cond : log (Nat.card H'') ≤
(1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := by
have cardprod : Nat.card H'' = Nat.card H' * Nat.card H := by
have hcard₀ := Nat.card_congr <| (AddSubgroup.addSubgroupOfEquivOfLe Hlt.le).toEquiv
have hcard₁ := Nat.card_congr <|
(QuotientAddGroup.quotientKerEquivRange (ψ.restrict H'')).toEquiv
have hcard₂ := AddSubgroup.card_eq_card_quotient_mul_card_addSubgroup (H.addSubgroupOf H'')
rw [ψ.ker_restrict H'', QuotientAddGroup.ker_mk', ψ.restrict_range H''] at hcard₁
simpa only [← Nat.card_eq_fintype_card, hcard₀, hcard₁] using hcard₂
calc
log (Nat.card H'')
_ = log ((Nat.card H' : ℝ) * (Nat.card H : ℝ)) := by rw [cardprod]; norm_cast
_ = log (Nat.card H') + log (Nat.card H) := by
rw [Real.log_mul (Nat.cast_ne_zero.2 (@Nat.card_pos H').ne')
(Nat.cast_ne_zero.2 (@Nat.card_pos H).ne')]
_ ≤ (1 + α) / 2 * (H[⇑ψ ∘ X ; μ] + H[⇑ψ ∘ Y ; μ']) + log (Nat.card H) := by gcongr
_ ≤ (1 + α) / 2 * (c * (H[X; μ] + H[Y;μ'])) +
(1 + α) / (2 * (1 - α)) * (1 - c) * (H[X ; μ] + H[Y ; μ']) := by gcongr
_ = (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X ; μ] + H[Y ; μ']) := by
field_simp; ring
have HS : H'' ∉ S := λ Hs => Hlt.ne (hMaxl H'' Hs Hlt.le)
simp only [S, Set.mem_setOf_eq, not_and, not_lt] at HS
refine ⟨?_, HS ⟨α * c, by positivity, cond, ?_⟩⟩
· calc
log (Nat.card H'')
_ ≤ (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := cond
_ ≤ (1 + α) / (2 * (1 - α)) * 1 * (H[X; μ] + H[Y;μ']) := by gcongr; simp; positivity
_ = (1 + α) / (2 * (1 - α)) * (H[X; μ] + H[Y;μ']) := by simp only [mul_one]
· calc
H[ ψ'' ∘ X; μ ] + H[ ψ'' ∘ Y; μ' ]
_ = H[ φ.symm ∘ ψ'' ∘ X; μ ] + H[ φ.symm ∘ ψ'' ∘ Y; μ' ] := by
simp_rw [← entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ φ.symm.injective,
← entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ φ.symm.injective]
_ ≤ α * (H[ ψ ∘ X; μ ] + H[ ψ ∘ Y; μ' ]) := hup'.le
_ ≤ α * (c * (H[X ; μ] + H[Y ; μ'])) := by gcongr
_ = (α * c) * (H[X ; μ] + H[Y ; μ']) := by ring
· use ⊥
constructor
· simp only [AddSubgroup.mem_bot, Nat.card_eq_fintype_card, Fintype.card_ofSubsingleton,
Nat.cast_one, log_one]
positivity
· simp only [S, Set.mem_setOf_eq, not_and, not_lt] at hE
exact hE ⟨1, by norm_num, by
norm_num; exact add_le_add (entropy_comp_le μ hX _) (entropy_comp_le μ' hY _)⟩
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq 2 * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 34 * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
34 * d[(QuotientAddGroup.mk' H) ∘ X;μ # (QuotientAddGroup.mk' H) ∘ Y;μ'] := by
rcases PFR_projection' X Y μ μ' ((3 : ℝ) / 5) hX hY (by norm_num) (by norm_num) with ⟨H, h, h'⟩
refine ⟨H, ?_, ?_⟩
· convert h
norm_num
· have : 0 ≤ d[⇑(QuotientAddGroup.mk' H) ∘ X ; μ # ⇑(QuotientAddGroup.mk' H) ∘ Y ; μ'] :=
rdist_nonneg ((measurable_discrete _).comp hX) ((measurable_discrete _).comp hY)
linarith
end F2_projection
open MeasureTheory ProbabilityTheory Real Set
open scoped BigOperators
lemma four_logs {a b c d : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) (hd : 0 < d) :
log ((a*b)/(c*d)) = log a + log b - log c - log d := by
rw [log_div, log_mul, log_mul, sub_sub] <;> positivity
lemma sum_prob_preimage {G H : Type*} {X : Finset H} {A : Set G} [Finite A] {φ : A → X}
{A_ : H → Set G} (hA : A.Nonempty) (hφ : ∀ x : X, A_ x = Subtype.val '' (φ ⁻¹' {x})) :
∑ x in X, (Nat.card (A_ x) : ℝ) / (Nat.card A) = 1 := by
rw [← Finset.sum_div]
apply (div_eq_one_iff_eq <| Nat.cast_ne_zero.mpr <| Nat.pos_iff_ne_zero.mp (@Nat.card_pos _ hA.to_subtype _)).mpr
classical
haveI := Fintype.ofFinite A
rewrite [Nat.card_eq_fintype_card, ← Finset.card_univ, Finset.card_eq_sum_card_fiberwise
<| fun a _ ↦ Finset.mem_univ (φ a), ← Finset.sum_coe_sort]
norm_cast
congr; ext
rewrite [← Set.Finite.toFinset_setOf, (Set.toFinite _).card_toFinset, ← Nat.card_eq_fintype_card,
hφ, Nat.card_image_of_injective Subtype.val_injective]; rfl
/-- Let $\phi : G\to H$ be a homomorphism and $A,B\subseteq G$ be finite subsets. If $x,y\in H$ then let $A_x=A\cap \phi^{-1}(x)$ and $B_y=B\cap \phi^{-1}(y)$. There exist $x,y\in H$ such that $A_x,B_y$ are both non-empty and
\[d[\phi(U_A);\phi(U_B)]\log \frac{\lvert A\rvert\lvert B\rvert}{\lvert A_x\rvert\lvert B_y\rvert}\leq (\mathbb{H}(\phi(U_A))+\mathbb{H}(\phi(U_B)))(d(U_A,U_B)-d(U_{A_x},U_{B_y}).\] -/
lemma single_fibres {G H Ω Ω': Type u}
[AddCommGroup G] [Countable G] [MeasurableSpace G] [MeasurableSingletonClass G]
[AddCommGroup H] [Countable H] [MeasurableSpace H] [MeasurableSingletonClass H]
[MeasureSpace Ω] [MeasureSpace Ω']
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
(φ : G →+ H)
{A B : Set G} [Finite A] [Finite B] {UA : Ω → G} {UB: Ω' → G} (hA : A.Nonempty) (hB : B.Nonempty)
(hUA': Measurable UA) (hUB': Measurable UB) (hUA: IsUniform A UA) (hUB: IsUniform B UB)
(hUA_mem : ∀ ω, UA ω ∈ A) (hUB_mem : ∀ ω, UB ω ∈ B) :
∃ (x y : H) (Ax By: Set G),
Ax = A ∩ φ.toFun ⁻¹' {x} ∧ By = B ∩ φ.toFun ⁻¹' {y} ∧ Ax.Nonempty ∧ By.Nonempty ∧
d[φ.toFun ∘ UA # φ.toFun ∘ UB]
* log ((Nat.card A) * (Nat.card B) / ((Nat.card Ax) * (Nat.card By))) ≤
(H[φ.toFun ∘ UA] + H[φ.toFun ∘ UB]) * (d[UA # UB] - dᵤ[Ax # By]) := by
have : Nonempty A := hA.to_subtype
have : Nonempty B := hB.to_subtype
haveI : FiniteRange UA := finiteRange_of_finset UA A.toFinite.toFinset (by simpa)
haveI : FiniteRange UB := finiteRange_of_finset UB B.toFinite.toFinset (by simpa)
have hUA_coe : IsUniform A.toFinite.toFinset.toSet UA := by rwa [Set.Finite.coe_toFinset]
have hUB_coe : IsUniform B.toFinite.toFinset.toSet UB := by rwa [Set.Finite.coe_toFinset]
let A_ (x : H) : Set G := A ∩ φ.toFun ⁻¹' {x}
let B_ (y : H) : Set G := B ∩ φ.toFun ⁻¹' {y}
let X : Finset H := FiniteRange.toFinset (φ.toFun ∘ UA)
let Y : Finset H := FiniteRange.toFinset (φ.toFun ∘ UB)
haveI h_Ax (x : X) : Nonempty (A_ x.val) := by
obtain ⟨ω, hω⟩ := (FiniteRange.mem_iff _ _).mp x.property
use UA ω; exact Set.mem_inter (hUA_mem ω) (by exact hω)
haveI h_By (y : Y) : Nonempty (B_ y.val) := by
obtain ⟨ω, hω⟩ := (FiniteRange.mem_iff _ _).mp y.property
use UB ω; exact Set.mem_inter (hUB_mem ω) (by exact hω)
have h_AX (a : A) : φ.toFun a.val ∈ X := by
obtain ⟨ω, hω⟩ := hUA_coe.nonempty_preimage_of_mem hUA' (A.toFinite.mem_toFinset.mpr a.property)
exact (FiniteRange.mem_iff _ (φ.toFun a.val)).mpr ⟨ω, congr_arg _ hω⟩
have h_BY (b : B) : φ.toFun b.val ∈ Y := by
obtain ⟨ω, hω⟩ := hUB_coe.nonempty_preimage_of_mem hUB' (B.toFinite.mem_toFinset.mpr b.property)
exact (FiniteRange.mem_iff _ (φ.toFun b.val)).mpr ⟨ω, congr_arg _ hω⟩
let φ_AX (a : A) : X := by use φ.toFun a.val; exact h_AX a
let φ_BY (b : B) : Y := by use φ.toFun b.val; exact h_BY b
have h_φ_AX (x : X) : A_ x.val = φ_AX ⁻¹' {x} := by ext; simp [A_, φ_AX]; simp [Subtype.ext_iff]
have h_φ_BY (y : Y) : B_ y.val = φ_BY ⁻¹' {y} := by ext; simp [B_, φ_BY]; simp [Subtype.ext_iff]
let p (x : H) (y : H) : ℝ :=
(Nat.card (A_ x).Elem) * (Nat.card (B_ y).Elem) / ((Nat.card A.Elem) * (Nat.card B.Elem))
have :
∑ x in X, ∑ y in Y, (p x y) * dᵤ[A_ x # B_ y] ≤ d[UA # UB] - d[φ.toFun ∘ UA # φ.toFun ∘ UB] :=
calc
_ = d[UA | φ.toFun ∘ UA # UB | φ.toFun ∘ UB] := by
rewrite [condRuzsaDist_eq_sum hUA' ((measurable_discrete _).comp hUA')
hUB' ((measurable_discrete _).comp hUB')]
refine Finset.sum_congr rfl <| fun x hx ↦ Finset.sum_congr rfl <| fun y hy ↦ ?_
haveI : Nonempty (A_ x) := h_Ax ⟨x, hx⟩
haveI : Nonempty (B_ y) := h_By ⟨y, hy⟩
let μx := (ℙ : Measure Ω)[|(φ.toFun ∘ UA) ⁻¹' {x}]
let μy := (ℙ : Measure Ω')[|(φ.toFun ∘ UB) ⁻¹' {y}]
have h_μ_p : IsProbabilityMeasure μx ∧ IsProbabilityMeasure μy := by
constructor <;> apply ProbabilityTheory.cond_isProbabilityMeasure <;> rw [Set.preimage_comp]
refine @IsUniform.measure_preimage_ne_zero _ _ _ _ _ _ _ _ _ _ hUA_coe hUA' _ ?_
swap; refine @IsUniform.measure_preimage_ne_zero _ _ _ _ _ _ _ _ _ _ hUB_coe hUB' _ ?_
all_goals rwa [Set.inter_comm, Set.Finite.coe_toFinset]
have h_μ_unif : IsUniform (A_ x) UA μx ∧ IsUniform (B_ y) UB μy := by
have : _ ∧ _ := ⟨hUA.restrict hUA' (φ.toFun ⁻¹' {x}), hUB.restrict hUB' (φ.toFun ⁻¹' {y})⟩
rwa [Set.inter_comm _ A, Set.inter_comm _ B] at this
rewrite [rdist_set_eq_rdist h_μ_p.1 h_μ_p.2 h_μ_unif.1 h_μ_unif.2 hUA' hUB']
show _ = (Measure.real _ (UA ⁻¹' (_ ⁻¹' _))) * (Measure.real _ (UB ⁻¹' (_ ⁻¹' _))) * _
rewrite [hUA_coe.measureReal_preimage hUA', hUB_coe.measureReal_preimage hUB']
simp_rw [p, A_, B_, IsProbabilityMeasure.measureReal_univ, one_mul]
rewrite [mul_div_mul_comm, Set.inter_comm A, Set.inter_comm B]
simp only [Set.Finite.coe_toFinset, Set.Finite.mem_toFinset, Finset.mem_val]; rfl
_ ≤ d[UA # UB] - d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
rewrite [ZeroHom.toFun_eq_coe, AddMonoidHom.toZeroHom_coe]
linarith only [rdist_le_sum_fibre φ hUA' hUB' (μ := ℙ) (μ' := ℙ)]
let M := H[φ.toFun ∘ UA] + H[φ.toFun ∘ UB]
have hM : M = ∑ x in X, ∑ y in Y, Real.negMulLog (p x y) := by
have h_compl {x y} (h_notin : (x, y) ∉ X ×ˢ Y) : Real.negMulLog (p x y) = 0 := by
unfold_let p; beta_reduce
rewrite [Finset.mem_product, not_and_or] at h_notin
suffices A_ x = ∅ ∨ B_ y = ∅ by obtain h | h := this <;> rw [h] <;> simp
refine h_notin.imp ?_ ?_
· rw [← not_nonempty_iff_eq_empty]
rintro h ⟨a, ha, rfl⟩
exact h (h_AX ⟨a, ha⟩)
· rw [← not_nonempty_iff_eq_empty]
rintro h ⟨a, ha, rfl⟩
exact h (h_BY ⟨a, ha⟩)
unfold_let M
unfold entropy
haveI := isProbabilityMeasure_map (μ := ℙ) ((measurable_discrete φ).comp hUA').aemeasurable
haveI := isProbabilityMeasure_map (μ := ℙ) ((measurable_discrete φ).comp hUB').aemeasurable
rewrite [← Finset.sum_product', ← tsum_eq_sum fun _ ↦ h_compl, ← measureEntropy_prod]
apply tsum_congr; intro; congr
rewrite [← Set.singleton_prod_singleton, Measure.smul_apply, Measure.prod_prod,
Measure.map_apply ((measurable_discrete _).comp hUA') (MeasurableSet.singleton _),
Measure.map_apply ((measurable_discrete _).comp hUB') (MeasurableSet.singleton _),
Set.preimage_comp, hUA_coe.measure_preimage hUA',
Set.preimage_comp, hUB_coe.measure_preimage hUB']
simp [p, A_, B_, mul_div_mul_comm, Set.inter_comm, ENNReal.toReal_div]
have h_sum : ∑ x in X, ∑ y in Y,
(p x y) * (M * dᵤ[A_ x # B_ y] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p x y)) ≤
M * d[UA # UB] :=
calc
_ = ∑ x in X, ∑ y in Y, (p x y) * M * dᵤ[A_ x # B_ y] + M * d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
simp_rw [hM, Finset.sum_mul, ← Finset.sum_add_distrib]
refine Finset.sum_congr rfl <| fun _ _ ↦ Finset.sum_congr rfl <| fun _ _ ↦ ?_
simp only [negMulLog, left_distrib, mul_assoc, Finset.sum_mul]
exact congrArg (HAdd.hAdd _) (by group)
_ = M * ∑ x in X, ∑ y in Y, (p x y) * dᵤ[A_ x # B_ y] + M * d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
simp_rw [Finset.mul_sum]
congr; ext; congr; ext; group
_ ≤ M * d[UA # UB] := by
rewrite [← left_distrib]
apply mul_le_mul_of_nonneg_left
· linarith
· unfold_let M
linarith only [entropy_nonneg (φ.toFun ∘ UA) ℙ, entropy_nonneg (φ.toFun ∘ UB) ℙ]
have : ∃ x : X, ∃ y : Y,
M * dᵤ[A_ x.val # B_ y.val] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p x.val y.val) ≤
M * d[UA # UB] := by
let f (xy : H × H) := (p xy.1 xy.2) * (M * d[UA # UB])
let g (xy : H × H) := (p xy.1 xy.2) *
(M * dᵤ[A_ xy.1 # B_ xy.2] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p xy.1 xy.2))
by_contra hc; push_neg at hc
replace hc : ∀ xy ∈ X ×ˢ Y, f xy < g xy := by
refine fun xy h ↦ mul_lt_mul_of_pos_left ?_ ?_
· exact hc ⟨xy.1, (Finset.mem_product.mp h).1⟩ ⟨xy.2, (Finset.mem_product.mp h).2⟩
· haveI : Nonempty _ := h_Ax ⟨xy.1, (Finset.mem_product.mp h).1⟩
haveI : Nonempty _ := h_By ⟨xy.2, (Finset.mem_product.mp h).2⟩
simp only [p, div_pos, mul_pos, Nat.cast_pos, Nat.card_pos]
have h_nonempty : Finset.Nonempty (X ×ˢ Y) := by
use ⟨φ.toFun <| UA <| Classical.choice <| ProbabilityMeasure.nonempty ⟨ℙ, inferInstance⟩,
φ.toFun <| UB <| Classical.choice <| ProbabilityMeasure.nonempty ⟨ℙ, inferInstance⟩⟩
exact Finset.mem_product.mpr ⟨FiniteRange.mem _ _, FiniteRange.mem _ _⟩
replace hc := Finset.sum_lt_sum_of_nonempty h_nonempty hc
have h_p_one : ∑ x in X ×ˢ Y, p x.1 x.2 = 1 := by
simp_rw [Finset.sum_product, p, mul_div_mul_comm, ← Finset.mul_sum,
← sum_prob_preimage hA h_φ_AX, sum_prob_preimage hB h_φ_BY, mul_one]
rewrite [← Finset.sum_mul, h_p_one, one_mul, Finset.sum_product] at hc
exact not_le_of_gt hc h_sum
obtain ⟨x, y, hxy⟩ := this
refine ⟨x, y, A_ x.val, B_ y.val, rfl, rfl, @nonempty_of_nonempty_subtype _ _ (h_Ax x), @nonempty_of_nonempty_subtype _ _ (h_By y), ?_⟩
rewrite [← inv_div, Real.log_inv]
show _ * -log (p x.val y.val) ≤ M * _
linarith only [hxy]
section dim
open Classical
variable {G : Type*} [AddCommGroup G]
/- If G ≅ ℤᵈ then there is a subgroup H of G such that A lies in a coset of H. This is helpful to
give the equivalent definition of `dimension`. Here this is stated in greated generality since the
proof carries over automatically-/
lemma exists_coset_cover (A : Set G) :
∃ (d : ℕ), ∃ (S : Submodule ℤ G) (v : G),
FiniteDimensional.finrank ℤ S = d ∧ ∀ a ∈ A, a - v ∈ S := by
existsi FiniteDimensional.finrank ℤ (⊤ : Submodule ℤ G), ⊤, 0
refine ⟨rfl, fun a _ ↦ trivial⟩
/-- The dimension of the affine span over `ℤ` of a subset of an additive group. -/
noncomputable def dimension (A : Set G) : ℕ := Nat.find (exists_coset_cover A)
lemma dimension_le_of_coset_cover (A : Set G) (S : Submodule ℤ G) (v : G)
(hA : ∀ a ∈ A, a - v ∈ S) : dimension A ≤ FiniteDimensional.finrank ℤ S := by
apply Nat.find_le
existsi S , v
exact ⟨rfl, hA⟩
lemma dimension_le_rank [Module.Finite ℤ G] (A : Set G) :
dimension A ≤ FiniteDimensional.finrank ℤ G := by
obtain ⟨S, v, hs, _⟩ := Nat.find_spec (exists_coset_cover A)
rw [dimension, ←hs]
apply Submodule.finrank_le S
end dim
variable {G : Type u} [AddCommGroup G] [Module.Free ℤ G] [Module.Finite ℤ G] [Countable G] [MeasurableSpace G] [MeasurableSingletonClass G]
open Real MeasureTheory ProbabilityTheory Pointwise Set
/-- Move to Mathlib? `Finsupp.mapRange` of a surjective function is surjective. -/
| lemma Finsupp.mapRange_surjective {α : Type u_1} {M : Type u_5} {N : Type u_7} [Zero M] [Zero N] (f : M → N) (hf : f 0 = 0)
(hs : Function.Surjective f) : Function.Surjective (Finsupp.mapRange (α := α) f hf) | Finsupp.mapRange_surjective | 25309ad 20231211 | f025369 20231228 | pfr/PFR/WeakPFR.lean | {
"lineInFile": 623,
"tokenPositionInFile": 34643,
"theoremPositionInFile": 19
} | {
"inFilePremises": false,
"repositoryPremises": false
} | {
"hasProof": true,
"proof": "by\n classical\n let g (n : N) : M := if n = 0 then 0 else Function.surjInv hs n\n have : Function.RightInverse g f := by\n intro n\n by_cases h : n = 0\n . simp [g, h, hf]\n · simp [g, h, Function.surjInv_eq hs n]\n have hg : g 0 = 0 := by simp [g]\n have hfg : (f ∘ g) 0 = 0 := by simp [hf, hg]\n intro F\n use Finsupp.mapRange g hg F\n rw [← Finsupp.mapRange_comp (h := hfg)]\n convert Finsupp.mapRange_id F\n convert Function.RightInverse.id this",
"proofType": "tactic",
"proofLengthLines": 15,
"proofLengthTokens": 458
} | pfr |
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Quotient
import Mathlib.GroupTheory.Torsion
import Mathlib.GroupTheory.Torsion
import Mathlib.LinearAlgebra.FreeModule.PID
import PFR.Mathlib.Data.Set.Pointwise.SMul
import PFR.EntropyPFR
import PFR.ImprovedPFR
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Mathlib.GroupTheory.Torsion
/-!
# Weak PFR over the integers
Here we use the entropic form of PFR to deduce a weak form of PFR over the integers.
## Main statement
* `weak_PFR_int`: Let $A\subseteq \mathbb{Z}^d$ and $\lvert A+A\rvert\leq K\lvert A\rvert$.
There exists $A'\subseteq A$ such that $\lvert A'\rvert \geq K^{-17}\lvert A\rvert$ and
$\dim A' \leq (40/\log 2)\log K$.
-/
section AddCommGroup
variable {G : Type*} [AddCommGroup G] {A B : Set G}
open Set
open scoped Pointwise
def IsShift (A B : Set G) : Prop := ∃ x : G, A = x +ᵥ B
lemma IsShift.sub_self_congr : IsShift A B → A - A = B - B := by
rintro ⟨x, rfl⟩; simp [vadd_sub_vadd_comm, singleton_zero]
lemma IsShift.card_congr : IsShift A B → Nat.card A = Nat.card B := by rintro ⟨x, rfl⟩; simp
/-- The property of two sets A, B of a group G not being contained in cosets of the same proper
subgroup -/
def NotInCoset (A B : Set G) : Prop := AddSubgroup.closure ((A - A) ∪ (B - B)) = ⊤
/-- Without loss of generality, one can move (up to translation and embedding) any pair A, B of non-empty sets into a subgroup where they are not in a coset. -/
lemma wlog_notInCoset (hA : A.Nonempty) (hB : B.Nonempty) :
∃ (G' : AddSubgroup G) (A' B' : Set G'), IsShift A A' ∧ IsShift B B' ∧ NotInCoset A' B' := by
obtain ⟨x, hx⟩ := hA
obtain ⟨y, hy⟩ := hB
set G' := AddSubgroup.closure ((A - A) ∪ (B - B))
set A' : Set G' := (↑) ⁻¹' ((-x) +ᵥ A)
set B' : Set G' := (↑) ⁻¹' ((-y) +ᵥ B)
have hxA : -x +ᵥ A ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hx).trans $ (subset_union_left ..).trans
AddSubgroup.subset_closure
have hyB : -y +ᵥ B ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hy).trans $ (subset_union_right ..).trans
AddSubgroup.subset_closure
have hA : IsShift A A' := ⟨x, by rw [Set.image_preimage_eq_of_subset hxA, vadd_neg_vadd]⟩
have hB : IsShift B B' := ⟨y, by rw [Set.image_preimage_eq_of_subset hyB, vadd_neg_vadd]⟩
refine ⟨G', A', B', hA, hB, ?_⟩
unfold NotInCoset
convert AddSubgroup.closure_preimage_eq_top ((A - A) ∪ (B - B))
simp_rw [preimage_union, hA.sub_self_congr, hB.sub_self_congr]
rw [preimage_sub, preimage_sub]
simp [A', B', preimage_image_preimage]
all_goals apply_rules [Subtype.coe_injective, (image_preimage_subset ..).trans, hxA, hyB]
end AddCommGroup
section Torsion
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [MeasurableSpace G] [MeasurableSingletonClass G]
[Countable G] {Ω Ω' : Type u} [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ': Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
/-- If $G$ is torsion-free and $X,Y$ are $G$-valued random variables then $d[X;2Y]\leq 5d[X;Y]$. -/
lemma torsion_free_doubling [FiniteRange X] [FiniteRange Y]
(hX : Measurable X) (hY : Measurable Y) (hG : AddMonoid.IsTorsionFree G) :
d[X ; μ # (Y + Y) ; μ'] ≤ 5 * d[X; μ # Y ; μ'] := by
obtain ⟨A, mA, μA, X', Y'₁, Y'₂, hμA, h_indep, hX'_meas, hY'₁_meas, hY'₂_meas, hX'_ident,
hY'₁_ident, hY'₂_ident, _, _, _⟩ := independent_copies3_nondep_finiteRange hX hY hY μ μ' μ'
have h_meas (i : Fin 3) : Measurable (![X', Y'₁, Y'₂] i) := by fin_cases i <;> assumption
haveI : NoZeroSMulDivisors ℕ G := hG.noZeroNsmulDivisors
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨x, y₁, y₂⟩ ↦ (x, y₁ - y₂, x - 2 • y₁)
show H[f ∘ ⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] = _
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hX'_meas <| Measurable.prod hY'₁_meas hY'₂_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun X' (prod Y'₁ Y'₂) μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 1 2 0 (by decide) (by decide)
rw [this.entropy_pair_eq_add hX'_meas (by exact Measurable.prod hY'₁_meas hY'₂_meas),
IndepFun.entropy_pair_eq_add hY'₁_meas hY'₂_meas (h_indep.indepFun (show 1 ≠ 2 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, two_mul]
have : H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[X ; μ] + H[Y ; μ'] := calc
H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[⟨X', Y'₁⟩ ; μA] := by
let f : G × G → G × G := fun ⟨x, y₁⟩ ↦ (x, x - 2 • y₁)
show H[f ∘ ⟨X', Y'₁⟩ ; μA] = _
apply entropy_comp_of_injective μA (by exact Measurable.prod hX'_meas hY'₁_meas) f
exact fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + H[Y ; μ'] := by
rw [IndepFun.entropy_pair_eq_add hX'_meas hY'₁_meas (h_indep.indepFun (show 0 ≠ 1 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq]
let f : G × G → G × G := fun ⟨x, y⟩ ↦ (x, y - x)
have hf : f.Injective := fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all
have : H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] := calc
H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] = H[f ∘ ⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
show _ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂ - (Y'₁ - Y'₂)⟩ ; μA]
rw [sub_sub_sub_cancel_right, ← sub_add_eq_sub_sub, two_nsmul]
_ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
refine entropy_comp_of_injective μA (Measurable.prod ?_ ?_) f hf
· exact Measurable.sub hY'₁_meas hY'₂_meas
· exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
_ ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] :=
entropy_pair_le_add (hY'₁_meas.sub' hY'₂_meas) (hX'_meas.sub' hY'₁_meas |>.sub' hY'₂_meas) μA
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] + H[X' - 2 • Y'₁ ; μA] ≤
H[⟨X', X' - 2 • Y'₁⟩ ; μA] + H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] := by
haveI : FiniteRange (Y'₁ - Y'₂) := FiniteRange.sub Y'₁ Y'₂
haveI : FiniteRange (2 • Y'₁) := by show FiniteRange ((fun x ↦ 2 • x) ∘ Y'₁); infer_instance
apply entropy_triple_add_entropy_le μA hX'_meas (Measurable.sub hY'₁_meas hY'₂_meas)
exact Measurable.sub' hX'_meas <| Measurable.const_smul hY'₁_meas 2
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨y₁, y₂, x⟩ ↦ (y₁, y₂, x - y₁ - y₂)
show H[f ∘ ⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA]
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hY'₁_meas <| Measurable.prod hY'₂_meas hX'_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun Y'₁ (prod Y'₂ X') μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 2 0 1 (by decide) (by decide)
rw [this.entropy_pair_eq_add hY'₁_meas (by exact Measurable.prod hY'₂_meas hX'_meas),
IndepFun.entropy_pair_eq_add hY'₂_meas hX'_meas (h_indep.indepFun (show 2 ≠ 0 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq]
group
have : H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₂ ; μA] := calc
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₁, X' - Y'₂⟩ ; μA] := by rw [sub_right_comm] ; rfl
_ = H[⟨Y'₁, X' - Y'₂⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₁_meas <| Measurable.sub hX'_meas hY'₂_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₂ ; μA] := by
haveI : FiniteRange (X' - Y'₂) := FiniteRange.sub X' Y'₂
convert IndepFun.entropy_pair_eq_add hY'₁_meas (hX'_meas.sub hY'₂_meas)
<| h_indep.indepFun_sub_right h_meas 1 0 2 (by decide) (by decide)
exact hY'₁_ident.entropy_eq.symm
have : H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₁ ; μA] := calc
H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₂, X' - Y'₁⟩ ; μA] := rfl
_ = H[⟨Y'₂, X' - Y'₁⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₂_meas <| Measurable.sub hX'_meas hY'₁_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₁ ; μA] := by
haveI : FiniteRange (X' - Y'₁) := FiniteRange.sub X' Y'₁
convert IndepFun.entropy_pair_eq_add hY'₂_meas (hX'_meas.sub hY'₁_meas)
<| h_indep.indepFun_sub_right h_meas 2 0 1 (by decide) (by decide)
exact hY'₂_ident.entropy_eq.symm
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] ≤
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] + H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
apply entropy_triple_add_entropy_le μA hY'₁_meas hY'₂_meas
exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
have : H[X' - Y'₁ - Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := calc
H[X' - Y'₁ - Y'₂ ; μA] ≤ H[X' - Y'₁ ; μA] + H[X' - Y'₂ ; μA] - H[X ; μ] := by linarith
_ = 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := by
nth_rw 1 [two_mul, ← hX'_ident.rdist_eq hY'₁_ident, ← hX'_ident.rdist_eq hY'₂_ident]
have h1 : d[X' ; μA # Y'₁ ; μA] = H[X' - Y'₁ ; μA] - H[X' ; μA] / 2 - H[Y'₁ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 1 by decide)).rdist_eq hX'_meas hY'₁_meas
have h2 : d[X' ; μA # Y'₂ ; μA] = H[X' - Y'₂ ; μA] - H[X' ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 2 by decide)).rdist_eq hX'_meas hY'₂_meas
rw [h1, h2, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, hX'_ident.entropy_eq]
group
have : d[X ; μ # 2 • Y ; μ'] ≤
d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := calc
d[X ; μ # 2 • Y ; μ'] = H[X' - 2 • Y'₁ ; μA] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by
have h2Y_ident : IdentDistrib (2 • Y'₁) (2 • Y) (μ := μA) (ν := μ') := by
convert hY'₁_ident.comp <| measurable_discrete <| fun g ↦ 2 • g
have h2Y_indep : IndepFun X' (2 • Y'₁) (μ := μA) := by
convert (h_indep.indepFun (show 0 ≠ 1 by decide)).comp measurable_id
(measurable_const_smul 2)
rw [← hX'_ident.rdist_eq h2Y_ident,
h2Y_indep.rdist_eq hX'_meas <| Measurable.const_smul hY'₁_meas 2,
hX'_ident.entropy_eq, h2Y_ident.entropy_eq]
_ ≤ H[Y'₁ - Y'₂ ; μA] + 2 * d[X ; μ # Y ; μ'] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by linarith
_ = d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := by
have H2Y : H[2 • Y ; μ'] = H[Y ; μ'] := by
let f (g : G) := 2 • g
exact entropy_comp_of_injective μ' hY f (fun _ _ ↦ by simp [f, smul_right_inj])
have : d[Y'₁ ; μA # Y'₂ ; μA] = H[Y'₁ - Y'₂ ; μA] - H[Y'₁ ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 1 ≠ 2 by decide)).rdist_eq hY'₁_meas hY'₂_meas
rw [this, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, H2Y]
group
have : d[Y'₁ ; μA # Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] := by
rw [two_mul]
convert rdist_triangle hY'₁_meas hX'_meas hY'₂_meas (μ := μA) (μ' := μA) (μ'' := μA)
· exact rdist_symm.trans (hY'₁_ident.rdist_eq hX'_ident).symm
· exact (hX'_ident.rdist_eq hY'₂_ident).symm
rw [← two_nsmul]
linarith [abs_le.mp <| diff_ent_le_rdist hX hY (μ := μ) (μ' := μ')]
/-- If $G$ is a torsion-free group and $X,Y$ are $G$-valued random variables and
$\phi : G\to \mathbb{F}_2^d$ is a homomorphism then
\[\mathbb{H}(\phi(X))\leq 10d[X;Y].\] -/
lemma torsion_dist_shrinking {H : Type u} [FiniteRange X] [FiniteRange Y] (hX : Measurable X)
(hY : Measurable Y) [AddCommGroup H] [ElementaryAddCommGroup H 2]
[MeasurableSpace H] [MeasurableSingletonClass H] [Countable H]
(hG : AddMonoid.IsTorsionFree G) (φ : G →+ H) :
H[φ ∘ X ; μ] ≤ 10 * d[X; μ # Y ; μ'] := by
have :=
calc d[φ ∘ X ; μ # φ ∘ (Y + Y); μ'] ≤ d[X; μ # (Y + Y) ; μ'] := rdist_of_hom_le φ hX (Measurable.add hY hY)
_ ≤ 5 * d[X; μ # Y ; μ'] := torsion_free_doubling X Y μ μ' hX hY hG
have eq_zero : φ ∘ (Y + Y) = fun _ ↦ 0 := by ext x ; simp only [Function.comp_apply, Pi.add_apply,
map_add, ElementaryAddCommGroup.add_self]
rwa [eq_zero, rdist_zero_eq_half_ent, div_le_iff zero_lt_two, mul_assoc, mul_comm _ 2, ←mul_assoc,
show (5*2 : ℝ) = 10 by norm_num] at this
end Torsion
instance {G : Type u} [AddCommGroup G] [Fintype G] [MeasurableSpace G] [MeasurableSingletonClass G] (H : AddSubgroup G)
: MeasurableSingletonClass (G ⧸ H) :=
⟨λ _ ↦ by { rw [measurableSet_quotient]; simp [measurableSet_discrete] }⟩
section F2_projection
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [ElementaryAddCommGroup G 2] [Fintype G] [MeasurableSpace G]
[MeasurableSingletonClass G] {Ω Ω' : Type*}
/-- Let $G=\mathbb{F}_2^n$ and $X,Y$ be $G$-valued random variables such that
\[\mathbb{H}(X)+\mathbb{H}(Y)> (20/\alpha) d[X;Y],\]
for some $\alpha > 0$.
There is a non-trivial subgroup $H\leq G$ such that
\[\log \lvert H\rvert <(1+\alpha)/2 (\mathbb{H}(X)+\mathbb{H}(Y))\] and
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))< \alpha (\mathbb{H}(X)+\mathbb{H}(Y))\]
where $\psi:G\to G/H$ is the natural projection homomorphism.
-/
lemma app_ent_PFR' [MeasureSpace Ω] [MeasureSpace Ω'] (X : Ω → G) (Y : Ω' → G)
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
{α : ℝ} (hent : 20 * d[X # Y] < α * (H[X] + H[Y])) (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X] + H[Y]) ∧
H[(QuotientAddGroup.mk' H) ∘ X] + H[(QuotientAddGroup.mk' H) ∘ Y] < α * (H[X] + H[Y]) := by
let p : refPackage Ω Ω' G := {
X₀₁ := X
X₀₂ := Y
hmeas1 := hX
hmeas2 := hY
η := 1/8
hη := by norm_num
hη' := by norm_num }
obtain ⟨H, Ω'', hΩ'', U, _, hUmeas, hUunif, ineq⟩ := entropic_PFR_conjecture_improv p rfl
let ψ := (QuotientAddGroup.mk' H)
use H
haveI : Finite H := Subtype.finite
-- Note that H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y]
have ent_le : H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y] := calc
H[ψ ∘ X] + H[ψ ∘ Y] ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· exact ent_of_proj_le hX hUmeas hUunif
· exact ent_of_proj_le hY hUmeas hUunif
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- Note that (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y]
have log_sub_le : (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y] := calc
(log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) =
(H[U] - H[X]) + (H[U] - H[Y]) := by
rw [IsUniform.entropy_eq' hUunif hUmeas, SetLike.coe_sort_coe]
_ ≤ |(H[U] - H[X])| + |(H[U] - H[Y])| := by gcongr <;> exact le_abs_self _
_ ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hX
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hY
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- then the conclusion follows from the assumption `hent` and basic inequality manipulations
exact ⟨by linarith, by linarith⟩
variable [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ' : Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
lemma app_ent_PFR (α : ℝ) (hent: 20 * d[X;μ # Y;μ'] < α * (H[X; μ] + H[Y; μ'])) (hX : Measurable X)
(hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ']
< α * (H[ X; μ] + H[Y; μ']) :=
@app_ent_PFR' _ _ _ _ _ _ _ _ (MeasureSpace.mk μ) (MeasureSpace.mk μ') _ _ _ _ α hent hX hY
set_option maxHeartbeats 300000 in
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables and $\alpha < 1$ then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq (1 + α) / (2 * (1 - α)) * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 20/\alpha * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection'
(α : ℝ) (hX : Measurable X) (hY : Measurable Y) (αpos : 0 < α) (αone : α < 1) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (H[X ; μ] + H[Y ; μ']) ∧
α * (H[(QuotientAddGroup.mk' H) ∘ X ; μ] + H[(QuotientAddGroup.mk' H) ∘ Y ; μ']) ≤
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] := by
let S := { H : AddSubgroup G | (∃ (c : ℝ), 0 ≤ c ∧
log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (1 - c) * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
c * (H[X; μ] + H[Y;μ'])) ∧
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] <
α * (H[ (QuotientAddGroup.mk' H) ∘ X; μ ] + H[ (QuotientAddGroup.mk' H) ∘ Y; μ']) }
have : 0 ≤ H[X ; μ] + H[Y ; μ'] := by linarith [entropy_nonneg X μ, entropy_nonneg Y μ']
have : 0 < 1 - α := sub_pos.mpr αone
by_cases hE : (⊥ : AddSubgroup G) ∈ S
· classical
obtain ⟨H, ⟨⟨c, hc, hlog, hup⟩, hent⟩, hMaxl⟩ :=
S.toFinite.exists_maximal_wrt id S (Set.nonempty_of_mem hE)
set ψ : G →+ G ⧸ H := QuotientAddGroup.mk' H
have surj : Function.Surjective ψ := QuotientAddGroup.mk'_surjective H
set G' := G ⧸ H
have : ElementaryAddCommGroup G' 2 := ElementaryAddCommGroup.quotient_group (by decide)
(by simp [AddSubgroup.zero_mem])
obtain ⟨H', hlog', hup'⟩ := app_ent_PFR _ _ _ _ α hent ((measurable_discrete _).comp hX)
((measurable_discrete _).comp hY)
have H_ne_bot: H' ≠ ⊥ := by
by_contra!
rcases this with rfl
have inj : Function.Injective (QuotientAddGroup.mk' (⊥ : AddSubgroup G')) :=
(QuotientAddGroup.quotientBot : (G' ⧸ ⊥) ≃+ G').symm.injective
rw [entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ inj,
entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ inj] at hup'
nlinarith [entropy_nonneg (ψ ∘ X) μ, entropy_nonneg (ψ ∘ Y) μ']
let H'' := H'.comap ψ
use H''
rw [← (AddSubgroup.map_comap_eq_self_of_surjective surj _ : H''.map ψ = H')] at hup' hlog'
set H' := H''.map ψ
have Hlt : H < H'' := by
have : H = (⊥ : AddSubgroup G').comap ψ := by
simp only [ψ, AddMonoidHom.comap_bot, QuotientAddGroup.ker_mk']
rw [this, AddSubgroup.comap_lt_comap_of_surjective surj]
exact Ne.bot_lt H_ne_bot
let φ : G' ⧸ H' ≃+ G ⧸ H'' := QuotientAddGroup.quotientQuotientEquivQuotient H H'' Hlt.le
set ψ' : G' →+ G' ⧸ H' := QuotientAddGroup.mk' H'
set ψ'' : G →+ G ⧸ H'' := QuotientAddGroup.mk' H''
have diag : ψ' ∘ ψ = φ.symm ∘ ψ'' := rfl
rw [← Function.comp.assoc, ← Function.comp.assoc, diag, Function.comp.assoc,
Function.comp.assoc] at hup'
have cond : log (Nat.card H'') ≤
(1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := by
have cardprod : Nat.card H'' = Nat.card H' * Nat.card H := by
have hcard₀ := Nat.card_congr <| (AddSubgroup.addSubgroupOfEquivOfLe Hlt.le).toEquiv
have hcard₁ := Nat.card_congr <|
(QuotientAddGroup.quotientKerEquivRange (ψ.restrict H'')).toEquiv
have hcard₂ := AddSubgroup.card_eq_card_quotient_mul_card_addSubgroup (H.addSubgroupOf H'')
rw [ψ.ker_restrict H'', QuotientAddGroup.ker_mk', ψ.restrict_range H''] at hcard₁
simpa only [← Nat.card_eq_fintype_card, hcard₀, hcard₁] using hcard₂
calc
log (Nat.card H'')
_ = log ((Nat.card H' : ℝ) * (Nat.card H : ℝ)) := by rw [cardprod]; norm_cast
_ = log (Nat.card H') + log (Nat.card H) := by
rw [Real.log_mul (Nat.cast_ne_zero.2 (@Nat.card_pos H').ne')
(Nat.cast_ne_zero.2 (@Nat.card_pos H).ne')]
_ ≤ (1 + α) / 2 * (H[⇑ψ ∘ X ; μ] + H[⇑ψ ∘ Y ; μ']) + log (Nat.card H) := by gcongr
_ ≤ (1 + α) / 2 * (c * (H[X; μ] + H[Y;μ'])) +
(1 + α) / (2 * (1 - α)) * (1 - c) * (H[X ; μ] + H[Y ; μ']) := by gcongr
_ = (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X ; μ] + H[Y ; μ']) := by
field_simp; ring
have HS : H'' ∉ S := λ Hs => Hlt.ne (hMaxl H'' Hs Hlt.le)
simp only [S, Set.mem_setOf_eq, not_and, not_lt] at HS
refine ⟨?_, HS ⟨α * c, by positivity, cond, ?_⟩⟩
· calc
log (Nat.card H'')
_ ≤ (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := cond
_ ≤ (1 + α) / (2 * (1 - α)) * 1 * (H[X; μ] + H[Y;μ']) := by gcongr; simp; positivity
_ = (1 + α) / (2 * (1 - α)) * (H[X; μ] + H[Y;μ']) := by simp only [mul_one]
· calc
H[ ψ'' ∘ X; μ ] + H[ ψ'' ∘ Y; μ' ]
_ = H[ φ.symm ∘ ψ'' ∘ X; μ ] + H[ φ.symm ∘ ψ'' ∘ Y; μ' ] := by
simp_rw [← entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ φ.symm.injective,
← entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ φ.symm.injective]
_ ≤ α * (H[ ψ ∘ X; μ ] + H[ ψ ∘ Y; μ' ]) := hup'.le
_ ≤ α * (c * (H[X ; μ] + H[Y ; μ'])) := by gcongr
_ = (α * c) * (H[X ; μ] + H[Y ; μ']) := by ring
· use ⊥
constructor
· simp only [AddSubgroup.mem_bot, Nat.card_eq_fintype_card, Fintype.card_ofSubsingleton,
Nat.cast_one, log_one]
positivity
· simp only [S, Set.mem_setOf_eq, not_and, not_lt] at hE
exact hE ⟨1, by norm_num, by
norm_num; exact add_le_add (entropy_comp_le μ hX _) (entropy_comp_le μ' hY _)⟩
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq 2 * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 34 * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
34 * d[(QuotientAddGroup.mk' H) ∘ X;μ # (QuotientAddGroup.mk' H) ∘ Y;μ'] := by
rcases PFR_projection' X Y μ μ' ((3 : ℝ) / 5) hX hY (by norm_num) (by norm_num) with ⟨H, h, h'⟩
refine ⟨H, ?_, ?_⟩
· convert h
norm_num
· have : 0 ≤ d[⇑(QuotientAddGroup.mk' H) ∘ X ; μ # ⇑(QuotientAddGroup.mk' H) ∘ Y ; μ'] :=
rdist_nonneg ((measurable_discrete _).comp hX) ((measurable_discrete _).comp hY)
linarith
end F2_projection
open MeasureTheory ProbabilityTheory Real Set
open scoped BigOperators
lemma four_logs {a b c d : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) (hd : 0 < d) :
log ((a*b)/(c*d)) = log a + log b - log c - log d := by
rw [log_div, log_mul, log_mul, sub_sub] <;> positivity
lemma sum_prob_preimage {G H : Type*} {X : Finset H} {A : Set G} [Finite A] {φ : A → X}
{A_ : H → Set G} (hA : A.Nonempty) (hφ : ∀ x : X, A_ x = Subtype.val '' (φ ⁻¹' {x})) :
∑ x in X, (Nat.card (A_ x) : ℝ) / (Nat.card A) = 1 := by
rw [← Finset.sum_div]
apply (div_eq_one_iff_eq <| Nat.cast_ne_zero.mpr <| Nat.pos_iff_ne_zero.mp (@Nat.card_pos _ hA.to_subtype _)).mpr
classical
haveI := Fintype.ofFinite A
rewrite [Nat.card_eq_fintype_card, ← Finset.card_univ, Finset.card_eq_sum_card_fiberwise
<| fun a _ ↦ Finset.mem_univ (φ a), ← Finset.sum_coe_sort]
norm_cast
congr; ext
rewrite [← Set.Finite.toFinset_setOf, (Set.toFinite _).card_toFinset, ← Nat.card_eq_fintype_card,
hφ, Nat.card_image_of_injective Subtype.val_injective]; rfl
/-- Let $\phi : G\to H$ be a homomorphism and $A,B\subseteq G$ be finite subsets. If $x,y\in H$ then let $A_x=A\cap \phi^{-1}(x)$ and $B_y=B\cap \phi^{-1}(y)$. There exist $x,y\in H$ such that $A_x,B_y$ are both non-empty and
\[d[\phi(U_A);\phi(U_B)]\log \frac{\lvert A\rvert\lvert B\rvert}{\lvert A_x\rvert\lvert B_y\rvert}\leq (\mathbb{H}(\phi(U_A))+\mathbb{H}(\phi(U_B)))(d(U_A,U_B)-d(U_{A_x},U_{B_y}).\] -/
lemma single_fibres {G H Ω Ω': Type u}
[AddCommGroup G] [Countable G] [MeasurableSpace G] [MeasurableSingletonClass G]
[AddCommGroup H] [Countable H] [MeasurableSpace H] [MeasurableSingletonClass H]
[MeasureSpace Ω] [MeasureSpace Ω']
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
(φ : G →+ H)
{A B : Set G} [Finite A] [Finite B] {UA : Ω → G} {UB: Ω' → G} (hA : A.Nonempty) (hB : B.Nonempty)
(hUA': Measurable UA) (hUB': Measurable UB) (hUA: IsUniform A UA) (hUB: IsUniform B UB)
(hUA_mem : ∀ ω, UA ω ∈ A) (hUB_mem : ∀ ω, UB ω ∈ B) :
∃ (x y : H) (Ax By: Set G),
Ax = A ∩ φ.toFun ⁻¹' {x} ∧ By = B ∩ φ.toFun ⁻¹' {y} ∧ Ax.Nonempty ∧ By.Nonempty ∧
d[φ.toFun ∘ UA # φ.toFun ∘ UB]
* log ((Nat.card A) * (Nat.card B) / ((Nat.card Ax) * (Nat.card By))) ≤
(H[φ.toFun ∘ UA] + H[φ.toFun ∘ UB]) * (d[UA # UB] - dᵤ[Ax # By]) := by
have : Nonempty A := hA.to_subtype
have : Nonempty B := hB.to_subtype
haveI : FiniteRange UA := finiteRange_of_finset UA A.toFinite.toFinset (by simpa)
haveI : FiniteRange UB := finiteRange_of_finset UB B.toFinite.toFinset (by simpa)
have hUA_coe : IsUniform A.toFinite.toFinset.toSet UA := by rwa [Set.Finite.coe_toFinset]
have hUB_coe : IsUniform B.toFinite.toFinset.toSet UB := by rwa [Set.Finite.coe_toFinset]
let A_ (x : H) : Set G := A ∩ φ.toFun ⁻¹' {x}
let B_ (y : H) : Set G := B ∩ φ.toFun ⁻¹' {y}
let X : Finset H := FiniteRange.toFinset (φ.toFun ∘ UA)
let Y : Finset H := FiniteRange.toFinset (φ.toFun ∘ UB)
haveI h_Ax (x : X) : Nonempty (A_ x.val) := by
obtain ⟨ω, hω⟩ := (FiniteRange.mem_iff _ _).mp x.property
use UA ω; exact Set.mem_inter (hUA_mem ω) (by exact hω)
haveI h_By (y : Y) : Nonempty (B_ y.val) := by
obtain ⟨ω, hω⟩ := (FiniteRange.mem_iff _ _).mp y.property
use UB ω; exact Set.mem_inter (hUB_mem ω) (by exact hω)
have h_AX (a : A) : φ.toFun a.val ∈ X := by
obtain ⟨ω, hω⟩ := hUA_coe.nonempty_preimage_of_mem hUA' (A.toFinite.mem_toFinset.mpr a.property)
exact (FiniteRange.mem_iff _ (φ.toFun a.val)).mpr ⟨ω, congr_arg _ hω⟩
have h_BY (b : B) : φ.toFun b.val ∈ Y := by
obtain ⟨ω, hω⟩ := hUB_coe.nonempty_preimage_of_mem hUB' (B.toFinite.mem_toFinset.mpr b.property)
exact (FiniteRange.mem_iff _ (φ.toFun b.val)).mpr ⟨ω, congr_arg _ hω⟩
let φ_AX (a : A) : X := by use φ.toFun a.val; exact h_AX a
let φ_BY (b : B) : Y := by use φ.toFun b.val; exact h_BY b
have h_φ_AX (x : X) : A_ x.val = φ_AX ⁻¹' {x} := by ext; simp [A_, φ_AX]; simp [Subtype.ext_iff]
have h_φ_BY (y : Y) : B_ y.val = φ_BY ⁻¹' {y} := by ext; simp [B_, φ_BY]; simp [Subtype.ext_iff]
let p (x : H) (y : H) : ℝ :=
(Nat.card (A_ x).Elem) * (Nat.card (B_ y).Elem) / ((Nat.card A.Elem) * (Nat.card B.Elem))
have :
∑ x in X, ∑ y in Y, (p x y) * dᵤ[A_ x # B_ y] ≤ d[UA # UB] - d[φ.toFun ∘ UA # φ.toFun ∘ UB] :=
calc
_ = d[UA | φ.toFun ∘ UA # UB | φ.toFun ∘ UB] := by
rewrite [condRuzsaDist_eq_sum hUA' ((measurable_discrete _).comp hUA')
hUB' ((measurable_discrete _).comp hUB')]
refine Finset.sum_congr rfl <| fun x hx ↦ Finset.sum_congr rfl <| fun y hy ↦ ?_
haveI : Nonempty (A_ x) := h_Ax ⟨x, hx⟩
haveI : Nonempty (B_ y) := h_By ⟨y, hy⟩
let μx := (ℙ : Measure Ω)[|(φ.toFun ∘ UA) ⁻¹' {x}]
let μy := (ℙ : Measure Ω')[|(φ.toFun ∘ UB) ⁻¹' {y}]
have h_μ_p : IsProbabilityMeasure μx ∧ IsProbabilityMeasure μy := by
constructor <;> apply ProbabilityTheory.cond_isProbabilityMeasure <;> rw [Set.preimage_comp]
refine @IsUniform.measure_preimage_ne_zero _ _ _ _ _ _ _ _ _ _ hUA_coe hUA' _ ?_
swap; refine @IsUniform.measure_preimage_ne_zero _ _ _ _ _ _ _ _ _ _ hUB_coe hUB' _ ?_
all_goals rwa [Set.inter_comm, Set.Finite.coe_toFinset]
have h_μ_unif : IsUniform (A_ x) UA μx ∧ IsUniform (B_ y) UB μy := by
have : _ ∧ _ := ⟨hUA.restrict hUA' (φ.toFun ⁻¹' {x}), hUB.restrict hUB' (φ.toFun ⁻¹' {y})⟩
rwa [Set.inter_comm _ A, Set.inter_comm _ B] at this
rewrite [rdist_set_eq_rdist h_μ_p.1 h_μ_p.2 h_μ_unif.1 h_μ_unif.2 hUA' hUB']
show _ = (Measure.real _ (UA ⁻¹' (_ ⁻¹' _))) * (Measure.real _ (UB ⁻¹' (_ ⁻¹' _))) * _
rewrite [hUA_coe.measureReal_preimage hUA', hUB_coe.measureReal_preimage hUB']
simp_rw [p, A_, B_, IsProbabilityMeasure.measureReal_univ, one_mul]
rewrite [mul_div_mul_comm, Set.inter_comm A, Set.inter_comm B]
simp only [Set.Finite.coe_toFinset, Set.Finite.mem_toFinset, Finset.mem_val]; rfl
_ ≤ d[UA # UB] - d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
rewrite [ZeroHom.toFun_eq_coe, AddMonoidHom.toZeroHom_coe]
linarith only [rdist_le_sum_fibre φ hUA' hUB' (μ := ℙ) (μ' := ℙ)]
let M := H[φ.toFun ∘ UA] + H[φ.toFun ∘ UB]
have hM : M = ∑ x in X, ∑ y in Y, Real.negMulLog (p x y) := by
have h_compl {x y} (h_notin : (x, y) ∉ X ×ˢ Y) : Real.negMulLog (p x y) = 0 := by
unfold_let p; beta_reduce
rewrite [Finset.mem_product, not_and_or] at h_notin
suffices A_ x = ∅ ∨ B_ y = ∅ by obtain h | h := this <;> rw [h] <;> simp
refine h_notin.imp ?_ ?_
· rw [← not_nonempty_iff_eq_empty]
rintro h ⟨a, ha, rfl⟩
exact h (h_AX ⟨a, ha⟩)
· rw [← not_nonempty_iff_eq_empty]
rintro h ⟨a, ha, rfl⟩
exact h (h_BY ⟨a, ha⟩)
unfold_let M
unfold entropy
haveI := isProbabilityMeasure_map (μ := ℙ) ((measurable_discrete φ).comp hUA').aemeasurable
haveI := isProbabilityMeasure_map (μ := ℙ) ((measurable_discrete φ).comp hUB').aemeasurable
rewrite [← Finset.sum_product', ← tsum_eq_sum fun _ ↦ h_compl, ← measureEntropy_prod]
apply tsum_congr; intro; congr
rewrite [← Set.singleton_prod_singleton, Measure.smul_apply, Measure.prod_prod,
Measure.map_apply ((measurable_discrete _).comp hUA') (MeasurableSet.singleton _),
Measure.map_apply ((measurable_discrete _).comp hUB') (MeasurableSet.singleton _),
Set.preimage_comp, hUA_coe.measure_preimage hUA',
Set.preimage_comp, hUB_coe.measure_preimage hUB']
simp [p, A_, B_, mul_div_mul_comm, Set.inter_comm, ENNReal.toReal_div]
have h_sum : ∑ x in X, ∑ y in Y,
(p x y) * (M * dᵤ[A_ x # B_ y] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p x y)) ≤
M * d[UA # UB] :=
calc
_ = ∑ x in X, ∑ y in Y, (p x y) * M * dᵤ[A_ x # B_ y] + M * d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
simp_rw [hM, Finset.sum_mul, ← Finset.sum_add_distrib]
refine Finset.sum_congr rfl <| fun _ _ ↦ Finset.sum_congr rfl <| fun _ _ ↦ ?_
simp only [negMulLog, left_distrib, mul_assoc, Finset.sum_mul]
exact congrArg (HAdd.hAdd _) (by group)
_ = M * ∑ x in X, ∑ y in Y, (p x y) * dᵤ[A_ x # B_ y] + M * d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
simp_rw [Finset.mul_sum]
congr; ext; congr; ext; group
_ ≤ M * d[UA # UB] := by
rewrite [← left_distrib]
apply mul_le_mul_of_nonneg_left
· linarith
· unfold_let M
linarith only [entropy_nonneg (φ.toFun ∘ UA) ℙ, entropy_nonneg (φ.toFun ∘ UB) ℙ]
have : ∃ x : X, ∃ y : Y,
M * dᵤ[A_ x.val # B_ y.val] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p x.val y.val) ≤
M * d[UA # UB] := by
let f (xy : H × H) := (p xy.1 xy.2) * (M * d[UA # UB])
let g (xy : H × H) := (p xy.1 xy.2) *
(M * dᵤ[A_ xy.1 # B_ xy.2] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p xy.1 xy.2))
by_contra hc; push_neg at hc
replace hc : ∀ xy ∈ X ×ˢ Y, f xy < g xy := by
refine fun xy h ↦ mul_lt_mul_of_pos_left ?_ ?_
· exact hc ⟨xy.1, (Finset.mem_product.mp h).1⟩ ⟨xy.2, (Finset.mem_product.mp h).2⟩
· haveI : Nonempty _ := h_Ax ⟨xy.1, (Finset.mem_product.mp h).1⟩
haveI : Nonempty _ := h_By ⟨xy.2, (Finset.mem_product.mp h).2⟩
simp only [p, div_pos, mul_pos, Nat.cast_pos, Nat.card_pos]
have h_nonempty : Finset.Nonempty (X ×ˢ Y) := by
use ⟨φ.toFun <| UA <| Classical.choice <| ProbabilityMeasure.nonempty ⟨ℙ, inferInstance⟩,
φ.toFun <| UB <| Classical.choice <| ProbabilityMeasure.nonempty ⟨ℙ, inferInstance⟩⟩
exact Finset.mem_product.mpr ⟨FiniteRange.mem _ _, FiniteRange.mem _ _⟩
replace hc := Finset.sum_lt_sum_of_nonempty h_nonempty hc
have h_p_one : ∑ x in X ×ˢ Y, p x.1 x.2 = 1 := by
simp_rw [Finset.sum_product, p, mul_div_mul_comm, ← Finset.mul_sum,
← sum_prob_preimage hA h_φ_AX, sum_prob_preimage hB h_φ_BY, mul_one]
rewrite [← Finset.sum_mul, h_p_one, one_mul, Finset.sum_product] at hc
exact not_le_of_gt hc h_sum
obtain ⟨x, y, hxy⟩ := this
refine ⟨x, y, A_ x.val, B_ y.val, rfl, rfl, @nonempty_of_nonempty_subtype _ _ (h_Ax x), @nonempty_of_nonempty_subtype _ _ (h_By y), ?_⟩
rewrite [← inv_div, Real.log_inv]
show _ * -log (p x.val y.val) ≤ M * _
linarith only [hxy]
section dim
open Classical
variable {G : Type*} [AddCommGroup G]
/- If G ≅ ℤᵈ then there is a subgroup H of G such that A lies in a coset of H. This is helpful to
give the equivalent definition of `dimension`. Here this is stated in greated generality since the
proof carries over automatically-/
lemma exists_coset_cover (A : Set G) :
∃ (d : ℕ), ∃ (S : Submodule ℤ G) (v : G),
FiniteDimensional.finrank ℤ S = d ∧ ∀ a ∈ A, a - v ∈ S := by
existsi FiniteDimensional.finrank ℤ (⊤ : Submodule ℤ G), ⊤, 0
refine ⟨rfl, fun a _ ↦ trivial⟩
/-- The dimension of the affine span over `ℤ` of a subset of an additive group. -/
noncomputable def dimension (A : Set G) : ℕ := Nat.find (exists_coset_cover A)
lemma dimension_le_of_coset_cover (A : Set G) (S : Submodule ℤ G) (v : G)
(hA : ∀ a ∈ A, a - v ∈ S) : dimension A ≤ FiniteDimensional.finrank ℤ S := by
apply Nat.find_le
existsi S , v
exact ⟨rfl, hA⟩
lemma dimension_le_rank [Module.Finite ℤ G] (A : Set G) :
dimension A ≤ FiniteDimensional.finrank ℤ G := by
obtain ⟨S, v, hs, _⟩ := Nat.find_spec (exists_coset_cover A)
rw [dimension, ←hs]
apply Submodule.finrank_le S
end dim
variable {G : Type u} [AddCommGroup G] [Module.Free ℤ G] [Module.Finite ℤ G] [Countable G] [MeasurableSpace G] [MeasurableSingletonClass G]
open Real MeasureTheory ProbabilityTheory Pointwise Set
/-- Move to Mathlib? `Finsupp.mapRange` of a surjective function is surjective. -/
lemma Finsupp.mapRange_surjective {α : Type u_1} {M : Type u_5} {N : Type u_7} [Zero M] [Zero N] (f : M → N) (hf : f 0 = 0)
(hs : Function.Surjective f) : Function.Surjective (Finsupp.mapRange (α := α) f hf) := by
classical
let g (n : N) : M := if n = 0 then 0 else Function.surjInv hs n
have : Function.RightInverse g f := by
intro n
by_cases h : n = 0
. simp [g, h, hf]
· simp [g, h, Function.surjInv_eq hs n]
have hg : g 0 = 0 := by simp [g]
have hfg : (f ∘ g) 0 = 0 := by simp [hf, hg]
intro F
use Finsupp.mapRange g hg F
rw [← Finsupp.mapRange_comp (h := hfg)]
convert Finsupp.mapRange_id F
convert Function.RightInverse.id this
/-- A free Z-module is torsion-free. Move to Mathlib? -/
| lemma torsion_free : AddMonoid.IsTorsionFree G | torsion_free | 25309ad 20231211 | f025369 20231228 | pfr/PFR/WeakPFR.lean | {
"lineInFile": 641,
"tokenPositionInFile": 35373,
"theoremPositionInFile": 20
} | {
"inFilePremises": false,
"repositoryPremises": false
} | {
"hasProof": true,
"proof": "by\n rintro x hx hn\n rw [isOfFinAddOrder_iff_nsmul_eq_zero] at hn\n rcases hn with ⟨ n, hn, hn' ⟩\n apply_fun Module.Free.repr ℤ G at hn'\n simp_rw [map_nsmul, map_zero, smul_eq_zero, AddEquivClass.map_eq_zero_iff, hx, or_false] at hn'\n linarith",
"proofType": "tactic",
"proofLengthLines": 7,
"proofLengthTokens": 259
} | pfr |
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Quotient
import Mathlib.GroupTheory.Torsion
import Mathlib.GroupTheory.Torsion
import Mathlib.LinearAlgebra.FreeModule.PID
import PFR.Mathlib.Data.Set.Pointwise.SMul
import PFR.EntropyPFR
import PFR.ImprovedPFR
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Mathlib.GroupTheory.Torsion
/-!
# Weak PFR over the integers
Here we use the entropic form of PFR to deduce a weak form of PFR over the integers.
## Main statement
* `weak_PFR_int`: Let $A\subseteq \mathbb{Z}^d$ and $\lvert A+A\rvert\leq K\lvert A\rvert$.
There exists $A'\subseteq A$ such that $\lvert A'\rvert \geq K^{-17}\lvert A\rvert$ and
$\dim A' \leq (40/\log 2)\log K$.
-/
section AddCommGroup
variable {G : Type*} [AddCommGroup G] {A B : Set G}
open Set
open scoped Pointwise
def IsShift (A B : Set G) : Prop := ∃ x : G, A = x +ᵥ B
lemma IsShift.sub_self_congr : IsShift A B → A - A = B - B := by
rintro ⟨x, rfl⟩; simp [vadd_sub_vadd_comm, singleton_zero]
lemma IsShift.card_congr : IsShift A B → Nat.card A = Nat.card B := by rintro ⟨x, rfl⟩; simp
/-- The property of two sets A, B of a group G not being contained in cosets of the same proper
subgroup -/
def NotInCoset (A B : Set G) : Prop := AddSubgroup.closure ((A - A) ∪ (B - B)) = ⊤
/-- Without loss of generality, one can move (up to translation and embedding) any pair A, B of non-empty sets into a subgroup where they are not in a coset. -/
lemma wlog_notInCoset (hA : A.Nonempty) (hB : B.Nonempty) :
∃ (G' : AddSubgroup G) (A' B' : Set G'), IsShift A A' ∧ IsShift B B' ∧ NotInCoset A' B' := by
obtain ⟨x, hx⟩ := hA
obtain ⟨y, hy⟩ := hB
set G' := AddSubgroup.closure ((A - A) ∪ (B - B))
set A' : Set G' := (↑) ⁻¹' ((-x) +ᵥ A)
set B' : Set G' := (↑) ⁻¹' ((-y) +ᵥ B)
have hxA : -x +ᵥ A ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hx).trans $ (subset_union_left ..).trans
AddSubgroup.subset_closure
have hyB : -y +ᵥ B ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hy).trans $ (subset_union_right ..).trans
AddSubgroup.subset_closure
have hA : IsShift A A' := ⟨x, by rw [Set.image_preimage_eq_of_subset hxA, vadd_neg_vadd]⟩
have hB : IsShift B B' := ⟨y, by rw [Set.image_preimage_eq_of_subset hyB, vadd_neg_vadd]⟩
refine ⟨G', A', B', hA, hB, ?_⟩
unfold NotInCoset
convert AddSubgroup.closure_preimage_eq_top ((A - A) ∪ (B - B))
simp_rw [preimage_union, hA.sub_self_congr, hB.sub_self_congr]
rw [preimage_sub, preimage_sub]
simp [A', B', preimage_image_preimage]
all_goals apply_rules [Subtype.coe_injective, (image_preimage_subset ..).trans, hxA, hyB]
end AddCommGroup
section Torsion
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [MeasurableSpace G] [MeasurableSingletonClass G]
[Countable G] {Ω Ω' : Type u} [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ': Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
/-- If $G$ is torsion-free and $X,Y$ are $G$-valued random variables then $d[X;2Y]\leq 5d[X;Y]$. -/
lemma torsion_free_doubling [FiniteRange X] [FiniteRange Y]
(hX : Measurable X) (hY : Measurable Y) (hG : AddMonoid.IsTorsionFree G) :
d[X ; μ # (Y + Y) ; μ'] ≤ 5 * d[X; μ # Y ; μ'] := by
obtain ⟨A, mA, μA, X', Y'₁, Y'₂, hμA, h_indep, hX'_meas, hY'₁_meas, hY'₂_meas, hX'_ident,
hY'₁_ident, hY'₂_ident, _, _, _⟩ := independent_copies3_nondep_finiteRange hX hY hY μ μ' μ'
have h_meas (i : Fin 3) : Measurable (![X', Y'₁, Y'₂] i) := by fin_cases i <;> assumption
haveI : NoZeroSMulDivisors ℕ G := hG.noZeroNsmulDivisors
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨x, y₁, y₂⟩ ↦ (x, y₁ - y₂, x - 2 • y₁)
show H[f ∘ ⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] = _
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hX'_meas <| Measurable.prod hY'₁_meas hY'₂_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun X' (prod Y'₁ Y'₂) μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 1 2 0 (by decide) (by decide)
rw [this.entropy_pair_eq_add hX'_meas (by exact Measurable.prod hY'₁_meas hY'₂_meas),
IndepFun.entropy_pair_eq_add hY'₁_meas hY'₂_meas (h_indep.indepFun (show 1 ≠ 2 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, two_mul]
have : H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[X ; μ] + H[Y ; μ'] := calc
H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[⟨X', Y'₁⟩ ; μA] := by
let f : G × G → G × G := fun ⟨x, y₁⟩ ↦ (x, x - 2 • y₁)
show H[f ∘ ⟨X', Y'₁⟩ ; μA] = _
apply entropy_comp_of_injective μA (by exact Measurable.prod hX'_meas hY'₁_meas) f
exact fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + H[Y ; μ'] := by
rw [IndepFun.entropy_pair_eq_add hX'_meas hY'₁_meas (h_indep.indepFun (show 0 ≠ 1 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq]
let f : G × G → G × G := fun ⟨x, y⟩ ↦ (x, y - x)
have hf : f.Injective := fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all
have : H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] := calc
H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] = H[f ∘ ⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
show _ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂ - (Y'₁ - Y'₂)⟩ ; μA]
rw [sub_sub_sub_cancel_right, ← sub_add_eq_sub_sub, two_nsmul]
_ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
refine entropy_comp_of_injective μA (Measurable.prod ?_ ?_) f hf
· exact Measurable.sub hY'₁_meas hY'₂_meas
· exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
_ ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] :=
entropy_pair_le_add (hY'₁_meas.sub' hY'₂_meas) (hX'_meas.sub' hY'₁_meas |>.sub' hY'₂_meas) μA
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] + H[X' - 2 • Y'₁ ; μA] ≤
H[⟨X', X' - 2 • Y'₁⟩ ; μA] + H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] := by
haveI : FiniteRange (Y'₁ - Y'₂) := FiniteRange.sub Y'₁ Y'₂
haveI : FiniteRange (2 • Y'₁) := by show FiniteRange ((fun x ↦ 2 • x) ∘ Y'₁); infer_instance
apply entropy_triple_add_entropy_le μA hX'_meas (Measurable.sub hY'₁_meas hY'₂_meas)
exact Measurable.sub' hX'_meas <| Measurable.const_smul hY'₁_meas 2
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨y₁, y₂, x⟩ ↦ (y₁, y₂, x - y₁ - y₂)
show H[f ∘ ⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA]
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hY'₁_meas <| Measurable.prod hY'₂_meas hX'_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun Y'₁ (prod Y'₂ X') μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 2 0 1 (by decide) (by decide)
rw [this.entropy_pair_eq_add hY'₁_meas (by exact Measurable.prod hY'₂_meas hX'_meas),
IndepFun.entropy_pair_eq_add hY'₂_meas hX'_meas (h_indep.indepFun (show 2 ≠ 0 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq]
group
have : H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₂ ; μA] := calc
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₁, X' - Y'₂⟩ ; μA] := by rw [sub_right_comm] ; rfl
_ = H[⟨Y'₁, X' - Y'₂⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₁_meas <| Measurable.sub hX'_meas hY'₂_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₂ ; μA] := by
haveI : FiniteRange (X' - Y'₂) := FiniteRange.sub X' Y'₂
convert IndepFun.entropy_pair_eq_add hY'₁_meas (hX'_meas.sub hY'₂_meas)
<| h_indep.indepFun_sub_right h_meas 1 0 2 (by decide) (by decide)
exact hY'₁_ident.entropy_eq.symm
have : H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₁ ; μA] := calc
H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₂, X' - Y'₁⟩ ; μA] := rfl
_ = H[⟨Y'₂, X' - Y'₁⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₂_meas <| Measurable.sub hX'_meas hY'₁_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₁ ; μA] := by
haveI : FiniteRange (X' - Y'₁) := FiniteRange.sub X' Y'₁
convert IndepFun.entropy_pair_eq_add hY'₂_meas (hX'_meas.sub hY'₁_meas)
<| h_indep.indepFun_sub_right h_meas 2 0 1 (by decide) (by decide)
exact hY'₂_ident.entropy_eq.symm
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] ≤
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] + H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
apply entropy_triple_add_entropy_le μA hY'₁_meas hY'₂_meas
exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
have : H[X' - Y'₁ - Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := calc
H[X' - Y'₁ - Y'₂ ; μA] ≤ H[X' - Y'₁ ; μA] + H[X' - Y'₂ ; μA] - H[X ; μ] := by linarith
_ = 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := by
nth_rw 1 [two_mul, ← hX'_ident.rdist_eq hY'₁_ident, ← hX'_ident.rdist_eq hY'₂_ident]
have h1 : d[X' ; μA # Y'₁ ; μA] = H[X' - Y'₁ ; μA] - H[X' ; μA] / 2 - H[Y'₁ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 1 by decide)).rdist_eq hX'_meas hY'₁_meas
have h2 : d[X' ; μA # Y'₂ ; μA] = H[X' - Y'₂ ; μA] - H[X' ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 2 by decide)).rdist_eq hX'_meas hY'₂_meas
rw [h1, h2, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, hX'_ident.entropy_eq]
group
have : d[X ; μ # 2 • Y ; μ'] ≤
d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := calc
d[X ; μ # 2 • Y ; μ'] = H[X' - 2 • Y'₁ ; μA] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by
have h2Y_ident : IdentDistrib (2 • Y'₁) (2 • Y) (μ := μA) (ν := μ') := by
convert hY'₁_ident.comp <| measurable_discrete <| fun g ↦ 2 • g
have h2Y_indep : IndepFun X' (2 • Y'₁) (μ := μA) := by
convert (h_indep.indepFun (show 0 ≠ 1 by decide)).comp measurable_id
(measurable_const_smul 2)
rw [← hX'_ident.rdist_eq h2Y_ident,
h2Y_indep.rdist_eq hX'_meas <| Measurable.const_smul hY'₁_meas 2,
hX'_ident.entropy_eq, h2Y_ident.entropy_eq]
_ ≤ H[Y'₁ - Y'₂ ; μA] + 2 * d[X ; μ # Y ; μ'] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by linarith
_ = d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := by
have H2Y : H[2 • Y ; μ'] = H[Y ; μ'] := by
let f (g : G) := 2 • g
exact entropy_comp_of_injective μ' hY f (fun _ _ ↦ by simp [f, smul_right_inj])
have : d[Y'₁ ; μA # Y'₂ ; μA] = H[Y'₁ - Y'₂ ; μA] - H[Y'₁ ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 1 ≠ 2 by decide)).rdist_eq hY'₁_meas hY'₂_meas
rw [this, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, H2Y]
group
have : d[Y'₁ ; μA # Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] := by
rw [two_mul]
convert rdist_triangle hY'₁_meas hX'_meas hY'₂_meas (μ := μA) (μ' := μA) (μ'' := μA)
· exact rdist_symm.trans (hY'₁_ident.rdist_eq hX'_ident).symm
· exact (hX'_ident.rdist_eq hY'₂_ident).symm
rw [← two_nsmul]
linarith [abs_le.mp <| diff_ent_le_rdist hX hY (μ := μ) (μ' := μ')]
/-- If $G$ is a torsion-free group and $X,Y$ are $G$-valued random variables and
$\phi : G\to \mathbb{F}_2^d$ is a homomorphism then
\[\mathbb{H}(\phi(X))\leq 10d[X;Y].\] -/
lemma torsion_dist_shrinking {H : Type u} [FiniteRange X] [FiniteRange Y] (hX : Measurable X)
(hY : Measurable Y) [AddCommGroup H] [ElementaryAddCommGroup H 2]
[MeasurableSpace H] [MeasurableSingletonClass H] [Countable H]
(hG : AddMonoid.IsTorsionFree G) (φ : G →+ H) :
H[φ ∘ X ; μ] ≤ 10 * d[X; μ # Y ; μ'] := by
have :=
calc d[φ ∘ X ; μ # φ ∘ (Y + Y); μ'] ≤ d[X; μ # (Y + Y) ; μ'] := rdist_of_hom_le φ hX (Measurable.add hY hY)
_ ≤ 5 * d[X; μ # Y ; μ'] := torsion_free_doubling X Y μ μ' hX hY hG
have eq_zero : φ ∘ (Y + Y) = fun _ ↦ 0 := by ext x ; simp only [Function.comp_apply, Pi.add_apply,
map_add, ElementaryAddCommGroup.add_self]
rwa [eq_zero, rdist_zero_eq_half_ent, div_le_iff zero_lt_two, mul_assoc, mul_comm _ 2, ←mul_assoc,
show (5*2 : ℝ) = 10 by norm_num] at this
end Torsion
instance {G : Type u} [AddCommGroup G] [Fintype G] [MeasurableSpace G] [MeasurableSingletonClass G] (H : AddSubgroup G)
: MeasurableSingletonClass (G ⧸ H) :=
⟨λ _ ↦ by { rw [measurableSet_quotient]; simp [measurableSet_discrete] }⟩
section F2_projection
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [ElementaryAddCommGroup G 2] [Fintype G] [MeasurableSpace G]
[MeasurableSingletonClass G] {Ω Ω' : Type*}
/-- Let $G=\mathbb{F}_2^n$ and $X,Y$ be $G$-valued random variables such that
\[\mathbb{H}(X)+\mathbb{H}(Y)> (20/\alpha) d[X;Y],\]
for some $\alpha > 0$.
There is a non-trivial subgroup $H\leq G$ such that
\[\log \lvert H\rvert <(1+\alpha)/2 (\mathbb{H}(X)+\mathbb{H}(Y))\] and
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))< \alpha (\mathbb{H}(X)+\mathbb{H}(Y))\]
where $\psi:G\to G/H$ is the natural projection homomorphism.
-/
lemma app_ent_PFR' [MeasureSpace Ω] [MeasureSpace Ω'] (X : Ω → G) (Y : Ω' → G)
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
{α : ℝ} (hent : 20 * d[X # Y] < α * (H[X] + H[Y])) (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X] + H[Y]) ∧
H[(QuotientAddGroup.mk' H) ∘ X] + H[(QuotientAddGroup.mk' H) ∘ Y] < α * (H[X] + H[Y]) := by
let p : refPackage Ω Ω' G := {
X₀₁ := X
X₀₂ := Y
hmeas1 := hX
hmeas2 := hY
η := 1/8
hη := by norm_num
hη' := by norm_num }
obtain ⟨H, Ω'', hΩ'', U, _, hUmeas, hUunif, ineq⟩ := entropic_PFR_conjecture_improv p rfl
let ψ := (QuotientAddGroup.mk' H)
use H
haveI : Finite H := Subtype.finite
-- Note that H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y]
have ent_le : H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y] := calc
H[ψ ∘ X] + H[ψ ∘ Y] ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· exact ent_of_proj_le hX hUmeas hUunif
· exact ent_of_proj_le hY hUmeas hUunif
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- Note that (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y]
have log_sub_le : (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y] := calc
(log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) =
(H[U] - H[X]) + (H[U] - H[Y]) := by
rw [IsUniform.entropy_eq' hUunif hUmeas, SetLike.coe_sort_coe]
_ ≤ |(H[U] - H[X])| + |(H[U] - H[Y])| := by gcongr <;> exact le_abs_self _
_ ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hX
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hY
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- then the conclusion follows from the assumption `hent` and basic inequality manipulations
exact ⟨by linarith, by linarith⟩
variable [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ' : Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
lemma app_ent_PFR (α : ℝ) (hent: 20 * d[X;μ # Y;μ'] < α * (H[X; μ] + H[Y; μ'])) (hX : Measurable X)
(hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ']
< α * (H[ X; μ] + H[Y; μ']) :=
@app_ent_PFR' _ _ _ _ _ _ _ _ (MeasureSpace.mk μ) (MeasureSpace.mk μ') _ _ _ _ α hent hX hY
set_option maxHeartbeats 300000 in
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables and $\alpha < 1$ then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq (1 + α) / (2 * (1 - α)) * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 20/\alpha * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection'
(α : ℝ) (hX : Measurable X) (hY : Measurable Y) (αpos : 0 < α) (αone : α < 1) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (H[X ; μ] + H[Y ; μ']) ∧
α * (H[(QuotientAddGroup.mk' H) ∘ X ; μ] + H[(QuotientAddGroup.mk' H) ∘ Y ; μ']) ≤
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] := by
let S := { H : AddSubgroup G | (∃ (c : ℝ), 0 ≤ c ∧
log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (1 - c) * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
c * (H[X; μ] + H[Y;μ'])) ∧
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] <
α * (H[ (QuotientAddGroup.mk' H) ∘ X; μ ] + H[ (QuotientAddGroup.mk' H) ∘ Y; μ']) }
have : 0 ≤ H[X ; μ] + H[Y ; μ'] := by linarith [entropy_nonneg X μ, entropy_nonneg Y μ']
have : 0 < 1 - α := sub_pos.mpr αone
by_cases hE : (⊥ : AddSubgroup G) ∈ S
· classical
obtain ⟨H, ⟨⟨c, hc, hlog, hup⟩, hent⟩, hMaxl⟩ :=
S.toFinite.exists_maximal_wrt id S (Set.nonempty_of_mem hE)
set ψ : G →+ G ⧸ H := QuotientAddGroup.mk' H
have surj : Function.Surjective ψ := QuotientAddGroup.mk'_surjective H
set G' := G ⧸ H
have : ElementaryAddCommGroup G' 2 := ElementaryAddCommGroup.quotient_group (by decide)
(by simp [AddSubgroup.zero_mem])
obtain ⟨H', hlog', hup'⟩ := app_ent_PFR _ _ _ _ α hent ((measurable_discrete _).comp hX)
((measurable_discrete _).comp hY)
have H_ne_bot: H' ≠ ⊥ := by
by_contra!
rcases this with rfl
have inj : Function.Injective (QuotientAddGroup.mk' (⊥ : AddSubgroup G')) :=
(QuotientAddGroup.quotientBot : (G' ⧸ ⊥) ≃+ G').symm.injective
rw [entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ inj,
entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ inj] at hup'
nlinarith [entropy_nonneg (ψ ∘ X) μ, entropy_nonneg (ψ ∘ Y) μ']
let H'' := H'.comap ψ
use H''
rw [← (AddSubgroup.map_comap_eq_self_of_surjective surj _ : H''.map ψ = H')] at hup' hlog'
set H' := H''.map ψ
have Hlt : H < H'' := by
have : H = (⊥ : AddSubgroup G').comap ψ := by
simp only [ψ, AddMonoidHom.comap_bot, QuotientAddGroup.ker_mk']
rw [this, AddSubgroup.comap_lt_comap_of_surjective surj]
exact Ne.bot_lt H_ne_bot
let φ : G' ⧸ H' ≃+ G ⧸ H'' := QuotientAddGroup.quotientQuotientEquivQuotient H H'' Hlt.le
set ψ' : G' →+ G' ⧸ H' := QuotientAddGroup.mk' H'
set ψ'' : G →+ G ⧸ H'' := QuotientAddGroup.mk' H''
have diag : ψ' ∘ ψ = φ.symm ∘ ψ'' := rfl
rw [← Function.comp.assoc, ← Function.comp.assoc, diag, Function.comp.assoc,
Function.comp.assoc] at hup'
have cond : log (Nat.card H'') ≤
(1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := by
have cardprod : Nat.card H'' = Nat.card H' * Nat.card H := by
have hcard₀ := Nat.card_congr <| (AddSubgroup.addSubgroupOfEquivOfLe Hlt.le).toEquiv
have hcard₁ := Nat.card_congr <|
(QuotientAddGroup.quotientKerEquivRange (ψ.restrict H'')).toEquiv
have hcard₂ := AddSubgroup.card_eq_card_quotient_mul_card_addSubgroup (H.addSubgroupOf H'')
rw [ψ.ker_restrict H'', QuotientAddGroup.ker_mk', ψ.restrict_range H''] at hcard₁
simpa only [← Nat.card_eq_fintype_card, hcard₀, hcard₁] using hcard₂
calc
log (Nat.card H'')
_ = log ((Nat.card H' : ℝ) * (Nat.card H : ℝ)) := by rw [cardprod]; norm_cast
_ = log (Nat.card H') + log (Nat.card H) := by
rw [Real.log_mul (Nat.cast_ne_zero.2 (@Nat.card_pos H').ne')
(Nat.cast_ne_zero.2 (@Nat.card_pos H).ne')]
_ ≤ (1 + α) / 2 * (H[⇑ψ ∘ X ; μ] + H[⇑ψ ∘ Y ; μ']) + log (Nat.card H) := by gcongr
_ ≤ (1 + α) / 2 * (c * (H[X; μ] + H[Y;μ'])) +
(1 + α) / (2 * (1 - α)) * (1 - c) * (H[X ; μ] + H[Y ; μ']) := by gcongr
_ = (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X ; μ] + H[Y ; μ']) := by
field_simp; ring
have HS : H'' ∉ S := λ Hs => Hlt.ne (hMaxl H'' Hs Hlt.le)
simp only [S, Set.mem_setOf_eq, not_and, not_lt] at HS
refine ⟨?_, HS ⟨α * c, by positivity, cond, ?_⟩⟩
· calc
log (Nat.card H'')
_ ≤ (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := cond
_ ≤ (1 + α) / (2 * (1 - α)) * 1 * (H[X; μ] + H[Y;μ']) := by gcongr; simp; positivity
_ = (1 + α) / (2 * (1 - α)) * (H[X; μ] + H[Y;μ']) := by simp only [mul_one]
· calc
H[ ψ'' ∘ X; μ ] + H[ ψ'' ∘ Y; μ' ]
_ = H[ φ.symm ∘ ψ'' ∘ X; μ ] + H[ φ.symm ∘ ψ'' ∘ Y; μ' ] := by
simp_rw [← entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ φ.symm.injective,
← entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ φ.symm.injective]
_ ≤ α * (H[ ψ ∘ X; μ ] + H[ ψ ∘ Y; μ' ]) := hup'.le
_ ≤ α * (c * (H[X ; μ] + H[Y ; μ'])) := by gcongr
_ = (α * c) * (H[X ; μ] + H[Y ; μ']) := by ring
· use ⊥
constructor
· simp only [AddSubgroup.mem_bot, Nat.card_eq_fintype_card, Fintype.card_ofSubsingleton,
Nat.cast_one, log_one]
positivity
· simp only [S, Set.mem_setOf_eq, not_and, not_lt] at hE
exact hE ⟨1, by norm_num, by
norm_num; exact add_le_add (entropy_comp_le μ hX _) (entropy_comp_le μ' hY _)⟩
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq 2 * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 34 * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
34 * d[(QuotientAddGroup.mk' H) ∘ X;μ # (QuotientAddGroup.mk' H) ∘ Y;μ'] := by
rcases PFR_projection' X Y μ μ' ((3 : ℝ) / 5) hX hY (by norm_num) (by norm_num) with ⟨H, h, h'⟩
refine ⟨H, ?_, ?_⟩
· convert h
norm_num
· have : 0 ≤ d[⇑(QuotientAddGroup.mk' H) ∘ X ; μ # ⇑(QuotientAddGroup.mk' H) ∘ Y ; μ'] :=
rdist_nonneg ((measurable_discrete _).comp hX) ((measurable_discrete _).comp hY)
linarith
end F2_projection
open MeasureTheory ProbabilityTheory Real Set
open scoped BigOperators
lemma four_logs {a b c d : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) (hd : 0 < d) :
log ((a*b)/(c*d)) = log a + log b - log c - log d := by
rw [log_div, log_mul, log_mul, sub_sub] <;> positivity
lemma sum_prob_preimage {G H : Type*} {X : Finset H} {A : Set G} [Finite A] {φ : A → X}
{A_ : H → Set G} (hA : A.Nonempty) (hφ : ∀ x : X, A_ x = Subtype.val '' (φ ⁻¹' {x})) :
∑ x in X, (Nat.card (A_ x) : ℝ) / (Nat.card A) = 1 := by
rw [← Finset.sum_div]
apply (div_eq_one_iff_eq <| Nat.cast_ne_zero.mpr <| Nat.pos_iff_ne_zero.mp (@Nat.card_pos _ hA.to_subtype _)).mpr
classical
haveI := Fintype.ofFinite A
rewrite [Nat.card_eq_fintype_card, ← Finset.card_univ, Finset.card_eq_sum_card_fiberwise
<| fun a _ ↦ Finset.mem_univ (φ a), ← Finset.sum_coe_sort]
norm_cast
congr; ext
rewrite [← Set.Finite.toFinset_setOf, (Set.toFinite _).card_toFinset, ← Nat.card_eq_fintype_card,
hφ, Nat.card_image_of_injective Subtype.val_injective]; rfl
/-- Let $\phi : G\to H$ be a homomorphism and $A,B\subseteq G$ be finite subsets. If $x,y\in H$ then let $A_x=A\cap \phi^{-1}(x)$ and $B_y=B\cap \phi^{-1}(y)$. There exist $x,y\in H$ such that $A_x,B_y$ are both non-empty and
\[d[\phi(U_A);\phi(U_B)]\log \frac{\lvert A\rvert\lvert B\rvert}{\lvert A_x\rvert\lvert B_y\rvert}\leq (\mathbb{H}(\phi(U_A))+\mathbb{H}(\phi(U_B)))(d(U_A,U_B)-d(U_{A_x},U_{B_y}).\] -/
lemma single_fibres {G H Ω Ω': Type u}
[AddCommGroup G] [Countable G] [MeasurableSpace G] [MeasurableSingletonClass G]
[AddCommGroup H] [Countable H] [MeasurableSpace H] [MeasurableSingletonClass H]
[MeasureSpace Ω] [MeasureSpace Ω']
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
(φ : G →+ H)
{A B : Set G} [Finite A] [Finite B] {UA : Ω → G} {UB: Ω' → G} (hA : A.Nonempty) (hB : B.Nonempty)
(hUA': Measurable UA) (hUB': Measurable UB) (hUA: IsUniform A UA) (hUB: IsUniform B UB)
(hUA_mem : ∀ ω, UA ω ∈ A) (hUB_mem : ∀ ω, UB ω ∈ B) :
∃ (x y : H) (Ax By: Set G),
Ax = A ∩ φ.toFun ⁻¹' {x} ∧ By = B ∩ φ.toFun ⁻¹' {y} ∧ Ax.Nonempty ∧ By.Nonempty ∧
d[φ.toFun ∘ UA # φ.toFun ∘ UB]
* log ((Nat.card A) * (Nat.card B) / ((Nat.card Ax) * (Nat.card By))) ≤
(H[φ.toFun ∘ UA] + H[φ.toFun ∘ UB]) * (d[UA # UB] - dᵤ[Ax # By]) := by
have : Nonempty A := hA.to_subtype
have : Nonempty B := hB.to_subtype
haveI : FiniteRange UA := finiteRange_of_finset UA A.toFinite.toFinset (by simpa)
haveI : FiniteRange UB := finiteRange_of_finset UB B.toFinite.toFinset (by simpa)
have hUA_coe : IsUniform A.toFinite.toFinset.toSet UA := by rwa [Set.Finite.coe_toFinset]
have hUB_coe : IsUniform B.toFinite.toFinset.toSet UB := by rwa [Set.Finite.coe_toFinset]
let A_ (x : H) : Set G := A ∩ φ.toFun ⁻¹' {x}
let B_ (y : H) : Set G := B ∩ φ.toFun ⁻¹' {y}
let X : Finset H := FiniteRange.toFinset (φ.toFun ∘ UA)
let Y : Finset H := FiniteRange.toFinset (φ.toFun ∘ UB)
haveI h_Ax (x : X) : Nonempty (A_ x.val) := by
obtain ⟨ω, hω⟩ := (FiniteRange.mem_iff _ _).mp x.property
use UA ω; exact Set.mem_inter (hUA_mem ω) (by exact hω)
haveI h_By (y : Y) : Nonempty (B_ y.val) := by
obtain ⟨ω, hω⟩ := (FiniteRange.mem_iff _ _).mp y.property
use UB ω; exact Set.mem_inter (hUB_mem ω) (by exact hω)
have h_AX (a : A) : φ.toFun a.val ∈ X := by
obtain ⟨ω, hω⟩ := hUA_coe.nonempty_preimage_of_mem hUA' (A.toFinite.mem_toFinset.mpr a.property)
exact (FiniteRange.mem_iff _ (φ.toFun a.val)).mpr ⟨ω, congr_arg _ hω⟩
have h_BY (b : B) : φ.toFun b.val ∈ Y := by
obtain ⟨ω, hω⟩ := hUB_coe.nonempty_preimage_of_mem hUB' (B.toFinite.mem_toFinset.mpr b.property)
exact (FiniteRange.mem_iff _ (φ.toFun b.val)).mpr ⟨ω, congr_arg _ hω⟩
let φ_AX (a : A) : X := by use φ.toFun a.val; exact h_AX a
let φ_BY (b : B) : Y := by use φ.toFun b.val; exact h_BY b
have h_φ_AX (x : X) : A_ x.val = φ_AX ⁻¹' {x} := by ext; simp [A_, φ_AX]; simp [Subtype.ext_iff]
have h_φ_BY (y : Y) : B_ y.val = φ_BY ⁻¹' {y} := by ext; simp [B_, φ_BY]; simp [Subtype.ext_iff]
let p (x : H) (y : H) : ℝ :=
(Nat.card (A_ x).Elem) * (Nat.card (B_ y).Elem) / ((Nat.card A.Elem) * (Nat.card B.Elem))
have :
∑ x in X, ∑ y in Y, (p x y) * dᵤ[A_ x # B_ y] ≤ d[UA # UB] - d[φ.toFun ∘ UA # φ.toFun ∘ UB] :=
calc
_ = d[UA | φ.toFun ∘ UA # UB | φ.toFun ∘ UB] := by
rewrite [condRuzsaDist_eq_sum hUA' ((measurable_discrete _).comp hUA')
hUB' ((measurable_discrete _).comp hUB')]
refine Finset.sum_congr rfl <| fun x hx ↦ Finset.sum_congr rfl <| fun y hy ↦ ?_
haveI : Nonempty (A_ x) := h_Ax ⟨x, hx⟩
haveI : Nonempty (B_ y) := h_By ⟨y, hy⟩
let μx := (ℙ : Measure Ω)[|(φ.toFun ∘ UA) ⁻¹' {x}]
let μy := (ℙ : Measure Ω')[|(φ.toFun ∘ UB) ⁻¹' {y}]
have h_μ_p : IsProbabilityMeasure μx ∧ IsProbabilityMeasure μy := by
constructor <;> apply ProbabilityTheory.cond_isProbabilityMeasure <;> rw [Set.preimage_comp]
refine @IsUniform.measure_preimage_ne_zero _ _ _ _ _ _ _ _ _ _ hUA_coe hUA' _ ?_
swap; refine @IsUniform.measure_preimage_ne_zero _ _ _ _ _ _ _ _ _ _ hUB_coe hUB' _ ?_
all_goals rwa [Set.inter_comm, Set.Finite.coe_toFinset]
have h_μ_unif : IsUniform (A_ x) UA μx ∧ IsUniform (B_ y) UB μy := by
have : _ ∧ _ := ⟨hUA.restrict hUA' (φ.toFun ⁻¹' {x}), hUB.restrict hUB' (φ.toFun ⁻¹' {y})⟩
rwa [Set.inter_comm _ A, Set.inter_comm _ B] at this
rewrite [rdist_set_eq_rdist h_μ_p.1 h_μ_p.2 h_μ_unif.1 h_μ_unif.2 hUA' hUB']
show _ = (Measure.real _ (UA ⁻¹' (_ ⁻¹' _))) * (Measure.real _ (UB ⁻¹' (_ ⁻¹' _))) * _
rewrite [hUA_coe.measureReal_preimage hUA', hUB_coe.measureReal_preimage hUB']
simp_rw [p, A_, B_, IsProbabilityMeasure.measureReal_univ, one_mul]
rewrite [mul_div_mul_comm, Set.inter_comm A, Set.inter_comm B]
simp only [Set.Finite.coe_toFinset, Set.Finite.mem_toFinset, Finset.mem_val]; rfl
_ ≤ d[UA # UB] - d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
rewrite [ZeroHom.toFun_eq_coe, AddMonoidHom.toZeroHom_coe]
linarith only [rdist_le_sum_fibre φ hUA' hUB' (μ := ℙ) (μ' := ℙ)]
let M := H[φ.toFun ∘ UA] + H[φ.toFun ∘ UB]
have hM : M = ∑ x in X, ∑ y in Y, Real.negMulLog (p x y) := by
have h_compl {x y} (h_notin : (x, y) ∉ X ×ˢ Y) : Real.negMulLog (p x y) = 0 := by
unfold_let p; beta_reduce
rewrite [Finset.mem_product, not_and_or] at h_notin
suffices A_ x = ∅ ∨ B_ y = ∅ by obtain h | h := this <;> rw [h] <;> simp
refine h_notin.imp ?_ ?_
· rw [← not_nonempty_iff_eq_empty]
rintro h ⟨a, ha, rfl⟩
exact h (h_AX ⟨a, ha⟩)
· rw [← not_nonempty_iff_eq_empty]
rintro h ⟨a, ha, rfl⟩
exact h (h_BY ⟨a, ha⟩)
unfold_let M
unfold entropy
haveI := isProbabilityMeasure_map (μ := ℙ) ((measurable_discrete φ).comp hUA').aemeasurable
haveI := isProbabilityMeasure_map (μ := ℙ) ((measurable_discrete φ).comp hUB').aemeasurable
rewrite [← Finset.sum_product', ← tsum_eq_sum fun _ ↦ h_compl, ← measureEntropy_prod]
apply tsum_congr; intro; congr
rewrite [← Set.singleton_prod_singleton, Measure.smul_apply, Measure.prod_prod,
Measure.map_apply ((measurable_discrete _).comp hUA') (MeasurableSet.singleton _),
Measure.map_apply ((measurable_discrete _).comp hUB') (MeasurableSet.singleton _),
Set.preimage_comp, hUA_coe.measure_preimage hUA',
Set.preimage_comp, hUB_coe.measure_preimage hUB']
simp [p, A_, B_, mul_div_mul_comm, Set.inter_comm, ENNReal.toReal_div]
have h_sum : ∑ x in X, ∑ y in Y,
(p x y) * (M * dᵤ[A_ x # B_ y] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p x y)) ≤
M * d[UA # UB] :=
calc
_ = ∑ x in X, ∑ y in Y, (p x y) * M * dᵤ[A_ x # B_ y] + M * d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
simp_rw [hM, Finset.sum_mul, ← Finset.sum_add_distrib]
refine Finset.sum_congr rfl <| fun _ _ ↦ Finset.sum_congr rfl <| fun _ _ ↦ ?_
simp only [negMulLog, left_distrib, mul_assoc, Finset.sum_mul]
exact congrArg (HAdd.hAdd _) (by group)
_ = M * ∑ x in X, ∑ y in Y, (p x y) * dᵤ[A_ x # B_ y] + M * d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
simp_rw [Finset.mul_sum]
congr; ext; congr; ext; group
_ ≤ M * d[UA # UB] := by
rewrite [← left_distrib]
apply mul_le_mul_of_nonneg_left
· linarith
· unfold_let M
linarith only [entropy_nonneg (φ.toFun ∘ UA) ℙ, entropy_nonneg (φ.toFun ∘ UB) ℙ]
have : ∃ x : X, ∃ y : Y,
M * dᵤ[A_ x.val # B_ y.val] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p x.val y.val) ≤
M * d[UA # UB] := by
let f (xy : H × H) := (p xy.1 xy.2) * (M * d[UA # UB])
let g (xy : H × H) := (p xy.1 xy.2) *
(M * dᵤ[A_ xy.1 # B_ xy.2] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p xy.1 xy.2))
by_contra hc; push_neg at hc
replace hc : ∀ xy ∈ X ×ˢ Y, f xy < g xy := by
refine fun xy h ↦ mul_lt_mul_of_pos_left ?_ ?_
· exact hc ⟨xy.1, (Finset.mem_product.mp h).1⟩ ⟨xy.2, (Finset.mem_product.mp h).2⟩
· haveI : Nonempty _ := h_Ax ⟨xy.1, (Finset.mem_product.mp h).1⟩
haveI : Nonempty _ := h_By ⟨xy.2, (Finset.mem_product.mp h).2⟩
simp only [p, div_pos, mul_pos, Nat.cast_pos, Nat.card_pos]
have h_nonempty : Finset.Nonempty (X ×ˢ Y) := by
use ⟨φ.toFun <| UA <| Classical.choice <| ProbabilityMeasure.nonempty ⟨ℙ, inferInstance⟩,
φ.toFun <| UB <| Classical.choice <| ProbabilityMeasure.nonempty ⟨ℙ, inferInstance⟩⟩
exact Finset.mem_product.mpr ⟨FiniteRange.mem _ _, FiniteRange.mem _ _⟩
replace hc := Finset.sum_lt_sum_of_nonempty h_nonempty hc
have h_p_one : ∑ x in X ×ˢ Y, p x.1 x.2 = 1 := by
simp_rw [Finset.sum_product, p, mul_div_mul_comm, ← Finset.mul_sum,
← sum_prob_preimage hA h_φ_AX, sum_prob_preimage hB h_φ_BY, mul_one]
rewrite [← Finset.sum_mul, h_p_one, one_mul, Finset.sum_product] at hc
exact not_le_of_gt hc h_sum
obtain ⟨x, y, hxy⟩ := this
refine ⟨x, y, A_ x.val, B_ y.val, rfl, rfl, @nonempty_of_nonempty_subtype _ _ (h_Ax x), @nonempty_of_nonempty_subtype _ _ (h_By y), ?_⟩
rewrite [← inv_div, Real.log_inv]
show _ * -log (p x.val y.val) ≤ M * _
linarith only [hxy]
section dim
open Classical
variable {G : Type*} [AddCommGroup G]
/- If G ≅ ℤᵈ then there is a subgroup H of G such that A lies in a coset of H. This is helpful to
give the equivalent definition of `dimension`. Here this is stated in greated generality since the
proof carries over automatically-/
lemma exists_coset_cover (A : Set G) :
∃ (d : ℕ), ∃ (S : Submodule ℤ G) (v : G),
FiniteDimensional.finrank ℤ S = d ∧ ∀ a ∈ A, a - v ∈ S := by
existsi FiniteDimensional.finrank ℤ (⊤ : Submodule ℤ G), ⊤, 0
refine ⟨rfl, fun a _ ↦ trivial⟩
/-- The dimension of the affine span over `ℤ` of a subset of an additive group. -/
noncomputable def dimension (A : Set G) : ℕ := Nat.find (exists_coset_cover A)
lemma dimension_le_of_coset_cover (A : Set G) (S : Submodule ℤ G) (v : G)
(hA : ∀ a ∈ A, a - v ∈ S) : dimension A ≤ FiniteDimensional.finrank ℤ S := by
apply Nat.find_le
existsi S , v
exact ⟨rfl, hA⟩
lemma dimension_le_rank [Module.Finite ℤ G] (A : Set G) :
dimension A ≤ FiniteDimensional.finrank ℤ G := by
obtain ⟨S, v, hs, _⟩ := Nat.find_spec (exists_coset_cover A)
rw [dimension, ←hs]
apply Submodule.finrank_le S
end dim
variable {G : Type u} [AddCommGroup G] [Module.Free ℤ G] [Module.Finite ℤ G] [Countable G] [MeasurableSpace G] [MeasurableSingletonClass G]
open Real MeasureTheory ProbabilityTheory Pointwise Set
/-- Move to Mathlib? `Finsupp.mapRange` of a surjective function is surjective. -/
lemma Finsupp.mapRange_surjective {α : Type u_1} {M : Type u_5} {N : Type u_7} [Zero M] [Zero N] (f : M → N) (hf : f 0 = 0)
(hs : Function.Surjective f) : Function.Surjective (Finsupp.mapRange (α := α) f hf) := by
classical
let g (n : N) : M := if n = 0 then 0 else Function.surjInv hs n
have : Function.RightInverse g f := by
intro n
by_cases h : n = 0
. simp [g, h, hf]
· simp [g, h, Function.surjInv_eq hs n]
have hg : g 0 = 0 := by simp [g]
have hfg : (f ∘ g) 0 = 0 := by simp [hf, hg]
intro F
use Finsupp.mapRange g hg F
rw [← Finsupp.mapRange_comp (h := hfg)]
convert Finsupp.mapRange_id F
convert Function.RightInverse.id this
/-- A free Z-module is torsion-free. Move to Mathlib? -/
lemma torsion_free : AddMonoid.IsTorsionFree G := by
rintro x hx hn
rw [isOfFinAddOrder_iff_nsmul_eq_zero] at hn
rcases hn with ⟨ n, hn, hn' ⟩
apply_fun Module.Free.repr ℤ G at hn'
simp_rw [map_nsmul, map_zero, smul_eq_zero, AddEquivClass.map_eq_zero_iff, hx, or_false] at hn'
linarith
/-- If G is a rank n free Z-module, then G/2G is a finite elementary 2-group of cardinality 2^n. Code is slow, needs to be golfed -/
| lemma weak_PFR_quotient_prelim :
let H := G ⧸ (AddMonoidHom.range (zsmulAddGroupHom 2))
ElementaryAddCommGroup H 2 ∧ Finite H ∧ Nat.card H = 2^(FiniteDimensional.finrank ℤ G) | weak_PFR_quotient_prelim | 25309ad 20231211 | f025369 20231228 | pfr/PFR/WeakPFR.lean | {
"lineInFile": 650,
"tokenPositionInFile": 35818,
"theoremPositionInFile": 21
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n set ψ : G →+ G := zsmulAddGroupHom 2\n set G₂ := AddMonoidHom.range ψ\n set H := G ⧸ G₂\n set φ : G →+ H := QuotientAddGroup.mk' G₂\n have hH_elem : ElementaryAddCommGroup H 2 := by\n apply ElementaryAddCommGroup.quotient_group (by decide)\n intro x; rw [AddMonoidHom.mem_range]\n use x\n rw [zsmulAddGroupHom_apply]\n norm_cast\n let B := Module.Free.ChooseBasisIndex ℤ G\n let bG : Basis B ℤ G := Module.Free.chooseBasis ℤ G\n have hB_fin : Fintype B := by infer_instance\n have hB_card : Nat.card B = FiniteDimensional.finrank ℤ G := by\n rw [FiniteDimensional.finrank_eq_card_basis bG, Nat.card_eq_fintype_card]\n have hH_module : Module (ZMod 2) H := by infer_instance\n let mod : (B →₀ ℤ) →+ (B →₀ ZMod 2) := Finsupp.mapRange.addMonoidHom (Int.castAddHom (ZMod 2))\n let f : G →+ (B →₀ ℤ) := bG.repr\n have hker : G₂ ≤ AddMonoidHom.ker (AddMonoidHom.comp mod f) := by\n intro x hx\n simp only [AddMonoidHom.mem_range, G₂, ψ, zsmulAddGroupHom_apply] at hx\n simp_rw [AddMonoidHom.mem_ker, AddMonoidHom.coe_comp, Function.comp_apply, mod,\n Finsupp.mapRange.addMonoidHom_apply, Int.coe_castAddHom]\n rcases hx with ⟨y, rfl⟩\n ext b\n simp_rw [map_zsmul, Finsupp.mapRange_apply, Finsupp.coe_smul, Pi.smul_apply, smul_eq_mul,\n Int.cast_mul, Int.cast_ofNat, Finsupp.coe_zero, Pi.zero_apply, mul_eq_zero]\n left\n exact ZMod.nat_cast_self 2\n let g : H →+ (B →₀ ZMod 2) := QuotientAddGroup.lift G₂ (AddMonoidHom.comp mod f) hker\n have hsur : Function.Surjective g := by\n have h1 : Function.Surjective mod := Finsupp.mapRange_surjective (Int.castAddHom (ZMod 2)) (map_zero _) ZMod.int_cast_surjective\n have h2 := h1.comp bG.repr.surjective\n have h3 : mod ∘ bG.repr = g ∘ (QuotientAddGroup.mk' G₂) := by\n ext x b\n simp_rw [mod, Function.comp_apply, Finsupp.mapRange.addMonoidHom_apply, Int.coe_castAddHom,\n Finsupp.mapRange_apply, QuotientAddGroup.coe_mk', g]\n rw [QuotientAddGroup.lift_mk]\n simp [mod, f]\n rw [h3] at h2\n apply Function.Surjective.of_comp h2\n have hinj : Function.Injective g := by\n rw [injective_iff_map_eq_zero]\n intro x hx\n rcases QuotientAddGroup.mk'_surjective G₂ x with ⟨y, rfl⟩\n simp only [QuotientAddGroup.mk'_apply, g] at hx\n rw [QuotientAddGroup.lift_mk] at hx\n simp_rw [AddMonoidHom.coe_comp, Function.comp_apply, mod, Finsupp.mapRange.addMonoidHom_apply,\n Int.coe_castAddHom, DFunLike.ext_iff,Finsupp.mapRange_apply, Finsupp.coe_zero, Pi.zero_apply,\n ZMod.int_cast_zmod_eq_zero_iff_dvd] at hx\n replace hx := fun x ↦ Int.mul_ediv_cancel' (hx x)\n let z (b : B) := ((Module.Free.chooseBasis ℤ G).repr y) b / 2\n let z' := (Finsupp.equivFunOnFinite).symm z\n change ∀ b : B, 2 * z' b = (f y) b at hx\n let x' := bG.repr.symm z'\n rw [QuotientAddGroup.mk'_apply, QuotientAddGroup.eq_zero_iff, AddMonoidHom.mem_range]\n simp_rw [ψ, zsmulAddGroupHom_apply]\n use x'\n change 2 • (bG.repr.symm.toLinearMap.toAddMonoidHom z') = y\n rw [← AddMonoidHom.map_zsmul bG.repr.symm.toLinearMap.toAddMonoidHom z' (2 : ℤ)]\n rw [← LinearEquiv.symm_apply_apply bG.repr y]\n change bG.repr.symm (2 • z') = bG.repr.symm (f y)\n congr\n ext b\n rw [Finsupp.smul_apply, ← hx b, smul_eq_mul]\n rcases Function.bijective_iff_has_inverse.mp ⟨ hinj, hsur ⟩ with ⟨ g', hg' ⟩\n\n have bH : Basis B (ZMod 2) H := by\n constructor\n exact {\n toFun := g\n invFun := g'\n left_inv := hg'.1\n right_inv := hg'.2\n map_add' := AddMonoidHom.map_add _\n map_smul' := by\n intro r x\n rcases ZMod.int_cast_surjective r with ⟨ n, rfl ⟩\n change g ((n : ZMod 2) • x) = (n : ZMod 2) • g x\n rw [intCast_smul, intCast_smul]\n exact AddMonoidHom.map_zsmul g x n\n }\n have hH_fin : Fintype H := Module.fintypeOfFintype bH\n have hH_card : Nat.card H = 2^(FiniteDimensional.finrank ℤ G) := by\n rw [Nat.card_eq_fintype_card, Module.card_fintype bH, ← Nat.card_eq_fintype_card (α := B), hB_card]\n congr\n exact ⟨ hH_elem, Finite.of_fintype H, hH_card ⟩",
"proofType": "tactic",
"proofLengthLines": 88,
"proofLengthTokens": 4044
} | pfr |
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Quotient
import Mathlib.GroupTheory.Torsion
import Mathlib.GroupTheory.Torsion
import Mathlib.LinearAlgebra.FreeModule.PID
import PFR.Mathlib.Data.Set.Pointwise.SMul
import PFR.EntropyPFR
import PFR.ImprovedPFR
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Mathlib.GroupTheory.Torsion
/-!
# Weak PFR over the integers
Here we use the entropic form of PFR to deduce a weak form of PFR over the integers.
## Main statement
* `weak_PFR_int`: Let $A\subseteq \mathbb{Z}^d$ and $\lvert A+A\rvert\leq K\lvert A\rvert$.
There exists $A'\subseteq A$ such that $\lvert A'\rvert \geq K^{-17}\lvert A\rvert$ and
$\dim A' \leq (40/\log 2)\log K$.
-/
section AddCommGroup
variable {G : Type*} [AddCommGroup G] {A B : Set G}
open Set
open scoped Pointwise
def IsShift (A B : Set G) : Prop := ∃ x : G, A = x +ᵥ B
lemma IsShift.sub_self_congr : IsShift A B → A - A = B - B := by
rintro ⟨x, rfl⟩; simp [vadd_sub_vadd_comm, singleton_zero]
lemma IsShift.card_congr : IsShift A B → Nat.card A = Nat.card B := by rintro ⟨x, rfl⟩; simp
/-- The property of two sets A, B of a group G not being contained in cosets of the same proper
subgroup -/
def NotInCoset (A B : Set G) : Prop := AddSubgroup.closure ((A - A) ∪ (B - B)) = ⊤
/-- Without loss of generality, one can move (up to translation and embedding) any pair A, B of non-empty sets into a subgroup where they are not in a coset. -/
lemma wlog_notInCoset (hA : A.Nonempty) (hB : B.Nonempty) :
∃ (G' : AddSubgroup G) (A' B' : Set G'), IsShift A A' ∧ IsShift B B' ∧ NotInCoset A' B' := by
obtain ⟨x, hx⟩ := hA
obtain ⟨y, hy⟩ := hB
set G' := AddSubgroup.closure ((A - A) ∪ (B - B))
set A' : Set G' := (↑) ⁻¹' ((-x) +ᵥ A)
set B' : Set G' := (↑) ⁻¹' ((-y) +ᵥ B)
have hxA : -x +ᵥ A ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hx).trans $ (subset_union_left ..).trans
AddSubgroup.subset_closure
have hyB : -y +ᵥ B ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hy).trans $ (subset_union_right ..).trans
AddSubgroup.subset_closure
have hA : IsShift A A' := ⟨x, by rw [Set.image_preimage_eq_of_subset hxA, vadd_neg_vadd]⟩
have hB : IsShift B B' := ⟨y, by rw [Set.image_preimage_eq_of_subset hyB, vadd_neg_vadd]⟩
refine ⟨G', A', B', hA, hB, ?_⟩
unfold NotInCoset
convert AddSubgroup.closure_preimage_eq_top ((A - A) ∪ (B - B))
simp_rw [preimage_union, hA.sub_self_congr, hB.sub_self_congr]
rw [preimage_sub, preimage_sub]
simp [A', B', preimage_image_preimage]
all_goals apply_rules [Subtype.coe_injective, (image_preimage_subset ..).trans, hxA, hyB]
end AddCommGroup
section Torsion
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [MeasurableSpace G] [MeasurableSingletonClass G]
[Countable G] {Ω Ω' : Type u} [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ': Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
/-- If $G$ is torsion-free and $X,Y$ are $G$-valued random variables then $d[X;2Y]\leq 5d[X;Y]$. -/
lemma torsion_free_doubling [FiniteRange X] [FiniteRange Y]
(hX : Measurable X) (hY : Measurable Y) (hG : AddMonoid.IsTorsionFree G) :
d[X ; μ # (Y + Y) ; μ'] ≤ 5 * d[X; μ # Y ; μ'] := by
obtain ⟨A, mA, μA, X', Y'₁, Y'₂, hμA, h_indep, hX'_meas, hY'₁_meas, hY'₂_meas, hX'_ident,
hY'₁_ident, hY'₂_ident, _, _, _⟩ := independent_copies3_nondep_finiteRange hX hY hY μ μ' μ'
have h_meas (i : Fin 3) : Measurable (![X', Y'₁, Y'₂] i) := by fin_cases i <;> assumption
haveI : NoZeroSMulDivisors ℕ G := hG.noZeroNsmulDivisors
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨x, y₁, y₂⟩ ↦ (x, y₁ - y₂, x - 2 • y₁)
show H[f ∘ ⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] = _
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hX'_meas <| Measurable.prod hY'₁_meas hY'₂_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun X' (prod Y'₁ Y'₂) μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 1 2 0 (by decide) (by decide)
rw [this.entropy_pair_eq_add hX'_meas (by exact Measurable.prod hY'₁_meas hY'₂_meas),
IndepFun.entropy_pair_eq_add hY'₁_meas hY'₂_meas (h_indep.indepFun (show 1 ≠ 2 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, two_mul]
have : H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[X ; μ] + H[Y ; μ'] := calc
H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[⟨X', Y'₁⟩ ; μA] := by
let f : G × G → G × G := fun ⟨x, y₁⟩ ↦ (x, x - 2 • y₁)
show H[f ∘ ⟨X', Y'₁⟩ ; μA] = _
apply entropy_comp_of_injective μA (by exact Measurable.prod hX'_meas hY'₁_meas) f
exact fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + H[Y ; μ'] := by
rw [IndepFun.entropy_pair_eq_add hX'_meas hY'₁_meas (h_indep.indepFun (show 0 ≠ 1 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq]
let f : G × G → G × G := fun ⟨x, y⟩ ↦ (x, y - x)
have hf : f.Injective := fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all
have : H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] := calc
H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] = H[f ∘ ⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
show _ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂ - (Y'₁ - Y'₂)⟩ ; μA]
rw [sub_sub_sub_cancel_right, ← sub_add_eq_sub_sub, two_nsmul]
_ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
refine entropy_comp_of_injective μA (Measurable.prod ?_ ?_) f hf
· exact Measurable.sub hY'₁_meas hY'₂_meas
· exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
_ ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] :=
entropy_pair_le_add (hY'₁_meas.sub' hY'₂_meas) (hX'_meas.sub' hY'₁_meas |>.sub' hY'₂_meas) μA
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] + H[X' - 2 • Y'₁ ; μA] ≤
H[⟨X', X' - 2 • Y'₁⟩ ; μA] + H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] := by
haveI : FiniteRange (Y'₁ - Y'₂) := FiniteRange.sub Y'₁ Y'₂
haveI : FiniteRange (2 • Y'₁) := by show FiniteRange ((fun x ↦ 2 • x) ∘ Y'₁); infer_instance
apply entropy_triple_add_entropy_le μA hX'_meas (Measurable.sub hY'₁_meas hY'₂_meas)
exact Measurable.sub' hX'_meas <| Measurable.const_smul hY'₁_meas 2
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨y₁, y₂, x⟩ ↦ (y₁, y₂, x - y₁ - y₂)
show H[f ∘ ⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA]
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hY'₁_meas <| Measurable.prod hY'₂_meas hX'_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun Y'₁ (prod Y'₂ X') μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 2 0 1 (by decide) (by decide)
rw [this.entropy_pair_eq_add hY'₁_meas (by exact Measurable.prod hY'₂_meas hX'_meas),
IndepFun.entropy_pair_eq_add hY'₂_meas hX'_meas (h_indep.indepFun (show 2 ≠ 0 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq]
group
have : H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₂ ; μA] := calc
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₁, X' - Y'₂⟩ ; μA] := by rw [sub_right_comm] ; rfl
_ = H[⟨Y'₁, X' - Y'₂⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₁_meas <| Measurable.sub hX'_meas hY'₂_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₂ ; μA] := by
haveI : FiniteRange (X' - Y'₂) := FiniteRange.sub X' Y'₂
convert IndepFun.entropy_pair_eq_add hY'₁_meas (hX'_meas.sub hY'₂_meas)
<| h_indep.indepFun_sub_right h_meas 1 0 2 (by decide) (by decide)
exact hY'₁_ident.entropy_eq.symm
have : H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₁ ; μA] := calc
H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₂, X' - Y'₁⟩ ; μA] := rfl
_ = H[⟨Y'₂, X' - Y'₁⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₂_meas <| Measurable.sub hX'_meas hY'₁_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₁ ; μA] := by
haveI : FiniteRange (X' - Y'₁) := FiniteRange.sub X' Y'₁
convert IndepFun.entropy_pair_eq_add hY'₂_meas (hX'_meas.sub hY'₁_meas)
<| h_indep.indepFun_sub_right h_meas 2 0 1 (by decide) (by decide)
exact hY'₂_ident.entropy_eq.symm
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] ≤
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] + H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
apply entropy_triple_add_entropy_le μA hY'₁_meas hY'₂_meas
exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
have : H[X' - Y'₁ - Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := calc
H[X' - Y'₁ - Y'₂ ; μA] ≤ H[X' - Y'₁ ; μA] + H[X' - Y'₂ ; μA] - H[X ; μ] := by linarith
_ = 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := by
nth_rw 1 [two_mul, ← hX'_ident.rdist_eq hY'₁_ident, ← hX'_ident.rdist_eq hY'₂_ident]
have h1 : d[X' ; μA # Y'₁ ; μA] = H[X' - Y'₁ ; μA] - H[X' ; μA] / 2 - H[Y'₁ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 1 by decide)).rdist_eq hX'_meas hY'₁_meas
have h2 : d[X' ; μA # Y'₂ ; μA] = H[X' - Y'₂ ; μA] - H[X' ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 2 by decide)).rdist_eq hX'_meas hY'₂_meas
rw [h1, h2, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, hX'_ident.entropy_eq]
group
have : d[X ; μ # 2 • Y ; μ'] ≤
d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := calc
d[X ; μ # 2 • Y ; μ'] = H[X' - 2 • Y'₁ ; μA] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by
have h2Y_ident : IdentDistrib (2 • Y'₁) (2 • Y) (μ := μA) (ν := μ') := by
convert hY'₁_ident.comp <| measurable_discrete <| fun g ↦ 2 • g
have h2Y_indep : IndepFun X' (2 • Y'₁) (μ := μA) := by
convert (h_indep.indepFun (show 0 ≠ 1 by decide)).comp measurable_id
(measurable_const_smul 2)
rw [← hX'_ident.rdist_eq h2Y_ident,
h2Y_indep.rdist_eq hX'_meas <| Measurable.const_smul hY'₁_meas 2,
hX'_ident.entropy_eq, h2Y_ident.entropy_eq]
_ ≤ H[Y'₁ - Y'₂ ; μA] + 2 * d[X ; μ # Y ; μ'] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by linarith
_ = d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := by
have H2Y : H[2 • Y ; μ'] = H[Y ; μ'] := by
let f (g : G) := 2 • g
exact entropy_comp_of_injective μ' hY f (fun _ _ ↦ by simp [f, smul_right_inj])
have : d[Y'₁ ; μA # Y'₂ ; μA] = H[Y'₁ - Y'₂ ; μA] - H[Y'₁ ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 1 ≠ 2 by decide)).rdist_eq hY'₁_meas hY'₂_meas
rw [this, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, H2Y]
group
have : d[Y'₁ ; μA # Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] := by
rw [two_mul]
convert rdist_triangle hY'₁_meas hX'_meas hY'₂_meas (μ := μA) (μ' := μA) (μ'' := μA)
· exact rdist_symm.trans (hY'₁_ident.rdist_eq hX'_ident).symm
· exact (hX'_ident.rdist_eq hY'₂_ident).symm
rw [← two_nsmul]
linarith [abs_le.mp <| diff_ent_le_rdist hX hY (μ := μ) (μ' := μ')]
/-- If $G$ is a torsion-free group and $X,Y$ are $G$-valued random variables and
$\phi : G\to \mathbb{F}_2^d$ is a homomorphism then
\[\mathbb{H}(\phi(X))\leq 10d[X;Y].\] -/
lemma torsion_dist_shrinking {H : Type u} [FiniteRange X] [FiniteRange Y] (hX : Measurable X)
(hY : Measurable Y) [AddCommGroup H] [ElementaryAddCommGroup H 2]
[MeasurableSpace H] [MeasurableSingletonClass H] [Countable H]
(hG : AddMonoid.IsTorsionFree G) (φ : G →+ H) :
H[φ ∘ X ; μ] ≤ 10 * d[X; μ # Y ; μ'] := by
have :=
calc d[φ ∘ X ; μ # φ ∘ (Y + Y); μ'] ≤ d[X; μ # (Y + Y) ; μ'] := rdist_of_hom_le φ hX (Measurable.add hY hY)
_ ≤ 5 * d[X; μ # Y ; μ'] := torsion_free_doubling X Y μ μ' hX hY hG
have eq_zero : φ ∘ (Y + Y) = fun _ ↦ 0 := by ext x ; simp only [Function.comp_apply, Pi.add_apply,
map_add, ElementaryAddCommGroup.add_self]
rwa [eq_zero, rdist_zero_eq_half_ent, div_le_iff zero_lt_two, mul_assoc, mul_comm _ 2, ←mul_assoc,
show (5*2 : ℝ) = 10 by norm_num] at this
end Torsion
instance {G : Type u} [AddCommGroup G] [Fintype G] [MeasurableSpace G] [MeasurableSingletonClass G] (H : AddSubgroup G)
: MeasurableSingletonClass (G ⧸ H) :=
⟨λ _ ↦ by { rw [measurableSet_quotient]; simp [measurableSet_discrete] }⟩
section F2_projection
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [ElementaryAddCommGroup G 2] [Fintype G] [MeasurableSpace G]
[MeasurableSingletonClass G] {Ω Ω' : Type*}
/-- Let $G=\mathbb{F}_2^n$ and $X,Y$ be $G$-valued random variables such that
\[\mathbb{H}(X)+\mathbb{H}(Y)> (20/\alpha) d[X;Y],\]
for some $\alpha > 0$.
There is a non-trivial subgroup $H\leq G$ such that
\[\log \lvert H\rvert <(1+\alpha)/2 (\mathbb{H}(X)+\mathbb{H}(Y))\] and
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))< \alpha (\mathbb{H}(X)+\mathbb{H}(Y))\]
where $\psi:G\to G/H$ is the natural projection homomorphism.
-/
lemma app_ent_PFR' [MeasureSpace Ω] [MeasureSpace Ω'] (X : Ω → G) (Y : Ω' → G)
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
{α : ℝ} (hent : 20 * d[X # Y] < α * (H[X] + H[Y])) (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X] + H[Y]) ∧
H[(QuotientAddGroup.mk' H) ∘ X] + H[(QuotientAddGroup.mk' H) ∘ Y] < α * (H[X] + H[Y]) := by
let p : refPackage Ω Ω' G := {
X₀₁ := X
X₀₂ := Y
hmeas1 := hX
hmeas2 := hY
η := 1/8
hη := by norm_num
hη' := by norm_num }
obtain ⟨H, Ω'', hΩ'', U, _, hUmeas, hUunif, ineq⟩ := entropic_PFR_conjecture_improv p rfl
let ψ := (QuotientAddGroup.mk' H)
use H
haveI : Finite H := Subtype.finite
-- Note that H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y]
have ent_le : H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y] := calc
H[ψ ∘ X] + H[ψ ∘ Y] ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· exact ent_of_proj_le hX hUmeas hUunif
· exact ent_of_proj_le hY hUmeas hUunif
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- Note that (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y]
have log_sub_le : (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y] := calc
(log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) =
(H[U] - H[X]) + (H[U] - H[Y]) := by
rw [IsUniform.entropy_eq' hUunif hUmeas, SetLike.coe_sort_coe]
_ ≤ |(H[U] - H[X])| + |(H[U] - H[Y])| := by gcongr <;> exact le_abs_self _
_ ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hX
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hY
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- then the conclusion follows from the assumption `hent` and basic inequality manipulations
exact ⟨by linarith, by linarith⟩
variable [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ' : Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
lemma app_ent_PFR (α : ℝ) (hent: 20 * d[X;μ # Y;μ'] < α * (H[X; μ] + H[Y; μ'])) (hX : Measurable X)
(hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ']
< α * (H[ X; μ] + H[Y; μ']) :=
@app_ent_PFR' _ _ _ _ _ _ _ _ (MeasureSpace.mk μ) (MeasureSpace.mk μ') _ _ _ _ α hent hX hY
set_option maxHeartbeats 300000 in
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables and $\alpha < 1$ then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq (1 + α) / (2 * (1 - α)) * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 20/\alpha * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection'
(α : ℝ) (hX : Measurable X) (hY : Measurable Y) (αpos : 0 < α) (αone : α < 1) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (H[X ; μ] + H[Y ; μ']) ∧
α * (H[(QuotientAddGroup.mk' H) ∘ X ; μ] + H[(QuotientAddGroup.mk' H) ∘ Y ; μ']) ≤
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] := by
let S := { H : AddSubgroup G | (∃ (c : ℝ), 0 ≤ c ∧
log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (1 - c) * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
c * (H[X; μ] + H[Y;μ'])) ∧
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] <
α * (H[ (QuotientAddGroup.mk' H) ∘ X; μ ] + H[ (QuotientAddGroup.mk' H) ∘ Y; μ']) }
have : 0 ≤ H[X ; μ] + H[Y ; μ'] := by linarith [entropy_nonneg X μ, entropy_nonneg Y μ']
have : 0 < 1 - α := sub_pos.mpr αone
by_cases hE : (⊥ : AddSubgroup G) ∈ S
· classical
obtain ⟨H, ⟨⟨c, hc, hlog, hup⟩, hent⟩, hMaxl⟩ :=
S.toFinite.exists_maximal_wrt id S (Set.nonempty_of_mem hE)
set ψ : G →+ G ⧸ H := QuotientAddGroup.mk' H
have surj : Function.Surjective ψ := QuotientAddGroup.mk'_surjective H
set G' := G ⧸ H
have : ElementaryAddCommGroup G' 2 := ElementaryAddCommGroup.quotient_group (by decide)
(by simp [AddSubgroup.zero_mem])
obtain ⟨H', hlog', hup'⟩ := app_ent_PFR _ _ _ _ α hent ((measurable_discrete _).comp hX)
((measurable_discrete _).comp hY)
have H_ne_bot: H' ≠ ⊥ := by
by_contra!
rcases this with rfl
have inj : Function.Injective (QuotientAddGroup.mk' (⊥ : AddSubgroup G')) :=
(QuotientAddGroup.quotientBot : (G' ⧸ ⊥) ≃+ G').symm.injective
rw [entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ inj,
entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ inj] at hup'
nlinarith [entropy_nonneg (ψ ∘ X) μ, entropy_nonneg (ψ ∘ Y) μ']
let H'' := H'.comap ψ
use H''
rw [← (AddSubgroup.map_comap_eq_self_of_surjective surj _ : H''.map ψ = H')] at hup' hlog'
set H' := H''.map ψ
have Hlt : H < H'' := by
have : H = (⊥ : AddSubgroup G').comap ψ := by
simp only [ψ, AddMonoidHom.comap_bot, QuotientAddGroup.ker_mk']
rw [this, AddSubgroup.comap_lt_comap_of_surjective surj]
exact Ne.bot_lt H_ne_bot
let φ : G' ⧸ H' ≃+ G ⧸ H'' := QuotientAddGroup.quotientQuotientEquivQuotient H H'' Hlt.le
set ψ' : G' →+ G' ⧸ H' := QuotientAddGroup.mk' H'
set ψ'' : G →+ G ⧸ H'' := QuotientAddGroup.mk' H''
have diag : ψ' ∘ ψ = φ.symm ∘ ψ'' := rfl
rw [← Function.comp.assoc, ← Function.comp.assoc, diag, Function.comp.assoc,
Function.comp.assoc] at hup'
have cond : log (Nat.card H'') ≤
(1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := by
have cardprod : Nat.card H'' = Nat.card H' * Nat.card H := by
have hcard₀ := Nat.card_congr <| (AddSubgroup.addSubgroupOfEquivOfLe Hlt.le).toEquiv
have hcard₁ := Nat.card_congr <|
(QuotientAddGroup.quotientKerEquivRange (ψ.restrict H'')).toEquiv
have hcard₂ := AddSubgroup.card_eq_card_quotient_mul_card_addSubgroup (H.addSubgroupOf H'')
rw [ψ.ker_restrict H'', QuotientAddGroup.ker_mk', ψ.restrict_range H''] at hcard₁
simpa only [← Nat.card_eq_fintype_card, hcard₀, hcard₁] using hcard₂
calc
log (Nat.card H'')
_ = log ((Nat.card H' : ℝ) * (Nat.card H : ℝ)) := by rw [cardprod]; norm_cast
_ = log (Nat.card H') + log (Nat.card H) := by
rw [Real.log_mul (Nat.cast_ne_zero.2 (@Nat.card_pos H').ne')
(Nat.cast_ne_zero.2 (@Nat.card_pos H).ne')]
_ ≤ (1 + α) / 2 * (H[⇑ψ ∘ X ; μ] + H[⇑ψ ∘ Y ; μ']) + log (Nat.card H) := by gcongr
_ ≤ (1 + α) / 2 * (c * (H[X; μ] + H[Y;μ'])) +
(1 + α) / (2 * (1 - α)) * (1 - c) * (H[X ; μ] + H[Y ; μ']) := by gcongr
_ = (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X ; μ] + H[Y ; μ']) := by
field_simp; ring
have HS : H'' ∉ S := λ Hs => Hlt.ne (hMaxl H'' Hs Hlt.le)
simp only [S, Set.mem_setOf_eq, not_and, not_lt] at HS
refine ⟨?_, HS ⟨α * c, by positivity, cond, ?_⟩⟩
· calc
log (Nat.card H'')
_ ≤ (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := cond
_ ≤ (1 + α) / (2 * (1 - α)) * 1 * (H[X; μ] + H[Y;μ']) := by gcongr; simp; positivity
_ = (1 + α) / (2 * (1 - α)) * (H[X; μ] + H[Y;μ']) := by simp only [mul_one]
· calc
H[ ψ'' ∘ X; μ ] + H[ ψ'' ∘ Y; μ' ]
_ = H[ φ.symm ∘ ψ'' ∘ X; μ ] + H[ φ.symm ∘ ψ'' ∘ Y; μ' ] := by
simp_rw [← entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ φ.symm.injective,
← entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ φ.symm.injective]
_ ≤ α * (H[ ψ ∘ X; μ ] + H[ ψ ∘ Y; μ' ]) := hup'.le
_ ≤ α * (c * (H[X ; μ] + H[Y ; μ'])) := by gcongr
_ = (α * c) * (H[X ; μ] + H[Y ; μ']) := by ring
· use ⊥
constructor
· simp only [AddSubgroup.mem_bot, Nat.card_eq_fintype_card, Fintype.card_ofSubsingleton,
Nat.cast_one, log_one]
positivity
· simp only [S, Set.mem_setOf_eq, not_and, not_lt] at hE
exact hE ⟨1, by norm_num, by
norm_num; exact add_le_add (entropy_comp_le μ hX _) (entropy_comp_le μ' hY _)⟩
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq 2 * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 34 * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
34 * d[(QuotientAddGroup.mk' H) ∘ X;μ # (QuotientAddGroup.mk' H) ∘ Y;μ'] := by
rcases PFR_projection' X Y μ μ' ((3 : ℝ) / 5) hX hY (by norm_num) (by norm_num) with ⟨H, h, h'⟩
refine ⟨H, ?_, ?_⟩
· convert h
norm_num
· have : 0 ≤ d[⇑(QuotientAddGroup.mk' H) ∘ X ; μ # ⇑(QuotientAddGroup.mk' H) ∘ Y ; μ'] :=
rdist_nonneg ((measurable_discrete _).comp hX) ((measurable_discrete _).comp hY)
linarith
end F2_projection
open MeasureTheory ProbabilityTheory Real Set
open scoped BigOperators
lemma four_logs {a b c d : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) (hd : 0 < d) :
log ((a*b)/(c*d)) = log a + log b - log c - log d := by
rw [log_div, log_mul, log_mul, sub_sub] <;> positivity
lemma sum_prob_preimage {G H : Type*} {X : Finset H} {A : Set G} [Finite A] {φ : A → X}
{A_ : H → Set G} (hA : A.Nonempty) (hφ : ∀ x : X, A_ x = Subtype.val '' (φ ⁻¹' {x})) :
∑ x in X, (Nat.card (A_ x) : ℝ) / (Nat.card A) = 1 := by
rw [← Finset.sum_div]
apply (div_eq_one_iff_eq <| Nat.cast_ne_zero.mpr <| Nat.pos_iff_ne_zero.mp (@Nat.card_pos _ hA.to_subtype _)).mpr
classical
haveI := Fintype.ofFinite A
rewrite [Nat.card_eq_fintype_card, ← Finset.card_univ, Finset.card_eq_sum_card_fiberwise
<| fun a _ ↦ Finset.mem_univ (φ a), ← Finset.sum_coe_sort]
norm_cast
congr; ext
rewrite [← Set.Finite.toFinset_setOf, (Set.toFinite _).card_toFinset, ← Nat.card_eq_fintype_card,
hφ, Nat.card_image_of_injective Subtype.val_injective]; rfl
/-- Let $\phi : G\to H$ be a homomorphism and $A,B\subseteq G$ be finite subsets. If $x,y\in H$ then let $A_x=A\cap \phi^{-1}(x)$ and $B_y=B\cap \phi^{-1}(y)$. There exist $x,y\in H$ such that $A_x,B_y$ are both non-empty and
\[d[\phi(U_A);\phi(U_B)]\log \frac{\lvert A\rvert\lvert B\rvert}{\lvert A_x\rvert\lvert B_y\rvert}\leq (\mathbb{H}(\phi(U_A))+\mathbb{H}(\phi(U_B)))(d(U_A,U_B)-d(U_{A_x},U_{B_y}).\] -/
lemma single_fibres {G H Ω Ω': Type u}
[AddCommGroup G] [Countable G] [MeasurableSpace G] [MeasurableSingletonClass G]
[AddCommGroup H] [Countable H] [MeasurableSpace H] [MeasurableSingletonClass H]
[MeasureSpace Ω] [MeasureSpace Ω']
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
(φ : G →+ H)
{A B : Set G} [Finite A] [Finite B] {UA : Ω → G} {UB: Ω' → G} (hA : A.Nonempty) (hB : B.Nonempty)
(hUA': Measurable UA) (hUB': Measurable UB) (hUA: IsUniform A UA) (hUB: IsUniform B UB)
(hUA_mem : ∀ ω, UA ω ∈ A) (hUB_mem : ∀ ω, UB ω ∈ B) :
∃ (x y : H) (Ax By: Set G),
Ax = A ∩ φ.toFun ⁻¹' {x} ∧ By = B ∩ φ.toFun ⁻¹' {y} ∧ Ax.Nonempty ∧ By.Nonempty ∧
d[φ.toFun ∘ UA # φ.toFun ∘ UB]
* log ((Nat.card A) * (Nat.card B) / ((Nat.card Ax) * (Nat.card By))) ≤
(H[φ.toFun ∘ UA] + H[φ.toFun ∘ UB]) * (d[UA # UB] - dᵤ[Ax # By]) := by
have : Nonempty A := hA.to_subtype
have : Nonempty B := hB.to_subtype
haveI : FiniteRange UA := finiteRange_of_finset UA A.toFinite.toFinset (by simpa)
haveI : FiniteRange UB := finiteRange_of_finset UB B.toFinite.toFinset (by simpa)
have hUA_coe : IsUniform A.toFinite.toFinset.toSet UA := by rwa [Set.Finite.coe_toFinset]
have hUB_coe : IsUniform B.toFinite.toFinset.toSet UB := by rwa [Set.Finite.coe_toFinset]
let A_ (x : H) : Set G := A ∩ φ.toFun ⁻¹' {x}
let B_ (y : H) : Set G := B ∩ φ.toFun ⁻¹' {y}
let X : Finset H := FiniteRange.toFinset (φ.toFun ∘ UA)
let Y : Finset H := FiniteRange.toFinset (φ.toFun ∘ UB)
haveI h_Ax (x : X) : Nonempty (A_ x.val) := by
obtain ⟨ω, hω⟩ := (FiniteRange.mem_iff _ _).mp x.property
use UA ω; exact Set.mem_inter (hUA_mem ω) (by exact hω)
haveI h_By (y : Y) : Nonempty (B_ y.val) := by
obtain ⟨ω, hω⟩ := (FiniteRange.mem_iff _ _).mp y.property
use UB ω; exact Set.mem_inter (hUB_mem ω) (by exact hω)
have h_AX (a : A) : φ.toFun a.val ∈ X := by
obtain ⟨ω, hω⟩ := hUA_coe.nonempty_preimage_of_mem hUA' (A.toFinite.mem_toFinset.mpr a.property)
exact (FiniteRange.mem_iff _ (φ.toFun a.val)).mpr ⟨ω, congr_arg _ hω⟩
have h_BY (b : B) : φ.toFun b.val ∈ Y := by
obtain ⟨ω, hω⟩ := hUB_coe.nonempty_preimage_of_mem hUB' (B.toFinite.mem_toFinset.mpr b.property)
exact (FiniteRange.mem_iff _ (φ.toFun b.val)).mpr ⟨ω, congr_arg _ hω⟩
let φ_AX (a : A) : X := by use φ.toFun a.val; exact h_AX a
let φ_BY (b : B) : Y := by use φ.toFun b.val; exact h_BY b
have h_φ_AX (x : X) : A_ x.val = φ_AX ⁻¹' {x} := by ext; simp [A_, φ_AX]; simp [Subtype.ext_iff]
have h_φ_BY (y : Y) : B_ y.val = φ_BY ⁻¹' {y} := by ext; simp [B_, φ_BY]; simp [Subtype.ext_iff]
let p (x : H) (y : H) : ℝ :=
(Nat.card (A_ x).Elem) * (Nat.card (B_ y).Elem) / ((Nat.card A.Elem) * (Nat.card B.Elem))
have :
∑ x in X, ∑ y in Y, (p x y) * dᵤ[A_ x # B_ y] ≤ d[UA # UB] - d[φ.toFun ∘ UA # φ.toFun ∘ UB] :=
calc
_ = d[UA | φ.toFun ∘ UA # UB | φ.toFun ∘ UB] := by
rewrite [condRuzsaDist_eq_sum hUA' ((measurable_discrete _).comp hUA')
hUB' ((measurable_discrete _).comp hUB')]
refine Finset.sum_congr rfl <| fun x hx ↦ Finset.sum_congr rfl <| fun y hy ↦ ?_
haveI : Nonempty (A_ x) := h_Ax ⟨x, hx⟩
haveI : Nonempty (B_ y) := h_By ⟨y, hy⟩
let μx := (ℙ : Measure Ω)[|(φ.toFun ∘ UA) ⁻¹' {x}]
let μy := (ℙ : Measure Ω')[|(φ.toFun ∘ UB) ⁻¹' {y}]
have h_μ_p : IsProbabilityMeasure μx ∧ IsProbabilityMeasure μy := by
constructor <;> apply ProbabilityTheory.cond_isProbabilityMeasure <;> rw [Set.preimage_comp]
refine @IsUniform.measure_preimage_ne_zero _ _ _ _ _ _ _ _ _ _ hUA_coe hUA' _ ?_
swap; refine @IsUniform.measure_preimage_ne_zero _ _ _ _ _ _ _ _ _ _ hUB_coe hUB' _ ?_
all_goals rwa [Set.inter_comm, Set.Finite.coe_toFinset]
have h_μ_unif : IsUniform (A_ x) UA μx ∧ IsUniform (B_ y) UB μy := by
have : _ ∧ _ := ⟨hUA.restrict hUA' (φ.toFun ⁻¹' {x}), hUB.restrict hUB' (φ.toFun ⁻¹' {y})⟩
rwa [Set.inter_comm _ A, Set.inter_comm _ B] at this
rewrite [rdist_set_eq_rdist h_μ_p.1 h_μ_p.2 h_μ_unif.1 h_μ_unif.2 hUA' hUB']
show _ = (Measure.real _ (UA ⁻¹' (_ ⁻¹' _))) * (Measure.real _ (UB ⁻¹' (_ ⁻¹' _))) * _
rewrite [hUA_coe.measureReal_preimage hUA', hUB_coe.measureReal_preimage hUB']
simp_rw [p, A_, B_, IsProbabilityMeasure.measureReal_univ, one_mul]
rewrite [mul_div_mul_comm, Set.inter_comm A, Set.inter_comm B]
simp only [Set.Finite.coe_toFinset, Set.Finite.mem_toFinset, Finset.mem_val]; rfl
_ ≤ d[UA # UB] - d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
rewrite [ZeroHom.toFun_eq_coe, AddMonoidHom.toZeroHom_coe]
linarith only [rdist_le_sum_fibre φ hUA' hUB' (μ := ℙ) (μ' := ℙ)]
let M := H[φ.toFun ∘ UA] + H[φ.toFun ∘ UB]
have hM : M = ∑ x in X, ∑ y in Y, Real.negMulLog (p x y) := by
have h_compl {x y} (h_notin : (x, y) ∉ X ×ˢ Y) : Real.negMulLog (p x y) = 0 := by
unfold_let p; beta_reduce
rewrite [Finset.mem_product, not_and_or] at h_notin
suffices A_ x = ∅ ∨ B_ y = ∅ by obtain h | h := this <;> rw [h] <;> simp
refine h_notin.imp ?_ ?_
· rw [← not_nonempty_iff_eq_empty]
rintro h ⟨a, ha, rfl⟩
exact h (h_AX ⟨a, ha⟩)
· rw [← not_nonempty_iff_eq_empty]
rintro h ⟨a, ha, rfl⟩
exact h (h_BY ⟨a, ha⟩)
unfold_let M
unfold entropy
haveI := isProbabilityMeasure_map (μ := ℙ) ((measurable_discrete φ).comp hUA').aemeasurable
haveI := isProbabilityMeasure_map (μ := ℙ) ((measurable_discrete φ).comp hUB').aemeasurable
rewrite [← Finset.sum_product', ← tsum_eq_sum fun _ ↦ h_compl, ← measureEntropy_prod]
apply tsum_congr; intro; congr
rewrite [← Set.singleton_prod_singleton, Measure.smul_apply, Measure.prod_prod,
Measure.map_apply ((measurable_discrete _).comp hUA') (MeasurableSet.singleton _),
Measure.map_apply ((measurable_discrete _).comp hUB') (MeasurableSet.singleton _),
Set.preimage_comp, hUA_coe.measure_preimage hUA',
Set.preimage_comp, hUB_coe.measure_preimage hUB']
simp [p, A_, B_, mul_div_mul_comm, Set.inter_comm, ENNReal.toReal_div]
have h_sum : ∑ x in X, ∑ y in Y,
(p x y) * (M * dᵤ[A_ x # B_ y] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p x y)) ≤
M * d[UA # UB] :=
calc
_ = ∑ x in X, ∑ y in Y, (p x y) * M * dᵤ[A_ x # B_ y] + M * d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
simp_rw [hM, Finset.sum_mul, ← Finset.sum_add_distrib]
refine Finset.sum_congr rfl <| fun _ _ ↦ Finset.sum_congr rfl <| fun _ _ ↦ ?_
simp only [negMulLog, left_distrib, mul_assoc, Finset.sum_mul]
exact congrArg (HAdd.hAdd _) (by group)
_ = M * ∑ x in X, ∑ y in Y, (p x y) * dᵤ[A_ x # B_ y] + M * d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
simp_rw [Finset.mul_sum]
congr; ext; congr; ext; group
_ ≤ M * d[UA # UB] := by
rewrite [← left_distrib]
apply mul_le_mul_of_nonneg_left
· linarith
· unfold_let M
linarith only [entropy_nonneg (φ.toFun ∘ UA) ℙ, entropy_nonneg (φ.toFun ∘ UB) ℙ]
have : ∃ x : X, ∃ y : Y,
M * dᵤ[A_ x.val # B_ y.val] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p x.val y.val) ≤
M * d[UA # UB] := by
let f (xy : H × H) := (p xy.1 xy.2) * (M * d[UA # UB])
let g (xy : H × H) := (p xy.1 xy.2) *
(M * dᵤ[A_ xy.1 # B_ xy.2] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p xy.1 xy.2))
by_contra hc; push_neg at hc
replace hc : ∀ xy ∈ X ×ˢ Y, f xy < g xy := by
refine fun xy h ↦ mul_lt_mul_of_pos_left ?_ ?_
· exact hc ⟨xy.1, (Finset.mem_product.mp h).1⟩ ⟨xy.2, (Finset.mem_product.mp h).2⟩
· haveI : Nonempty _ := h_Ax ⟨xy.1, (Finset.mem_product.mp h).1⟩
haveI : Nonempty _ := h_By ⟨xy.2, (Finset.mem_product.mp h).2⟩
simp only [p, div_pos, mul_pos, Nat.cast_pos, Nat.card_pos]
have h_nonempty : Finset.Nonempty (X ×ˢ Y) := by
use ⟨φ.toFun <| UA <| Classical.choice <| ProbabilityMeasure.nonempty ⟨ℙ, inferInstance⟩,
φ.toFun <| UB <| Classical.choice <| ProbabilityMeasure.nonempty ⟨ℙ, inferInstance⟩⟩
exact Finset.mem_product.mpr ⟨FiniteRange.mem _ _, FiniteRange.mem _ _⟩
replace hc := Finset.sum_lt_sum_of_nonempty h_nonempty hc
have h_p_one : ∑ x in X ×ˢ Y, p x.1 x.2 = 1 := by
simp_rw [Finset.sum_product, p, mul_div_mul_comm, ← Finset.mul_sum,
← sum_prob_preimage hA h_φ_AX, sum_prob_preimage hB h_φ_BY, mul_one]
rewrite [← Finset.sum_mul, h_p_one, one_mul, Finset.sum_product] at hc
exact not_le_of_gt hc h_sum
obtain ⟨x, y, hxy⟩ := this
refine ⟨x, y, A_ x.val, B_ y.val, rfl, rfl, @nonempty_of_nonempty_subtype _ _ (h_Ax x), @nonempty_of_nonempty_subtype _ _ (h_By y), ?_⟩
rewrite [← inv_div, Real.log_inv]
show _ * -log (p x.val y.val) ≤ M * _
linarith only [hxy]
section dim
open Classical
variable {G : Type*} [AddCommGroup G]
/- If G ≅ ℤᵈ then there is a subgroup H of G such that A lies in a coset of H. This is helpful to
give the equivalent definition of `dimension`. Here this is stated in greated generality since the
proof carries over automatically-/
lemma exists_coset_cover (A : Set G) :
∃ (d : ℕ), ∃ (S : Submodule ℤ G) (v : G),
FiniteDimensional.finrank ℤ S = d ∧ ∀ a ∈ A, a - v ∈ S := by
existsi FiniteDimensional.finrank ℤ (⊤ : Submodule ℤ G), ⊤, 0
refine ⟨rfl, fun a _ ↦ trivial⟩
/-- The dimension of the affine span over `ℤ` of a subset of an additive group. -/
noncomputable def dimension (A : Set G) : ℕ := Nat.find (exists_coset_cover A)
lemma dimension_le_of_coset_cover (A : Set G) (S : Submodule ℤ G) (v : G)
(hA : ∀ a ∈ A, a - v ∈ S) : dimension A ≤ FiniteDimensional.finrank ℤ S := by
apply Nat.find_le
existsi S , v
exact ⟨rfl, hA⟩
lemma dimension_le_rank [Module.Finite ℤ G] (A : Set G) :
dimension A ≤ FiniteDimensional.finrank ℤ G := by
obtain ⟨S, v, hs, _⟩ := Nat.find_spec (exists_coset_cover A)
rw [dimension, ←hs]
apply Submodule.finrank_le S
end dim
variable {G : Type u} [AddCommGroup G] [Module.Free ℤ G] [Module.Finite ℤ G] [Countable G] [MeasurableSpace G] [MeasurableSingletonClass G]
open Real MeasureTheory ProbabilityTheory Pointwise Set
/-- Move to Mathlib? `Finsupp.mapRange` of a surjective function is surjective. -/
lemma Finsupp.mapRange_surjective {α : Type u_1} {M : Type u_5} {N : Type u_7} [Zero M] [Zero N] (f : M → N) (hf : f 0 = 0)
(hs : Function.Surjective f) : Function.Surjective (Finsupp.mapRange (α := α) f hf) := by
classical
let g (n : N) : M := if n = 0 then 0 else Function.surjInv hs n
have : Function.RightInverse g f := by
intro n
by_cases h : n = 0
. simp [g, h, hf]
· simp [g, h, Function.surjInv_eq hs n]
have hg : g 0 = 0 := by simp [g]
have hfg : (f ∘ g) 0 = 0 := by simp [hf, hg]
intro F
use Finsupp.mapRange g hg F
rw [← Finsupp.mapRange_comp (h := hfg)]
convert Finsupp.mapRange_id F
convert Function.RightInverse.id this
/-- A free Z-module is torsion-free. Move to Mathlib? -/
lemma torsion_free : AddMonoid.IsTorsionFree G := by
rintro x hx hn
rw [isOfFinAddOrder_iff_nsmul_eq_zero] at hn
rcases hn with ⟨ n, hn, hn' ⟩
apply_fun Module.Free.repr ℤ G at hn'
simp_rw [map_nsmul, map_zero, smul_eq_zero, AddEquivClass.map_eq_zero_iff, hx, or_false] at hn'
linarith
/-- If G is a rank n free Z-module, then G/2G is a finite elementary 2-group of cardinality 2^n. Code is slow, needs to be golfed -/
lemma weak_PFR_quotient_prelim :
let H := G ⧸ (AddMonoidHom.range (zsmulAddGroupHom 2))
ElementaryAddCommGroup H 2 ∧ Finite H ∧ Nat.card H = 2^(FiniteDimensional.finrank ℤ G) := by
set ψ : G →+ G := zsmulAddGroupHom 2
set G₂ := AddMonoidHom.range ψ
set H := G ⧸ G₂
set φ : G →+ H := QuotientAddGroup.mk' G₂
have hH_elem : ElementaryAddCommGroup H 2 := by
apply ElementaryAddCommGroup.quotient_group (by decide)
intro x; rw [AddMonoidHom.mem_range]
use x
rw [zsmulAddGroupHom_apply]
norm_cast
let B := Module.Free.ChooseBasisIndex ℤ G
let bG : Basis B ℤ G := Module.Free.chooseBasis ℤ G
have hB_fin : Fintype B := by infer_instance
have hB_card : Nat.card B = FiniteDimensional.finrank ℤ G := by
rw [FiniteDimensional.finrank_eq_card_basis bG, Nat.card_eq_fintype_card]
have hH_module : Module (ZMod 2) H := by infer_instance
let mod : (B →₀ ℤ) →+ (B →₀ ZMod 2) := Finsupp.mapRange.addMonoidHom (Int.castAddHom (ZMod 2))
let f : G →+ (B →₀ ℤ) := bG.repr
have hker : G₂ ≤ AddMonoidHom.ker (AddMonoidHom.comp mod f) := by
intro x hx
simp only [AddMonoidHom.mem_range, G₂, ψ, zsmulAddGroupHom_apply] at hx
simp_rw [AddMonoidHom.mem_ker, AddMonoidHom.coe_comp, Function.comp_apply, mod,
Finsupp.mapRange.addMonoidHom_apply, Int.coe_castAddHom]
rcases hx with ⟨y, rfl⟩
ext b
simp_rw [map_zsmul, Finsupp.mapRange_apply, Finsupp.coe_smul, Pi.smul_apply, smul_eq_mul,
Int.cast_mul, Int.cast_ofNat, Finsupp.coe_zero, Pi.zero_apply, mul_eq_zero]
left
exact ZMod.nat_cast_self 2
let g : H →+ (B →₀ ZMod 2) := QuotientAddGroup.lift G₂ (AddMonoidHom.comp mod f) hker
have hsur : Function.Surjective g := by
have h1 : Function.Surjective mod := Finsupp.mapRange_surjective (Int.castAddHom (ZMod 2)) (map_zero _) ZMod.int_cast_surjective
have h2 := h1.comp bG.repr.surjective
have h3 : mod ∘ bG.repr = g ∘ (QuotientAddGroup.mk' G₂) := by
ext x b
simp_rw [mod, Function.comp_apply, Finsupp.mapRange.addMonoidHom_apply, Int.coe_castAddHom,
Finsupp.mapRange_apply, QuotientAddGroup.coe_mk', g]
rw [QuotientAddGroup.lift_mk]
simp [mod, f]
rw [h3] at h2
apply Function.Surjective.of_comp h2
have hinj : Function.Injective g := by
rw [injective_iff_map_eq_zero]
intro x hx
rcases QuotientAddGroup.mk'_surjective G₂ x with ⟨y, rfl⟩
simp only [QuotientAddGroup.mk'_apply, g] at hx
rw [QuotientAddGroup.lift_mk] at hx
simp_rw [AddMonoidHom.coe_comp, Function.comp_apply, mod, Finsupp.mapRange.addMonoidHom_apply,
Int.coe_castAddHom, DFunLike.ext_iff,Finsupp.mapRange_apply, Finsupp.coe_zero, Pi.zero_apply,
ZMod.int_cast_zmod_eq_zero_iff_dvd] at hx
replace hx := fun x ↦ Int.mul_ediv_cancel' (hx x)
let z (b : B) := ((Module.Free.chooseBasis ℤ G).repr y) b / 2
let z' := (Finsupp.equivFunOnFinite).symm z
change ∀ b : B, 2 * z' b = (f y) b at hx
let x' := bG.repr.symm z'
rw [QuotientAddGroup.mk'_apply, QuotientAddGroup.eq_zero_iff, AddMonoidHom.mem_range]
simp_rw [ψ, zsmulAddGroupHom_apply]
use x'
change 2 • (bG.repr.symm.toLinearMap.toAddMonoidHom z') = y
rw [← AddMonoidHom.map_zsmul bG.repr.symm.toLinearMap.toAddMonoidHom z' (2 : ℤ)]
rw [← LinearEquiv.symm_apply_apply bG.repr y]
change bG.repr.symm (2 • z') = bG.repr.symm (f y)
congr
ext b
rw [Finsupp.smul_apply, ← hx b, smul_eq_mul]
rcases Function.bijective_iff_has_inverse.mp ⟨ hinj, hsur ⟩ with ⟨ g', hg' ⟩
have bH : Basis B (ZMod 2) H := by
constructor
exact {
toFun := g
invFun := g'
left_inv := hg'.1
right_inv := hg'.2
map_add' := AddMonoidHom.map_add _
map_smul' := by
intro r x
rcases ZMod.int_cast_surjective r with ⟨ n, rfl ⟩
change g ((n : ZMod 2) • x) = (n : ZMod 2) • g x
rw [intCast_smul, intCast_smul]
exact AddMonoidHom.map_zsmul g x n
}
have hH_fin : Fintype H := Module.fintypeOfFintype bH
have hH_card : Nat.card H = 2^(FiniteDimensional.finrank ℤ G) := by
rw [Nat.card_eq_fintype_card, Module.card_fintype bH, ← Nat.card_eq_fintype_card (α := B), hB_card]
congr
exact ⟨ hH_elem, Finite.of_fintype H, hH_card ⟩
open QuotientAddGroup
/-- A version of the third isomorphism theorem: if G₂ ≤ G and H' is a subgroup of G⧸G₂, then there is a canonical isomorphism between H⧸H' and G⧸N, where N is the preimage of H' in G. A bit clunky; may be a better way to do this -/
| lemma third_iso {G : Type u} [AddCommGroup G] {G₂ : AddSubgroup G} (H' : AddSubgroup (G ⧸ G₂)) :
let H := G ⧸ G₂
let φ : G →+ H := mk' G₂
let N := AddSubgroup.comap φ H'
∃ e : H ⧸ H' ≃+ G ⧸ N, ∀ x : G, e (mk' H' (φ x))= mk' N x | third_iso | 25309ad 20231211 | c0c547a 20240116 | pfr/PFR/WeakPFR.lean | {
"lineInFile": 744,
"tokenPositionInFile": 40301,
"theoremPositionInFile": 22
} | {
"inFilePremises": false,
"repositoryPremises": false
} | {
"hasProof": true,
"proof": "by\n set H := G ⧸ G₂\n let φ : G →+ H := mk' G₂\n let N := AddSubgroup.comap φ H'\n have h1 : G₂ ≤ N := by\n intro x hx\n rw [← eq_zero_iff] at hx\n have : φ x = 0 := hx\n simp [N, this, AddSubgroup.zero_mem H']\n set H'' := AddSubgroup.map (mk' G₂) N\n have h2 : H' = H'' := by\n change H' = AddSubgroup.map (mk' G₂) N\n rw [AddSubgroup.map_comap_eq, AddMonoidHom.range_top_of_surjective _ (mk'_surjective G₂)]\n simp\n let e1 : H ⧸ H'' ≃+ G ⧸ N := quotientQuotientEquivQuotient _ _ h1\n let e2 := quotientAddEquivOfEq h2\n set e := e2.trans e1\n use e\n intro x\n convert (quotientQuotientEquivQuotientAux_mk_mk _ _ h1 x) using 1",
"proofType": "tactic",
"proofLengthLines": 20,
"proofLengthTokens": 645
} | pfr |
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Quotient
import Mathlib.GroupTheory.Torsion
import Mathlib.GroupTheory.Torsion
import Mathlib.LinearAlgebra.FreeModule.PID
import PFR.Mathlib.Data.Set.Pointwise.SMul
import PFR.EntropyPFR
import PFR.ImprovedPFR
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Mathlib.GroupTheory.Torsion
/-!
# Weak PFR over the integers
Here we use the entropic form of PFR to deduce a weak form of PFR over the integers.
## Main statement
* `weak_PFR_int`: Let $A\subseteq \mathbb{Z}^d$ and $\lvert A+A\rvert\leq K\lvert A\rvert$.
There exists $A'\subseteq A$ such that $\lvert A'\rvert \geq K^{-17}\lvert A\rvert$ and
$\dim A' \leq (40/\log 2)\log K$.
-/
section AddCommGroup
variable {G : Type*} [AddCommGroup G] {A B : Set G}
open Set
open scoped Pointwise
def IsShift (A B : Set G) : Prop := ∃ x : G, A = x +ᵥ B
lemma IsShift.sub_self_congr : IsShift A B → A - A = B - B := by
rintro ⟨x, rfl⟩; simp [vadd_sub_vadd_comm, singleton_zero]
lemma IsShift.card_congr : IsShift A B → Nat.card A = Nat.card B := by rintro ⟨x, rfl⟩; simp
/-- The property of two sets A, B of a group G not being contained in cosets of the same proper
subgroup -/
def NotInCoset (A B : Set G) : Prop := AddSubgroup.closure ((A - A) ∪ (B - B)) = ⊤
/-- Without loss of generality, one can move (up to translation and embedding) any pair A, B of non-empty sets into a subgroup where they are not in a coset. -/
lemma wlog_notInCoset (hA : A.Nonempty) (hB : B.Nonempty) :
∃ (G' : AddSubgroup G) (A' B' : Set G'), IsShift A A' ∧ IsShift B B' ∧ NotInCoset A' B' := by
obtain ⟨x, hx⟩ := hA
obtain ⟨y, hy⟩ := hB
set G' := AddSubgroup.closure ((A - A) ∪ (B - B))
set A' : Set G' := (↑) ⁻¹' ((-x) +ᵥ A)
set B' : Set G' := (↑) ⁻¹' ((-y) +ᵥ B)
have hxA : -x +ᵥ A ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hx).trans $ (subset_union_left ..).trans
AddSubgroup.subset_closure
have hyB : -y +ᵥ B ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hy).trans $ (subset_union_right ..).trans
AddSubgroup.subset_closure
have hA : IsShift A A' := ⟨x, by rw [Set.image_preimage_eq_of_subset hxA, vadd_neg_vadd]⟩
have hB : IsShift B B' := ⟨y, by rw [Set.image_preimage_eq_of_subset hyB, vadd_neg_vadd]⟩
refine ⟨G', A', B', hA, hB, ?_⟩
unfold NotInCoset
convert AddSubgroup.closure_preimage_eq_top ((A - A) ∪ (B - B))
simp_rw [preimage_union, hA.sub_self_congr, hB.sub_self_congr]
rw [preimage_sub, preimage_sub]
simp [A', B', preimage_image_preimage]
all_goals apply_rules [Subtype.coe_injective, (image_preimage_subset ..).trans, hxA, hyB]
end AddCommGroup
section Torsion
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [MeasurableSpace G] [MeasurableSingletonClass G]
[Countable G] {Ω Ω' : Type u} [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ': Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
/-- If $G$ is torsion-free and $X,Y$ are $G$-valued random variables then $d[X;2Y]\leq 5d[X;Y]$. -/
lemma torsion_free_doubling [FiniteRange X] [FiniteRange Y]
(hX : Measurable X) (hY : Measurable Y) (hG : AddMonoid.IsTorsionFree G) :
d[X ; μ # (Y + Y) ; μ'] ≤ 5 * d[X; μ # Y ; μ'] := by
obtain ⟨A, mA, μA, X', Y'₁, Y'₂, hμA, h_indep, hX'_meas, hY'₁_meas, hY'₂_meas, hX'_ident,
hY'₁_ident, hY'₂_ident, _, _, _⟩ := independent_copies3_nondep_finiteRange hX hY hY μ μ' μ'
have h_meas (i : Fin 3) : Measurable (![X', Y'₁, Y'₂] i) := by fin_cases i <;> assumption
haveI : NoZeroSMulDivisors ℕ G := hG.noZeroNsmulDivisors
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨x, y₁, y₂⟩ ↦ (x, y₁ - y₂, x - 2 • y₁)
show H[f ∘ ⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] = _
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hX'_meas <| Measurable.prod hY'₁_meas hY'₂_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun X' (prod Y'₁ Y'₂) μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 1 2 0 (by decide) (by decide)
rw [this.entropy_pair_eq_add hX'_meas (by exact Measurable.prod hY'₁_meas hY'₂_meas),
IndepFun.entropy_pair_eq_add hY'₁_meas hY'₂_meas (h_indep.indepFun (show 1 ≠ 2 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, two_mul]
have : H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[X ; μ] + H[Y ; μ'] := calc
H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[⟨X', Y'₁⟩ ; μA] := by
let f : G × G → G × G := fun ⟨x, y₁⟩ ↦ (x, x - 2 • y₁)
show H[f ∘ ⟨X', Y'₁⟩ ; μA] = _
apply entropy_comp_of_injective μA (by exact Measurable.prod hX'_meas hY'₁_meas) f
exact fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + H[Y ; μ'] := by
rw [IndepFun.entropy_pair_eq_add hX'_meas hY'₁_meas (h_indep.indepFun (show 0 ≠ 1 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq]
let f : G × G → G × G := fun ⟨x, y⟩ ↦ (x, y - x)
have hf : f.Injective := fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all
have : H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] := calc
H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] = H[f ∘ ⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
show _ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂ - (Y'₁ - Y'₂)⟩ ; μA]
rw [sub_sub_sub_cancel_right, ← sub_add_eq_sub_sub, two_nsmul]
_ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
refine entropy_comp_of_injective μA (Measurable.prod ?_ ?_) f hf
· exact Measurable.sub hY'₁_meas hY'₂_meas
· exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
_ ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] :=
entropy_pair_le_add (hY'₁_meas.sub' hY'₂_meas) (hX'_meas.sub' hY'₁_meas |>.sub' hY'₂_meas) μA
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] + H[X' - 2 • Y'₁ ; μA] ≤
H[⟨X', X' - 2 • Y'₁⟩ ; μA] + H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] := by
haveI : FiniteRange (Y'₁ - Y'₂) := FiniteRange.sub Y'₁ Y'₂
haveI : FiniteRange (2 • Y'₁) := by show FiniteRange ((fun x ↦ 2 • x) ∘ Y'₁); infer_instance
apply entropy_triple_add_entropy_le μA hX'_meas (Measurable.sub hY'₁_meas hY'₂_meas)
exact Measurable.sub' hX'_meas <| Measurable.const_smul hY'₁_meas 2
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨y₁, y₂, x⟩ ↦ (y₁, y₂, x - y₁ - y₂)
show H[f ∘ ⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA]
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hY'₁_meas <| Measurable.prod hY'₂_meas hX'_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun Y'₁ (prod Y'₂ X') μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 2 0 1 (by decide) (by decide)
rw [this.entropy_pair_eq_add hY'₁_meas (by exact Measurable.prod hY'₂_meas hX'_meas),
IndepFun.entropy_pair_eq_add hY'₂_meas hX'_meas (h_indep.indepFun (show 2 ≠ 0 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq]
group
have : H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₂ ; μA] := calc
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₁, X' - Y'₂⟩ ; μA] := by rw [sub_right_comm] ; rfl
_ = H[⟨Y'₁, X' - Y'₂⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₁_meas <| Measurable.sub hX'_meas hY'₂_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₂ ; μA] := by
haveI : FiniteRange (X' - Y'₂) := FiniteRange.sub X' Y'₂
convert IndepFun.entropy_pair_eq_add hY'₁_meas (hX'_meas.sub hY'₂_meas)
<| h_indep.indepFun_sub_right h_meas 1 0 2 (by decide) (by decide)
exact hY'₁_ident.entropy_eq.symm
have : H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₁ ; μA] := calc
H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₂, X' - Y'₁⟩ ; μA] := rfl
_ = H[⟨Y'₂, X' - Y'₁⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₂_meas <| Measurable.sub hX'_meas hY'₁_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₁ ; μA] := by
haveI : FiniteRange (X' - Y'₁) := FiniteRange.sub X' Y'₁
convert IndepFun.entropy_pair_eq_add hY'₂_meas (hX'_meas.sub hY'₁_meas)
<| h_indep.indepFun_sub_right h_meas 2 0 1 (by decide) (by decide)
exact hY'₂_ident.entropy_eq.symm
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] ≤
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] + H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
apply entropy_triple_add_entropy_le μA hY'₁_meas hY'₂_meas
exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
have : H[X' - Y'₁ - Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := calc
H[X' - Y'₁ - Y'₂ ; μA] ≤ H[X' - Y'₁ ; μA] + H[X' - Y'₂ ; μA] - H[X ; μ] := by linarith
_ = 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := by
nth_rw 1 [two_mul, ← hX'_ident.rdist_eq hY'₁_ident, ← hX'_ident.rdist_eq hY'₂_ident]
have h1 : d[X' ; μA # Y'₁ ; μA] = H[X' - Y'₁ ; μA] - H[X' ; μA] / 2 - H[Y'₁ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 1 by decide)).rdist_eq hX'_meas hY'₁_meas
have h2 : d[X' ; μA # Y'₂ ; μA] = H[X' - Y'₂ ; μA] - H[X' ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 2 by decide)).rdist_eq hX'_meas hY'₂_meas
rw [h1, h2, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, hX'_ident.entropy_eq]
group
have : d[X ; μ # 2 • Y ; μ'] ≤
d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := calc
d[X ; μ # 2 • Y ; μ'] = H[X' - 2 • Y'₁ ; μA] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by
have h2Y_ident : IdentDistrib (2 • Y'₁) (2 • Y) (μ := μA) (ν := μ') := by
convert hY'₁_ident.comp <| measurable_discrete <| fun g ↦ 2 • g
have h2Y_indep : IndepFun X' (2 • Y'₁) (μ := μA) := by
convert (h_indep.indepFun (show 0 ≠ 1 by decide)).comp measurable_id
(measurable_const_smul 2)
rw [← hX'_ident.rdist_eq h2Y_ident,
h2Y_indep.rdist_eq hX'_meas <| Measurable.const_smul hY'₁_meas 2,
hX'_ident.entropy_eq, h2Y_ident.entropy_eq]
_ ≤ H[Y'₁ - Y'₂ ; μA] + 2 * d[X ; μ # Y ; μ'] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by linarith
_ = d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := by
have H2Y : H[2 • Y ; μ'] = H[Y ; μ'] := by
let f (g : G) := 2 • g
exact entropy_comp_of_injective μ' hY f (fun _ _ ↦ by simp [f, smul_right_inj])
have : d[Y'₁ ; μA # Y'₂ ; μA] = H[Y'₁ - Y'₂ ; μA] - H[Y'₁ ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 1 ≠ 2 by decide)).rdist_eq hY'₁_meas hY'₂_meas
rw [this, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, H2Y]
group
have : d[Y'₁ ; μA # Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] := by
rw [two_mul]
convert rdist_triangle hY'₁_meas hX'_meas hY'₂_meas (μ := μA) (μ' := μA) (μ'' := μA)
· exact rdist_symm.trans (hY'₁_ident.rdist_eq hX'_ident).symm
· exact (hX'_ident.rdist_eq hY'₂_ident).symm
rw [← two_nsmul]
linarith [abs_le.mp <| diff_ent_le_rdist hX hY (μ := μ) (μ' := μ')]
/-- If $G$ is a torsion-free group and $X,Y$ are $G$-valued random variables and
$\phi : G\to \mathbb{F}_2^d$ is a homomorphism then
\[\mathbb{H}(\phi(X))\leq 10d[X;Y].\] -/
lemma torsion_dist_shrinking {H : Type u} [FiniteRange X] [FiniteRange Y] (hX : Measurable X)
(hY : Measurable Y) [AddCommGroup H] [ElementaryAddCommGroup H 2]
[MeasurableSpace H] [MeasurableSingletonClass H] [Countable H]
(hG : AddMonoid.IsTorsionFree G) (φ : G →+ H) :
H[φ ∘ X ; μ] ≤ 10 * d[X; μ # Y ; μ'] := by
have :=
calc d[φ ∘ X ; μ # φ ∘ (Y + Y); μ'] ≤ d[X; μ # (Y + Y) ; μ'] := rdist_of_hom_le φ hX (Measurable.add hY hY)
_ ≤ 5 * d[X; μ # Y ; μ'] := torsion_free_doubling X Y μ μ' hX hY hG
have eq_zero : φ ∘ (Y + Y) = fun _ ↦ 0 := by ext x ; simp only [Function.comp_apply, Pi.add_apply,
map_add, ElementaryAddCommGroup.add_self]
rwa [eq_zero, rdist_zero_eq_half_ent, div_le_iff zero_lt_two, mul_assoc, mul_comm _ 2, ←mul_assoc,
show (5*2 : ℝ) = 10 by norm_num] at this
end Torsion
instance {G : Type u} [AddCommGroup G] [Fintype G] [MeasurableSpace G] [MeasurableSingletonClass G] (H : AddSubgroup G)
: MeasurableSingletonClass (G ⧸ H) :=
⟨λ _ ↦ by { rw [measurableSet_quotient]; simp [measurableSet_discrete] }⟩
section F2_projection
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [ElementaryAddCommGroup G 2] [Fintype G] [MeasurableSpace G]
[MeasurableSingletonClass G] {Ω Ω' : Type*}
/-- Let $G=\mathbb{F}_2^n$ and $X,Y$ be $G$-valued random variables such that
\[\mathbb{H}(X)+\mathbb{H}(Y)> (20/\alpha) d[X;Y],\]
for some $\alpha > 0$.
There is a non-trivial subgroup $H\leq G$ such that
\[\log \lvert H\rvert <(1+\alpha)/2 (\mathbb{H}(X)+\mathbb{H}(Y))\] and
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))< \alpha (\mathbb{H}(X)+\mathbb{H}(Y))\]
where $\psi:G\to G/H$ is the natural projection homomorphism.
-/
lemma app_ent_PFR' [MeasureSpace Ω] [MeasureSpace Ω'] (X : Ω → G) (Y : Ω' → G)
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
{α : ℝ} (hent : 20 * d[X # Y] < α * (H[X] + H[Y])) (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X] + H[Y]) ∧
H[(QuotientAddGroup.mk' H) ∘ X] + H[(QuotientAddGroup.mk' H) ∘ Y] < α * (H[X] + H[Y]) := by
let p : refPackage Ω Ω' G := {
X₀₁ := X
X₀₂ := Y
hmeas1 := hX
hmeas2 := hY
η := 1/8
hη := by norm_num
hη' := by norm_num }
obtain ⟨H, Ω'', hΩ'', U, _, hUmeas, hUunif, ineq⟩ := entropic_PFR_conjecture_improv p rfl
let ψ := (QuotientAddGroup.mk' H)
use H
haveI : Finite H := Subtype.finite
-- Note that H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y]
have ent_le : H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y] := calc
H[ψ ∘ X] + H[ψ ∘ Y] ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· exact ent_of_proj_le hX hUmeas hUunif
· exact ent_of_proj_le hY hUmeas hUunif
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- Note that (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y]
have log_sub_le : (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y] := calc
(log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) =
(H[U] - H[X]) + (H[U] - H[Y]) := by
rw [IsUniform.entropy_eq' hUunif hUmeas, SetLike.coe_sort_coe]
_ ≤ |(H[U] - H[X])| + |(H[U] - H[Y])| := by gcongr <;> exact le_abs_self _
_ ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hX
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hY
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- then the conclusion follows from the assumption `hent` and basic inequality manipulations
exact ⟨by linarith, by linarith⟩
variable [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ' : Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
lemma app_ent_PFR (α : ℝ) (hent: 20 * d[X;μ # Y;μ'] < α * (H[X; μ] + H[Y; μ'])) (hX : Measurable X)
(hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ']
< α * (H[ X; μ] + H[Y; μ']) :=
@app_ent_PFR' _ _ _ _ _ _ _ _ (MeasureSpace.mk μ) (MeasureSpace.mk μ') _ _ _ _ α hent hX hY
set_option maxHeartbeats 300000 in
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables and $\alpha < 1$ then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq (1 + α) / (2 * (1 - α)) * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 20/\alpha * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection'
(α : ℝ) (hX : Measurable X) (hY : Measurable Y) (αpos : 0 < α) (αone : α < 1) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (H[X ; μ] + H[Y ; μ']) ∧
α * (H[(QuotientAddGroup.mk' H) ∘ X ; μ] + H[(QuotientAddGroup.mk' H) ∘ Y ; μ']) ≤
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] := by
let S := { H : AddSubgroup G | (∃ (c : ℝ), 0 ≤ c ∧
log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (1 - c) * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
c * (H[X; μ] + H[Y;μ'])) ∧
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] <
α * (H[ (QuotientAddGroup.mk' H) ∘ X; μ ] + H[ (QuotientAddGroup.mk' H) ∘ Y; μ']) }
have : 0 ≤ H[X ; μ] + H[Y ; μ'] := by linarith [entropy_nonneg X μ, entropy_nonneg Y μ']
have : 0 < 1 - α := sub_pos.mpr αone
by_cases hE : (⊥ : AddSubgroup G) ∈ S
· classical
obtain ⟨H, ⟨⟨c, hc, hlog, hup⟩, hent⟩, hMaxl⟩ :=
S.toFinite.exists_maximal_wrt id S (Set.nonempty_of_mem hE)
set ψ : G →+ G ⧸ H := QuotientAddGroup.mk' H
have surj : Function.Surjective ψ := QuotientAddGroup.mk'_surjective H
set G' := G ⧸ H
have : ElementaryAddCommGroup G' 2 := ElementaryAddCommGroup.quotient_group (by decide)
(by simp [AddSubgroup.zero_mem])
obtain ⟨H', hlog', hup'⟩ := app_ent_PFR _ _ _ _ α hent ((measurable_discrete _).comp hX)
((measurable_discrete _).comp hY)
have H_ne_bot: H' ≠ ⊥ := by
by_contra!
rcases this with rfl
have inj : Function.Injective (QuotientAddGroup.mk' (⊥ : AddSubgroup G')) :=
(QuotientAddGroup.quotientBot : (G' ⧸ ⊥) ≃+ G').symm.injective
rw [entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ inj,
entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ inj] at hup'
nlinarith [entropy_nonneg (ψ ∘ X) μ, entropy_nonneg (ψ ∘ Y) μ']
let H'' := H'.comap ψ
use H''
rw [← (AddSubgroup.map_comap_eq_self_of_surjective surj _ : H''.map ψ = H')] at hup' hlog'
set H' := H''.map ψ
have Hlt : H < H'' := by
have : H = (⊥ : AddSubgroup G').comap ψ := by
simp only [ψ, AddMonoidHom.comap_bot, QuotientAddGroup.ker_mk']
rw [this, AddSubgroup.comap_lt_comap_of_surjective surj]
exact Ne.bot_lt H_ne_bot
let φ : G' ⧸ H' ≃+ G ⧸ H'' := QuotientAddGroup.quotientQuotientEquivQuotient H H'' Hlt.le
set ψ' : G' →+ G' ⧸ H' := QuotientAddGroup.mk' H'
set ψ'' : G →+ G ⧸ H'' := QuotientAddGroup.mk' H''
have diag : ψ' ∘ ψ = φ.symm ∘ ψ'' := rfl
rw [← Function.comp.assoc, ← Function.comp.assoc, diag, Function.comp.assoc,
Function.comp.assoc] at hup'
have cond : log (Nat.card H'') ≤
(1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := by
have cardprod : Nat.card H'' = Nat.card H' * Nat.card H := by
have hcard₀ := Nat.card_congr <| (AddSubgroup.addSubgroupOfEquivOfLe Hlt.le).toEquiv
have hcard₁ := Nat.card_congr <|
(QuotientAddGroup.quotientKerEquivRange (ψ.restrict H'')).toEquiv
have hcard₂ := AddSubgroup.card_eq_card_quotient_mul_card_addSubgroup (H.addSubgroupOf H'')
rw [ψ.ker_restrict H'', QuotientAddGroup.ker_mk', ψ.restrict_range H''] at hcard₁
simpa only [← Nat.card_eq_fintype_card, hcard₀, hcard₁] using hcard₂
calc
log (Nat.card H'')
_ = log ((Nat.card H' : ℝ) * (Nat.card H : ℝ)) := by rw [cardprod]; norm_cast
_ = log (Nat.card H') + log (Nat.card H) := by
rw [Real.log_mul (Nat.cast_ne_zero.2 (@Nat.card_pos H').ne')
(Nat.cast_ne_zero.2 (@Nat.card_pos H).ne')]
_ ≤ (1 + α) / 2 * (H[⇑ψ ∘ X ; μ] + H[⇑ψ ∘ Y ; μ']) + log (Nat.card H) := by gcongr
_ ≤ (1 + α) / 2 * (c * (H[X; μ] + H[Y;μ'])) +
(1 + α) / (2 * (1 - α)) * (1 - c) * (H[X ; μ] + H[Y ; μ']) := by gcongr
_ = (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X ; μ] + H[Y ; μ']) := by
field_simp; ring
have HS : H'' ∉ S := λ Hs => Hlt.ne (hMaxl H'' Hs Hlt.le)
simp only [S, Set.mem_setOf_eq, not_and, not_lt] at HS
refine ⟨?_, HS ⟨α * c, by positivity, cond, ?_⟩⟩
· calc
log (Nat.card H'')
_ ≤ (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := cond
_ ≤ (1 + α) / (2 * (1 - α)) * 1 * (H[X; μ] + H[Y;μ']) := by gcongr; simp; positivity
_ = (1 + α) / (2 * (1 - α)) * (H[X; μ] + H[Y;μ']) := by simp only [mul_one]
· calc
H[ ψ'' ∘ X; μ ] + H[ ψ'' ∘ Y; μ' ]
_ = H[ φ.symm ∘ ψ'' ∘ X; μ ] + H[ φ.symm ∘ ψ'' ∘ Y; μ' ] := by
simp_rw [← entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ φ.symm.injective,
← entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ φ.symm.injective]
_ ≤ α * (H[ ψ ∘ X; μ ] + H[ ψ ∘ Y; μ' ]) := hup'.le
_ ≤ α * (c * (H[X ; μ] + H[Y ; μ'])) := by gcongr
_ = (α * c) * (H[X ; μ] + H[Y ; μ']) := by ring
· use ⊥
constructor
· simp only [AddSubgroup.mem_bot, Nat.card_eq_fintype_card, Fintype.card_ofSubsingleton,
Nat.cast_one, log_one]
positivity
· simp only [S, Set.mem_setOf_eq, not_and, not_lt] at hE
exact hE ⟨1, by norm_num, by
norm_num; exact add_le_add (entropy_comp_le μ hX _) (entropy_comp_le μ' hY _)⟩
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq 2 * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 34 * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
34 * d[(QuotientAddGroup.mk' H) ∘ X;μ # (QuotientAddGroup.mk' H) ∘ Y;μ'] := by
rcases PFR_projection' X Y μ μ' ((3 : ℝ) / 5) hX hY (by norm_num) (by norm_num) with ⟨H, h, h'⟩
refine ⟨H, ?_, ?_⟩
· convert h
norm_num
· have : 0 ≤ d[⇑(QuotientAddGroup.mk' H) ∘ X ; μ # ⇑(QuotientAddGroup.mk' H) ∘ Y ; μ'] :=
rdist_nonneg ((measurable_discrete _).comp hX) ((measurable_discrete _).comp hY)
linarith
end F2_projection
open MeasureTheory ProbabilityTheory Real Set
open scoped BigOperators
lemma four_logs {a b c d : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) (hd : 0 < d) :
log ((a*b)/(c*d)) = log a + log b - log c - log d := by
rw [log_div, log_mul, log_mul, sub_sub] <;> positivity
lemma sum_prob_preimage {G H : Type*} {X : Finset H} {A : Set G} [Finite A] {φ : A → X}
{A_ : H → Set G} (hA : A.Nonempty) (hφ : ∀ x : X, A_ x = Subtype.val '' (φ ⁻¹' {x})) :
∑ x in X, (Nat.card (A_ x) : ℝ) / (Nat.card A) = 1 := by
rw [← Finset.sum_div]
apply (div_eq_one_iff_eq <| Nat.cast_ne_zero.mpr <| Nat.pos_iff_ne_zero.mp (@Nat.card_pos _ hA.to_subtype _)).mpr
classical
haveI := Fintype.ofFinite A
rewrite [Nat.card_eq_fintype_card, ← Finset.card_univ, Finset.card_eq_sum_card_fiberwise
<| fun a _ ↦ Finset.mem_univ (φ a), ← Finset.sum_coe_sort]
norm_cast
congr; ext
rewrite [← Set.Finite.toFinset_setOf, (Set.toFinite _).card_toFinset, ← Nat.card_eq_fintype_card,
hφ, Nat.card_image_of_injective Subtype.val_injective]; rfl
/-- Let $\phi : G\to H$ be a homomorphism and $A,B\subseteq G$ be finite subsets. If $x,y\in H$ then let $A_x=A\cap \phi^{-1}(x)$ and $B_y=B\cap \phi^{-1}(y)$. There exist $x,y\in H$ such that $A_x,B_y$ are both non-empty and
\[d[\phi(U_A);\phi(U_B)]\log \frac{\lvert A\rvert\lvert B\rvert}{\lvert A_x\rvert\lvert B_y\rvert}\leq (\mathbb{H}(\phi(U_A))+\mathbb{H}(\phi(U_B)))(d(U_A,U_B)-d(U_{A_x},U_{B_y}).\] -/
lemma single_fibres {G H Ω Ω': Type u}
[AddCommGroup G] [Countable G] [MeasurableSpace G] [MeasurableSingletonClass G]
[AddCommGroup H] [Countable H] [MeasurableSpace H] [MeasurableSingletonClass H]
[MeasureSpace Ω] [MeasureSpace Ω']
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
(φ : G →+ H)
{A B : Set G} [Finite A] [Finite B] {UA : Ω → G} {UB: Ω' → G} (hA : A.Nonempty) (hB : B.Nonempty)
(hUA': Measurable UA) (hUB': Measurable UB) (hUA: IsUniform A UA) (hUB: IsUniform B UB)
(hUA_mem : ∀ ω, UA ω ∈ A) (hUB_mem : ∀ ω, UB ω ∈ B) :
∃ (x y : H) (Ax By: Set G),
Ax = A ∩ φ.toFun ⁻¹' {x} ∧ By = B ∩ φ.toFun ⁻¹' {y} ∧ Ax.Nonempty ∧ By.Nonempty ∧
d[φ.toFun ∘ UA # φ.toFun ∘ UB]
* log ((Nat.card A) * (Nat.card B) / ((Nat.card Ax) * (Nat.card By))) ≤
(H[φ.toFun ∘ UA] + H[φ.toFun ∘ UB]) * (d[UA # UB] - dᵤ[Ax # By]) := by
have : Nonempty A := hA.to_subtype
have : Nonempty B := hB.to_subtype
haveI : FiniteRange UA := finiteRange_of_finset UA A.toFinite.toFinset (by simpa)
haveI : FiniteRange UB := finiteRange_of_finset UB B.toFinite.toFinset (by simpa)
have hUA_coe : IsUniform A.toFinite.toFinset.toSet UA := by rwa [Set.Finite.coe_toFinset]
have hUB_coe : IsUniform B.toFinite.toFinset.toSet UB := by rwa [Set.Finite.coe_toFinset]
let A_ (x : H) : Set G := A ∩ φ.toFun ⁻¹' {x}
let B_ (y : H) : Set G := B ∩ φ.toFun ⁻¹' {y}
let X : Finset H := FiniteRange.toFinset (φ.toFun ∘ UA)
let Y : Finset H := FiniteRange.toFinset (φ.toFun ∘ UB)
haveI h_Ax (x : X) : Nonempty (A_ x.val) := by
obtain ⟨ω, hω⟩ := (FiniteRange.mem_iff _ _).mp x.property
use UA ω; exact Set.mem_inter (hUA_mem ω) (by exact hω)
haveI h_By (y : Y) : Nonempty (B_ y.val) := by
obtain ⟨ω, hω⟩ := (FiniteRange.mem_iff _ _).mp y.property
use UB ω; exact Set.mem_inter (hUB_mem ω) (by exact hω)
have h_AX (a : A) : φ.toFun a.val ∈ X := by
obtain ⟨ω, hω⟩ := hUA_coe.nonempty_preimage_of_mem hUA' (A.toFinite.mem_toFinset.mpr a.property)
exact (FiniteRange.mem_iff _ (φ.toFun a.val)).mpr ⟨ω, congr_arg _ hω⟩
have h_BY (b : B) : φ.toFun b.val ∈ Y := by
obtain ⟨ω, hω⟩ := hUB_coe.nonempty_preimage_of_mem hUB' (B.toFinite.mem_toFinset.mpr b.property)
exact (FiniteRange.mem_iff _ (φ.toFun b.val)).mpr ⟨ω, congr_arg _ hω⟩
let φ_AX (a : A) : X := by use φ.toFun a.val; exact h_AX a
let φ_BY (b : B) : Y := by use φ.toFun b.val; exact h_BY b
have h_φ_AX (x : X) : A_ x.val = φ_AX ⁻¹' {x} := by ext; simp [A_, φ_AX]; simp [Subtype.ext_iff]
have h_φ_BY (y : Y) : B_ y.val = φ_BY ⁻¹' {y} := by ext; simp [B_, φ_BY]; simp [Subtype.ext_iff]
let p (x : H) (y : H) : ℝ :=
(Nat.card (A_ x).Elem) * (Nat.card (B_ y).Elem) / ((Nat.card A.Elem) * (Nat.card B.Elem))
have :
∑ x in X, ∑ y in Y, (p x y) * dᵤ[A_ x # B_ y] ≤ d[UA # UB] - d[φ.toFun ∘ UA # φ.toFun ∘ UB] :=
calc
_ = d[UA | φ.toFun ∘ UA # UB | φ.toFun ∘ UB] := by
rewrite [condRuzsaDist_eq_sum hUA' ((measurable_discrete _).comp hUA')
hUB' ((measurable_discrete _).comp hUB')]
refine Finset.sum_congr rfl <| fun x hx ↦ Finset.sum_congr rfl <| fun y hy ↦ ?_
haveI : Nonempty (A_ x) := h_Ax ⟨x, hx⟩
haveI : Nonempty (B_ y) := h_By ⟨y, hy⟩
let μx := (ℙ : Measure Ω)[|(φ.toFun ∘ UA) ⁻¹' {x}]
let μy := (ℙ : Measure Ω')[|(φ.toFun ∘ UB) ⁻¹' {y}]
have h_μ_p : IsProbabilityMeasure μx ∧ IsProbabilityMeasure μy := by
constructor <;> apply ProbabilityTheory.cond_isProbabilityMeasure <;> rw [Set.preimage_comp]
refine @IsUniform.measure_preimage_ne_zero _ _ _ _ _ _ _ _ _ _ hUA_coe hUA' _ ?_
swap; refine @IsUniform.measure_preimage_ne_zero _ _ _ _ _ _ _ _ _ _ hUB_coe hUB' _ ?_
all_goals rwa [Set.inter_comm, Set.Finite.coe_toFinset]
have h_μ_unif : IsUniform (A_ x) UA μx ∧ IsUniform (B_ y) UB μy := by
have : _ ∧ _ := ⟨hUA.restrict hUA' (φ.toFun ⁻¹' {x}), hUB.restrict hUB' (φ.toFun ⁻¹' {y})⟩
rwa [Set.inter_comm _ A, Set.inter_comm _ B] at this
rewrite [rdist_set_eq_rdist h_μ_p.1 h_μ_p.2 h_μ_unif.1 h_μ_unif.2 hUA' hUB']
show _ = (Measure.real _ (UA ⁻¹' (_ ⁻¹' _))) * (Measure.real _ (UB ⁻¹' (_ ⁻¹' _))) * _
rewrite [hUA_coe.measureReal_preimage hUA', hUB_coe.measureReal_preimage hUB']
simp_rw [p, A_, B_, IsProbabilityMeasure.measureReal_univ, one_mul]
rewrite [mul_div_mul_comm, Set.inter_comm A, Set.inter_comm B]
simp only [Set.Finite.coe_toFinset, Set.Finite.mem_toFinset, Finset.mem_val]; rfl
_ ≤ d[UA # UB] - d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
rewrite [ZeroHom.toFun_eq_coe, AddMonoidHom.toZeroHom_coe]
linarith only [rdist_le_sum_fibre φ hUA' hUB' (μ := ℙ) (μ' := ℙ)]
let M := H[φ.toFun ∘ UA] + H[φ.toFun ∘ UB]
have hM : M = ∑ x in X, ∑ y in Y, Real.negMulLog (p x y) := by
have h_compl {x y} (h_notin : (x, y) ∉ X ×ˢ Y) : Real.negMulLog (p x y) = 0 := by
unfold_let p; beta_reduce
rewrite [Finset.mem_product, not_and_or] at h_notin
suffices A_ x = ∅ ∨ B_ y = ∅ by obtain h | h := this <;> rw [h] <;> simp
refine h_notin.imp ?_ ?_
· rw [← not_nonempty_iff_eq_empty]
rintro h ⟨a, ha, rfl⟩
exact h (h_AX ⟨a, ha⟩)
· rw [← not_nonempty_iff_eq_empty]
rintro h ⟨a, ha, rfl⟩
exact h (h_BY ⟨a, ha⟩)
unfold_let M
unfold entropy
haveI := isProbabilityMeasure_map (μ := ℙ) ((measurable_discrete φ).comp hUA').aemeasurable
haveI := isProbabilityMeasure_map (μ := ℙ) ((measurable_discrete φ).comp hUB').aemeasurable
rewrite [← Finset.sum_product', ← tsum_eq_sum fun _ ↦ h_compl, ← measureEntropy_prod]
apply tsum_congr; intro; congr
rewrite [← Set.singleton_prod_singleton, Measure.smul_apply, Measure.prod_prod,
Measure.map_apply ((measurable_discrete _).comp hUA') (MeasurableSet.singleton _),
Measure.map_apply ((measurable_discrete _).comp hUB') (MeasurableSet.singleton _),
Set.preimage_comp, hUA_coe.measure_preimage hUA',
Set.preimage_comp, hUB_coe.measure_preimage hUB']
simp [p, A_, B_, mul_div_mul_comm, Set.inter_comm, ENNReal.toReal_div]
have h_sum : ∑ x in X, ∑ y in Y,
(p x y) * (M * dᵤ[A_ x # B_ y] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p x y)) ≤
M * d[UA # UB] :=
calc
_ = ∑ x in X, ∑ y in Y, (p x y) * M * dᵤ[A_ x # B_ y] + M * d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
simp_rw [hM, Finset.sum_mul, ← Finset.sum_add_distrib]
refine Finset.sum_congr rfl <| fun _ _ ↦ Finset.sum_congr rfl <| fun _ _ ↦ ?_
simp only [negMulLog, left_distrib, mul_assoc, Finset.sum_mul]
exact congrArg (HAdd.hAdd _) (by group)
_ = M * ∑ x in X, ∑ y in Y, (p x y) * dᵤ[A_ x # B_ y] + M * d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
simp_rw [Finset.mul_sum]
congr; ext; congr; ext; group
_ ≤ M * d[UA # UB] := by
rewrite [← left_distrib]
apply mul_le_mul_of_nonneg_left
· linarith
· unfold_let M
linarith only [entropy_nonneg (φ.toFun ∘ UA) ℙ, entropy_nonneg (φ.toFun ∘ UB) ℙ]
have : ∃ x : X, ∃ y : Y,
M * dᵤ[A_ x.val # B_ y.val] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p x.val y.val) ≤
M * d[UA # UB] := by
let f (xy : H × H) := (p xy.1 xy.2) * (M * d[UA # UB])
let g (xy : H × H) := (p xy.1 xy.2) *
(M * dᵤ[A_ xy.1 # B_ xy.2] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p xy.1 xy.2))
by_contra hc; push_neg at hc
replace hc : ∀ xy ∈ X ×ˢ Y, f xy < g xy := by
refine fun xy h ↦ mul_lt_mul_of_pos_left ?_ ?_
· exact hc ⟨xy.1, (Finset.mem_product.mp h).1⟩ ⟨xy.2, (Finset.mem_product.mp h).2⟩
· haveI : Nonempty _ := h_Ax ⟨xy.1, (Finset.mem_product.mp h).1⟩
haveI : Nonempty _ := h_By ⟨xy.2, (Finset.mem_product.mp h).2⟩
simp only [p, div_pos, mul_pos, Nat.cast_pos, Nat.card_pos]
have h_nonempty : Finset.Nonempty (X ×ˢ Y) := by
use ⟨φ.toFun <| UA <| Classical.choice <| ProbabilityMeasure.nonempty ⟨ℙ, inferInstance⟩,
φ.toFun <| UB <| Classical.choice <| ProbabilityMeasure.nonempty ⟨ℙ, inferInstance⟩⟩
exact Finset.mem_product.mpr ⟨FiniteRange.mem _ _, FiniteRange.mem _ _⟩
replace hc := Finset.sum_lt_sum_of_nonempty h_nonempty hc
have h_p_one : ∑ x in X ×ˢ Y, p x.1 x.2 = 1 := by
simp_rw [Finset.sum_product, p, mul_div_mul_comm, ← Finset.mul_sum,
← sum_prob_preimage hA h_φ_AX, sum_prob_preimage hB h_φ_BY, mul_one]
rewrite [← Finset.sum_mul, h_p_one, one_mul, Finset.sum_product] at hc
exact not_le_of_gt hc h_sum
obtain ⟨x, y, hxy⟩ := this
refine ⟨x, y, A_ x.val, B_ y.val, rfl, rfl, @nonempty_of_nonempty_subtype _ _ (h_Ax x), @nonempty_of_nonempty_subtype _ _ (h_By y), ?_⟩
rewrite [← inv_div, Real.log_inv]
show _ * -log (p x.val y.val) ≤ M * _
linarith only [hxy]
section dim
open Classical
variable {G : Type*} [AddCommGroup G]
/- If G ≅ ℤᵈ then there is a subgroup H of G such that A lies in a coset of H. This is helpful to
give the equivalent definition of `dimension`. Here this is stated in greated generality since the
proof carries over automatically-/
lemma exists_coset_cover (A : Set G) :
∃ (d : ℕ), ∃ (S : Submodule ℤ G) (v : G),
FiniteDimensional.finrank ℤ S = d ∧ ∀ a ∈ A, a - v ∈ S := by
existsi FiniteDimensional.finrank ℤ (⊤ : Submodule ℤ G), ⊤, 0
refine ⟨rfl, fun a _ ↦ trivial⟩
/-- The dimension of the affine span over `ℤ` of a subset of an additive group. -/
noncomputable def dimension (A : Set G) : ℕ := Nat.find (exists_coset_cover A)
lemma dimension_le_of_coset_cover (A : Set G) (S : Submodule ℤ G) (v : G)
(hA : ∀ a ∈ A, a - v ∈ S) : dimension A ≤ FiniteDimensional.finrank ℤ S := by
apply Nat.find_le
existsi S , v
exact ⟨rfl, hA⟩
lemma dimension_le_rank [Module.Finite ℤ G] (A : Set G) :
dimension A ≤ FiniteDimensional.finrank ℤ G := by
obtain ⟨S, v, hs, _⟩ := Nat.find_spec (exists_coset_cover A)
rw [dimension, ←hs]
apply Submodule.finrank_le S
end dim
variable {G : Type u} [AddCommGroup G] [Module.Free ℤ G] [Module.Finite ℤ G] [Countable G] [MeasurableSpace G] [MeasurableSingletonClass G]
open Real MeasureTheory ProbabilityTheory Pointwise Set
/-- Move to Mathlib? `Finsupp.mapRange` of a surjective function is surjective. -/
lemma Finsupp.mapRange_surjective {α : Type u_1} {M : Type u_5} {N : Type u_7} [Zero M] [Zero N] (f : M → N) (hf : f 0 = 0)
(hs : Function.Surjective f) : Function.Surjective (Finsupp.mapRange (α := α) f hf) := by
classical
let g (n : N) : M := if n = 0 then 0 else Function.surjInv hs n
have : Function.RightInverse g f := by
intro n
by_cases h : n = 0
. simp [g, h, hf]
· simp [g, h, Function.surjInv_eq hs n]
have hg : g 0 = 0 := by simp [g]
have hfg : (f ∘ g) 0 = 0 := by simp [hf, hg]
intro F
use Finsupp.mapRange g hg F
rw [← Finsupp.mapRange_comp (h := hfg)]
convert Finsupp.mapRange_id F
convert Function.RightInverse.id this
/-- A free Z-module is torsion-free. Move to Mathlib? -/
lemma torsion_free : AddMonoid.IsTorsionFree G := by
rintro x hx hn
rw [isOfFinAddOrder_iff_nsmul_eq_zero] at hn
rcases hn with ⟨ n, hn, hn' ⟩
apply_fun Module.Free.repr ℤ G at hn'
simp_rw [map_nsmul, map_zero, smul_eq_zero, AddEquivClass.map_eq_zero_iff, hx, or_false] at hn'
linarith
/-- If G is a rank n free Z-module, then G/2G is a finite elementary 2-group of cardinality 2^n. Code is slow, needs to be golfed -/
lemma weak_PFR_quotient_prelim :
let H := G ⧸ (AddMonoidHom.range (zsmulAddGroupHom 2))
ElementaryAddCommGroup H 2 ∧ Finite H ∧ Nat.card H = 2^(FiniteDimensional.finrank ℤ G) := by
set ψ : G →+ G := zsmulAddGroupHom 2
set G₂ := AddMonoidHom.range ψ
set H := G ⧸ G₂
set φ : G →+ H := QuotientAddGroup.mk' G₂
have hH_elem : ElementaryAddCommGroup H 2 := by
apply ElementaryAddCommGroup.quotient_group (by decide)
intro x; rw [AddMonoidHom.mem_range]
use x
rw [zsmulAddGroupHom_apply]
norm_cast
let B := Module.Free.ChooseBasisIndex ℤ G
let bG : Basis B ℤ G := Module.Free.chooseBasis ℤ G
have hB_fin : Fintype B := by infer_instance
have hB_card : Nat.card B = FiniteDimensional.finrank ℤ G := by
rw [FiniteDimensional.finrank_eq_card_basis bG, Nat.card_eq_fintype_card]
have hH_module : Module (ZMod 2) H := by infer_instance
let mod : (B →₀ ℤ) →+ (B →₀ ZMod 2) := Finsupp.mapRange.addMonoidHom (Int.castAddHom (ZMod 2))
let f : G →+ (B →₀ ℤ) := bG.repr
have hker : G₂ ≤ AddMonoidHom.ker (AddMonoidHom.comp mod f) := by
intro x hx
simp only [AddMonoidHom.mem_range, G₂, ψ, zsmulAddGroupHom_apply] at hx
simp_rw [AddMonoidHom.mem_ker, AddMonoidHom.coe_comp, Function.comp_apply, mod,
Finsupp.mapRange.addMonoidHom_apply, Int.coe_castAddHom]
rcases hx with ⟨y, rfl⟩
ext b
simp_rw [map_zsmul, Finsupp.mapRange_apply, Finsupp.coe_smul, Pi.smul_apply, smul_eq_mul,
Int.cast_mul, Int.cast_ofNat, Finsupp.coe_zero, Pi.zero_apply, mul_eq_zero]
left
exact ZMod.nat_cast_self 2
let g : H →+ (B →₀ ZMod 2) := QuotientAddGroup.lift G₂ (AddMonoidHom.comp mod f) hker
have hsur : Function.Surjective g := by
have h1 : Function.Surjective mod := Finsupp.mapRange_surjective (Int.castAddHom (ZMod 2)) (map_zero _) ZMod.int_cast_surjective
have h2 := h1.comp bG.repr.surjective
have h3 : mod ∘ bG.repr = g ∘ (QuotientAddGroup.mk' G₂) := by
ext x b
simp_rw [mod, Function.comp_apply, Finsupp.mapRange.addMonoidHom_apply, Int.coe_castAddHom,
Finsupp.mapRange_apply, QuotientAddGroup.coe_mk', g]
rw [QuotientAddGroup.lift_mk]
simp [mod, f]
rw [h3] at h2
apply Function.Surjective.of_comp h2
have hinj : Function.Injective g := by
rw [injective_iff_map_eq_zero]
intro x hx
rcases QuotientAddGroup.mk'_surjective G₂ x with ⟨y, rfl⟩
simp only [QuotientAddGroup.mk'_apply, g] at hx
rw [QuotientAddGroup.lift_mk] at hx
simp_rw [AddMonoidHom.coe_comp, Function.comp_apply, mod, Finsupp.mapRange.addMonoidHom_apply,
Int.coe_castAddHom, DFunLike.ext_iff,Finsupp.mapRange_apply, Finsupp.coe_zero, Pi.zero_apply,
ZMod.int_cast_zmod_eq_zero_iff_dvd] at hx
replace hx := fun x ↦ Int.mul_ediv_cancel' (hx x)
let z (b : B) := ((Module.Free.chooseBasis ℤ G).repr y) b / 2
let z' := (Finsupp.equivFunOnFinite).symm z
change ∀ b : B, 2 * z' b = (f y) b at hx
let x' := bG.repr.symm z'
rw [QuotientAddGroup.mk'_apply, QuotientAddGroup.eq_zero_iff, AddMonoidHom.mem_range]
simp_rw [ψ, zsmulAddGroupHom_apply]
use x'
change 2 • (bG.repr.symm.toLinearMap.toAddMonoidHom z') = y
rw [← AddMonoidHom.map_zsmul bG.repr.symm.toLinearMap.toAddMonoidHom z' (2 : ℤ)]
rw [← LinearEquiv.symm_apply_apply bG.repr y]
change bG.repr.symm (2 • z') = bG.repr.symm (f y)
congr
ext b
rw [Finsupp.smul_apply, ← hx b, smul_eq_mul]
rcases Function.bijective_iff_has_inverse.mp ⟨ hinj, hsur ⟩ with ⟨ g', hg' ⟩
have bH : Basis B (ZMod 2) H := by
constructor
exact {
toFun := g
invFun := g'
left_inv := hg'.1
right_inv := hg'.2
map_add' := AddMonoidHom.map_add _
map_smul' := by
intro r x
rcases ZMod.int_cast_surjective r with ⟨ n, rfl ⟩
change g ((n : ZMod 2) • x) = (n : ZMod 2) • g x
rw [intCast_smul, intCast_smul]
exact AddMonoidHom.map_zsmul g x n
}
have hH_fin : Fintype H := Module.fintypeOfFintype bH
have hH_card : Nat.card H = 2^(FiniteDimensional.finrank ℤ G) := by
rw [Nat.card_eq_fintype_card, Module.card_fintype bH, ← Nat.card_eq_fintype_card (α := B), hB_card]
congr
exact ⟨ hH_elem, Finite.of_fintype H, hH_card ⟩
open QuotientAddGroup
/-- A version of the third isomorphism theorem: if G₂ ≤ G and H' is a subgroup of G⧸G₂, then there is a canonical isomorphism between H⧸H' and G⧸N, where N is the preimage of H' in G. A bit clunky; may be a better way to do this -/
lemma third_iso {G : Type u} [AddCommGroup G] {G₂ : AddSubgroup G} (H' : AddSubgroup (G ⧸ G₂)) :
let H := G ⧸ G₂
let φ : G →+ H := mk' G₂
let N := AddSubgroup.comap φ H'
∃ e : H ⧸ H' ≃+ G ⧸ N, ∀ x : G, e (mk' H' (φ x))= mk' N x := by
set H := G ⧸ G₂
let φ : G →+ H := mk' G₂
let N := AddSubgroup.comap φ H'
have h1 : G₂ ≤ N := by
intro x hx
rw [← eq_zero_iff] at hx
have : φ x = 0 := hx
simp [N, this, AddSubgroup.zero_mem H']
set H'' := AddSubgroup.map (mk' G₂) N
have h2 : H' = H'' := by
change H' = AddSubgroup.map (mk' G₂) N
rw [AddSubgroup.map_comap_eq, AddMonoidHom.range_top_of_surjective _ (mk'_surjective G₂)]
simp
let e1 : H ⧸ H'' ≃+ G ⧸ N := quotientQuotientEquivQuotient _ _ h1
let e2 := quotientAddEquivOfEq h2
set e := e2.trans e1
use e
intro x
convert (quotientQuotientEquivQuotientAux_mk_mk _ _ h1 x) using 1
| lemma single {Ω : Type u} [MeasurableSpace Ω] [DiscreteMeasurableSpace Ω] (μ : Measure Ω)
[IsProbabilityMeasure μ] {A : Set Ω} {z : Ω} (hA : μ.real A = 1) (hz : μ.real {z} > 0) :
z ∈ A | single | 25309ad 20231211 | c0c547a 20240116 | pfr/PFR/WeakPFR.lean | {
"lineInFile": 769,
"tokenPositionInFile": 41187,
"theoremPositionInFile": 23
} | {
"inFilePremises": false,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n contrapose! hz\n have : Disjoint {z} A := by simp [hz]\n replace this := measureReal_union (μ := μ) this (measurableSet_discrete _)\n simp [hA] at this\n have h := measureReal_mono (μ := μ) (show insert z A ⊆ Set.univ by simp)\n simp [this] at h\n assumption",
"proofType": "tactic",
"proofLengthLines": 8,
"proofLengthTokens": 263
} | pfr |
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Quotient
import Mathlib.GroupTheory.Torsion
import Mathlib.GroupTheory.Torsion
import Mathlib.LinearAlgebra.FreeModule.PID
import PFR.Mathlib.Data.Set.Pointwise.SMul
import PFR.EntropyPFR
import PFR.ImprovedPFR
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Mathlib.GroupTheory.Torsion
/-!
# Weak PFR over the integers
Here we use the entropic form of PFR to deduce a weak form of PFR over the integers.
## Main statement
* `weak_PFR_int`: Let $A\subseteq \mathbb{Z}^d$ and $\lvert A+A\rvert\leq K\lvert A\rvert$.
There exists $A'\subseteq A$ such that $\lvert A'\rvert \geq K^{-17}\lvert A\rvert$ and
$\dim A' \leq (40/\log 2)\log K$.
-/
section AddCommGroup
variable {G : Type*} [AddCommGroup G] {A B : Set G}
open Set
open scoped Pointwise
def IsShift (A B : Set G) : Prop := ∃ x : G, A = x +ᵥ B
lemma IsShift.sub_self_congr : IsShift A B → A - A = B - B := by
rintro ⟨x, rfl⟩; simp [vadd_sub_vadd_comm, singleton_zero]
lemma IsShift.card_congr : IsShift A B → Nat.card A = Nat.card B := by rintro ⟨x, rfl⟩; simp
/-- The property of two sets A, B of a group G not being contained in cosets of the same proper
subgroup -/
def NotInCoset (A B : Set G) : Prop := AddSubgroup.closure ((A - A) ∪ (B - B)) = ⊤
/-- Without loss of generality, one can move (up to translation and embedding) any pair A, B of non-empty sets into a subgroup where they are not in a coset. -/
lemma wlog_notInCoset (hA : A.Nonempty) (hB : B.Nonempty) :
∃ (G' : AddSubgroup G) (A' B' : Set G'), IsShift A A' ∧ IsShift B B' ∧ NotInCoset A' B' := by
obtain ⟨x, hx⟩ := hA
obtain ⟨y, hy⟩ := hB
set G' := AddSubgroup.closure ((A - A) ∪ (B - B))
set A' : Set G' := (↑) ⁻¹' ((-x) +ᵥ A)
set B' : Set G' := (↑) ⁻¹' ((-y) +ᵥ B)
have hxA : -x +ᵥ A ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hx).trans $ (subset_union_left ..).trans
AddSubgroup.subset_closure
have hyB : -y +ᵥ B ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hy).trans $ (subset_union_right ..).trans
AddSubgroup.subset_closure
have hA : IsShift A A' := ⟨x, by rw [Set.image_preimage_eq_of_subset hxA, vadd_neg_vadd]⟩
have hB : IsShift B B' := ⟨y, by rw [Set.image_preimage_eq_of_subset hyB, vadd_neg_vadd]⟩
refine ⟨G', A', B', hA, hB, ?_⟩
unfold NotInCoset
convert AddSubgroup.closure_preimage_eq_top ((A - A) ∪ (B - B))
simp_rw [preimage_union, hA.sub_self_congr, hB.sub_self_congr]
rw [preimage_sub, preimage_sub]
simp [A', B', preimage_image_preimage]
all_goals apply_rules [Subtype.coe_injective, (image_preimage_subset ..).trans, hxA, hyB]
end AddCommGroup
section Torsion
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [MeasurableSpace G] [MeasurableSingletonClass G]
[Countable G] {Ω Ω' : Type u} [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ': Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
/-- If $G$ is torsion-free and $X,Y$ are $G$-valued random variables then $d[X;2Y]\leq 5d[X;Y]$. -/
lemma torsion_free_doubling [FiniteRange X] [FiniteRange Y]
(hX : Measurable X) (hY : Measurable Y) (hG : AddMonoid.IsTorsionFree G) :
d[X ; μ # (Y + Y) ; μ'] ≤ 5 * d[X; μ # Y ; μ'] := by
obtain ⟨A, mA, μA, X', Y'₁, Y'₂, hμA, h_indep, hX'_meas, hY'₁_meas, hY'₂_meas, hX'_ident,
hY'₁_ident, hY'₂_ident, _, _, _⟩ := independent_copies3_nondep_finiteRange hX hY hY μ μ' μ'
have h_meas (i : Fin 3) : Measurable (![X', Y'₁, Y'₂] i) := by fin_cases i <;> assumption
haveI : NoZeroSMulDivisors ℕ G := hG.noZeroNsmulDivisors
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨x, y₁, y₂⟩ ↦ (x, y₁ - y₂, x - 2 • y₁)
show H[f ∘ ⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] = _
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hX'_meas <| Measurable.prod hY'₁_meas hY'₂_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun X' (prod Y'₁ Y'₂) μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 1 2 0 (by decide) (by decide)
rw [this.entropy_pair_eq_add hX'_meas (by exact Measurable.prod hY'₁_meas hY'₂_meas),
IndepFun.entropy_pair_eq_add hY'₁_meas hY'₂_meas (h_indep.indepFun (show 1 ≠ 2 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, two_mul]
have : H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[X ; μ] + H[Y ; μ'] := calc
H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[⟨X', Y'₁⟩ ; μA] := by
let f : G × G → G × G := fun ⟨x, y₁⟩ ↦ (x, x - 2 • y₁)
show H[f ∘ ⟨X', Y'₁⟩ ; μA] = _
apply entropy_comp_of_injective μA (by exact Measurable.prod hX'_meas hY'₁_meas) f
exact fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + H[Y ; μ'] := by
rw [IndepFun.entropy_pair_eq_add hX'_meas hY'₁_meas (h_indep.indepFun (show 0 ≠ 1 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq]
let f : G × G → G × G := fun ⟨x, y⟩ ↦ (x, y - x)
have hf : f.Injective := fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all
have : H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] := calc
H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] = H[f ∘ ⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
show _ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂ - (Y'₁ - Y'₂)⟩ ; μA]
rw [sub_sub_sub_cancel_right, ← sub_add_eq_sub_sub, two_nsmul]
_ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
refine entropy_comp_of_injective μA (Measurable.prod ?_ ?_) f hf
· exact Measurable.sub hY'₁_meas hY'₂_meas
· exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
_ ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] :=
entropy_pair_le_add (hY'₁_meas.sub' hY'₂_meas) (hX'_meas.sub' hY'₁_meas |>.sub' hY'₂_meas) μA
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] + H[X' - 2 • Y'₁ ; μA] ≤
H[⟨X', X' - 2 • Y'₁⟩ ; μA] + H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] := by
haveI : FiniteRange (Y'₁ - Y'₂) := FiniteRange.sub Y'₁ Y'₂
haveI : FiniteRange (2 • Y'₁) := by show FiniteRange ((fun x ↦ 2 • x) ∘ Y'₁); infer_instance
apply entropy_triple_add_entropy_le μA hX'_meas (Measurable.sub hY'₁_meas hY'₂_meas)
exact Measurable.sub' hX'_meas <| Measurable.const_smul hY'₁_meas 2
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨y₁, y₂, x⟩ ↦ (y₁, y₂, x - y₁ - y₂)
show H[f ∘ ⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA]
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hY'₁_meas <| Measurable.prod hY'₂_meas hX'_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun Y'₁ (prod Y'₂ X') μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 2 0 1 (by decide) (by decide)
rw [this.entropy_pair_eq_add hY'₁_meas (by exact Measurable.prod hY'₂_meas hX'_meas),
IndepFun.entropy_pair_eq_add hY'₂_meas hX'_meas (h_indep.indepFun (show 2 ≠ 0 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq]
group
have : H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₂ ; μA] := calc
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₁, X' - Y'₂⟩ ; μA] := by rw [sub_right_comm] ; rfl
_ = H[⟨Y'₁, X' - Y'₂⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₁_meas <| Measurable.sub hX'_meas hY'₂_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₂ ; μA] := by
haveI : FiniteRange (X' - Y'₂) := FiniteRange.sub X' Y'₂
convert IndepFun.entropy_pair_eq_add hY'₁_meas (hX'_meas.sub hY'₂_meas)
<| h_indep.indepFun_sub_right h_meas 1 0 2 (by decide) (by decide)
exact hY'₁_ident.entropy_eq.symm
have : H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₁ ; μA] := calc
H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₂, X' - Y'₁⟩ ; μA] := rfl
_ = H[⟨Y'₂, X' - Y'₁⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₂_meas <| Measurable.sub hX'_meas hY'₁_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₁ ; μA] := by
haveI : FiniteRange (X' - Y'₁) := FiniteRange.sub X' Y'₁
convert IndepFun.entropy_pair_eq_add hY'₂_meas (hX'_meas.sub hY'₁_meas)
<| h_indep.indepFun_sub_right h_meas 2 0 1 (by decide) (by decide)
exact hY'₂_ident.entropy_eq.symm
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] ≤
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] + H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
apply entropy_triple_add_entropy_le μA hY'₁_meas hY'₂_meas
exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
have : H[X' - Y'₁ - Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := calc
H[X' - Y'₁ - Y'₂ ; μA] ≤ H[X' - Y'₁ ; μA] + H[X' - Y'₂ ; μA] - H[X ; μ] := by linarith
_ = 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := by
nth_rw 1 [two_mul, ← hX'_ident.rdist_eq hY'₁_ident, ← hX'_ident.rdist_eq hY'₂_ident]
have h1 : d[X' ; μA # Y'₁ ; μA] = H[X' - Y'₁ ; μA] - H[X' ; μA] / 2 - H[Y'₁ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 1 by decide)).rdist_eq hX'_meas hY'₁_meas
have h2 : d[X' ; μA # Y'₂ ; μA] = H[X' - Y'₂ ; μA] - H[X' ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 2 by decide)).rdist_eq hX'_meas hY'₂_meas
rw [h1, h2, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, hX'_ident.entropy_eq]
group
have : d[X ; μ # 2 • Y ; μ'] ≤
d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := calc
d[X ; μ # 2 • Y ; μ'] = H[X' - 2 • Y'₁ ; μA] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by
have h2Y_ident : IdentDistrib (2 • Y'₁) (2 • Y) (μ := μA) (ν := μ') := by
convert hY'₁_ident.comp <| measurable_discrete <| fun g ↦ 2 • g
have h2Y_indep : IndepFun X' (2 • Y'₁) (μ := μA) := by
convert (h_indep.indepFun (show 0 ≠ 1 by decide)).comp measurable_id
(measurable_const_smul 2)
rw [← hX'_ident.rdist_eq h2Y_ident,
h2Y_indep.rdist_eq hX'_meas <| Measurable.const_smul hY'₁_meas 2,
hX'_ident.entropy_eq, h2Y_ident.entropy_eq]
_ ≤ H[Y'₁ - Y'₂ ; μA] + 2 * d[X ; μ # Y ; μ'] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by linarith
_ = d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := by
have H2Y : H[2 • Y ; μ'] = H[Y ; μ'] := by
let f (g : G) := 2 • g
exact entropy_comp_of_injective μ' hY f (fun _ _ ↦ by simp [f, smul_right_inj])
have : d[Y'₁ ; μA # Y'₂ ; μA] = H[Y'₁ - Y'₂ ; μA] - H[Y'₁ ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 1 ≠ 2 by decide)).rdist_eq hY'₁_meas hY'₂_meas
rw [this, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, H2Y]
group
have : d[Y'₁ ; μA # Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] := by
rw [two_mul]
convert rdist_triangle hY'₁_meas hX'_meas hY'₂_meas (μ := μA) (μ' := μA) (μ'' := μA)
· exact rdist_symm.trans (hY'₁_ident.rdist_eq hX'_ident).symm
· exact (hX'_ident.rdist_eq hY'₂_ident).symm
rw [← two_nsmul]
linarith [abs_le.mp <| diff_ent_le_rdist hX hY (μ := μ) (μ' := μ')]
/-- If $G$ is a torsion-free group and $X,Y$ are $G$-valued random variables and
$\phi : G\to \mathbb{F}_2^d$ is a homomorphism then
\[\mathbb{H}(\phi(X))\leq 10d[X;Y].\] -/
lemma torsion_dist_shrinking {H : Type u} [FiniteRange X] [FiniteRange Y] (hX : Measurable X)
(hY : Measurable Y) [AddCommGroup H] [ElementaryAddCommGroup H 2]
[MeasurableSpace H] [MeasurableSingletonClass H] [Countable H]
(hG : AddMonoid.IsTorsionFree G) (φ : G →+ H) :
H[φ ∘ X ; μ] ≤ 10 * d[X; μ # Y ; μ'] := by
have :=
calc d[φ ∘ X ; μ # φ ∘ (Y + Y); μ'] ≤ d[X; μ # (Y + Y) ; μ'] := rdist_of_hom_le φ hX (Measurable.add hY hY)
_ ≤ 5 * d[X; μ # Y ; μ'] := torsion_free_doubling X Y μ μ' hX hY hG
have eq_zero : φ ∘ (Y + Y) = fun _ ↦ 0 := by ext x ; simp only [Function.comp_apply, Pi.add_apply,
map_add, ElementaryAddCommGroup.add_self]
rwa [eq_zero, rdist_zero_eq_half_ent, div_le_iff zero_lt_two, mul_assoc, mul_comm _ 2, ←mul_assoc,
show (5*2 : ℝ) = 10 by norm_num] at this
end Torsion
instance {G : Type u} [AddCommGroup G] [Fintype G] [MeasurableSpace G] [MeasurableSingletonClass G] (H : AddSubgroup G)
: MeasurableSingletonClass (G ⧸ H) :=
⟨λ _ ↦ by { rw [measurableSet_quotient]; simp [measurableSet_discrete] }⟩
section F2_projection
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [ElementaryAddCommGroup G 2] [Fintype G] [MeasurableSpace G]
[MeasurableSingletonClass G] {Ω Ω' : Type*}
/-- Let $G=\mathbb{F}_2^n$ and $X,Y$ be $G$-valued random variables such that
\[\mathbb{H}(X)+\mathbb{H}(Y)> (20/\alpha) d[X;Y],\]
for some $\alpha > 0$.
There is a non-trivial subgroup $H\leq G$ such that
\[\log \lvert H\rvert <(1+\alpha)/2 (\mathbb{H}(X)+\mathbb{H}(Y))\] and
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))< \alpha (\mathbb{H}(X)+\mathbb{H}(Y))\]
where $\psi:G\to G/H$ is the natural projection homomorphism.
-/
lemma app_ent_PFR' [MeasureSpace Ω] [MeasureSpace Ω'] (X : Ω → G) (Y : Ω' → G)
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
{α : ℝ} (hent : 20 * d[X # Y] < α * (H[X] + H[Y])) (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X] + H[Y]) ∧
H[(QuotientAddGroup.mk' H) ∘ X] + H[(QuotientAddGroup.mk' H) ∘ Y] < α * (H[X] + H[Y]) := by
let p : refPackage Ω Ω' G := {
X₀₁ := X
X₀₂ := Y
hmeas1 := hX
hmeas2 := hY
η := 1/8
hη := by norm_num
hη' := by norm_num }
obtain ⟨H, Ω'', hΩ'', U, _, hUmeas, hUunif, ineq⟩ := entropic_PFR_conjecture_improv p rfl
let ψ := (QuotientAddGroup.mk' H)
use H
haveI : Finite H := Subtype.finite
-- Note that H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y]
have ent_le : H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y] := calc
H[ψ ∘ X] + H[ψ ∘ Y] ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· exact ent_of_proj_le hX hUmeas hUunif
· exact ent_of_proj_le hY hUmeas hUunif
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- Note that (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y]
have log_sub_le : (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y] := calc
(log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) =
(H[U] - H[X]) + (H[U] - H[Y]) := by
rw [IsUniform.entropy_eq' hUunif hUmeas, SetLike.coe_sort_coe]
_ ≤ |(H[U] - H[X])| + |(H[U] - H[Y])| := by gcongr <;> exact le_abs_self _
_ ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hX
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hY
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- then the conclusion follows from the assumption `hent` and basic inequality manipulations
exact ⟨by linarith, by linarith⟩
variable [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ' : Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
lemma app_ent_PFR (α : ℝ) (hent: 20 * d[X;μ # Y;μ'] < α * (H[X; μ] + H[Y; μ'])) (hX : Measurable X)
(hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ']
< α * (H[ X; μ] + H[Y; μ']) :=
@app_ent_PFR' _ _ _ _ _ _ _ _ (MeasureSpace.mk μ) (MeasureSpace.mk μ') _ _ _ _ α hent hX hY
set_option maxHeartbeats 300000 in
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables and $\alpha < 1$ then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq (1 + α) / (2 * (1 - α)) * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 20/\alpha * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection'
(α : ℝ) (hX : Measurable X) (hY : Measurable Y) (αpos : 0 < α) (αone : α < 1) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (H[X ; μ] + H[Y ; μ']) ∧
α * (H[(QuotientAddGroup.mk' H) ∘ X ; μ] + H[(QuotientAddGroup.mk' H) ∘ Y ; μ']) ≤
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] := by
let S := { H : AddSubgroup G | (∃ (c : ℝ), 0 ≤ c ∧
log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (1 - c) * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
c * (H[X; μ] + H[Y;μ'])) ∧
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] <
α * (H[ (QuotientAddGroup.mk' H) ∘ X; μ ] + H[ (QuotientAddGroup.mk' H) ∘ Y; μ']) }
have : 0 ≤ H[X ; μ] + H[Y ; μ'] := by linarith [entropy_nonneg X μ, entropy_nonneg Y μ']
have : 0 < 1 - α := sub_pos.mpr αone
by_cases hE : (⊥ : AddSubgroup G) ∈ S
· classical
obtain ⟨H, ⟨⟨c, hc, hlog, hup⟩, hent⟩, hMaxl⟩ :=
S.toFinite.exists_maximal_wrt id S (Set.nonempty_of_mem hE)
set ψ : G →+ G ⧸ H := QuotientAddGroup.mk' H
have surj : Function.Surjective ψ := QuotientAddGroup.mk'_surjective H
set G' := G ⧸ H
have : ElementaryAddCommGroup G' 2 := ElementaryAddCommGroup.quotient_group (by decide)
(by simp [AddSubgroup.zero_mem])
obtain ⟨H', hlog', hup'⟩ := app_ent_PFR _ _ _ _ α hent ((measurable_discrete _).comp hX)
((measurable_discrete _).comp hY)
have H_ne_bot: H' ≠ ⊥ := by
by_contra!
rcases this with rfl
have inj : Function.Injective (QuotientAddGroup.mk' (⊥ : AddSubgroup G')) :=
(QuotientAddGroup.quotientBot : (G' ⧸ ⊥) ≃+ G').symm.injective
rw [entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ inj,
entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ inj] at hup'
nlinarith [entropy_nonneg (ψ ∘ X) μ, entropy_nonneg (ψ ∘ Y) μ']
let H'' := H'.comap ψ
use H''
rw [← (AddSubgroup.map_comap_eq_self_of_surjective surj _ : H''.map ψ = H')] at hup' hlog'
set H' := H''.map ψ
have Hlt : H < H'' := by
have : H = (⊥ : AddSubgroup G').comap ψ := by
simp only [ψ, AddMonoidHom.comap_bot, QuotientAddGroup.ker_mk']
rw [this, AddSubgroup.comap_lt_comap_of_surjective surj]
exact Ne.bot_lt H_ne_bot
let φ : G' ⧸ H' ≃+ G ⧸ H'' := QuotientAddGroup.quotientQuotientEquivQuotient H H'' Hlt.le
set ψ' : G' →+ G' ⧸ H' := QuotientAddGroup.mk' H'
set ψ'' : G →+ G ⧸ H'' := QuotientAddGroup.mk' H''
have diag : ψ' ∘ ψ = φ.symm ∘ ψ'' := rfl
rw [← Function.comp.assoc, ← Function.comp.assoc, diag, Function.comp.assoc,
Function.comp.assoc] at hup'
have cond : log (Nat.card H'') ≤
(1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := by
have cardprod : Nat.card H'' = Nat.card H' * Nat.card H := by
have hcard₀ := Nat.card_congr <| (AddSubgroup.addSubgroupOfEquivOfLe Hlt.le).toEquiv
have hcard₁ := Nat.card_congr <|
(QuotientAddGroup.quotientKerEquivRange (ψ.restrict H'')).toEquiv
have hcard₂ := AddSubgroup.card_eq_card_quotient_mul_card_addSubgroup (H.addSubgroupOf H'')
rw [ψ.ker_restrict H'', QuotientAddGroup.ker_mk', ψ.restrict_range H''] at hcard₁
simpa only [← Nat.card_eq_fintype_card, hcard₀, hcard₁] using hcard₂
calc
log (Nat.card H'')
_ = log ((Nat.card H' : ℝ) * (Nat.card H : ℝ)) := by rw [cardprod]; norm_cast
_ = log (Nat.card H') + log (Nat.card H) := by
rw [Real.log_mul (Nat.cast_ne_zero.2 (@Nat.card_pos H').ne')
(Nat.cast_ne_zero.2 (@Nat.card_pos H).ne')]
_ ≤ (1 + α) / 2 * (H[⇑ψ ∘ X ; μ] + H[⇑ψ ∘ Y ; μ']) + log (Nat.card H) := by gcongr
_ ≤ (1 + α) / 2 * (c * (H[X; μ] + H[Y;μ'])) +
(1 + α) / (2 * (1 - α)) * (1 - c) * (H[X ; μ] + H[Y ; μ']) := by gcongr
_ = (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X ; μ] + H[Y ; μ']) := by
field_simp; ring
have HS : H'' ∉ S := λ Hs => Hlt.ne (hMaxl H'' Hs Hlt.le)
simp only [S, Set.mem_setOf_eq, not_and, not_lt] at HS
refine ⟨?_, HS ⟨α * c, by positivity, cond, ?_⟩⟩
· calc
log (Nat.card H'')
_ ≤ (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := cond
_ ≤ (1 + α) / (2 * (1 - α)) * 1 * (H[X; μ] + H[Y;μ']) := by gcongr; simp; positivity
_ = (1 + α) / (2 * (1 - α)) * (H[X; μ] + H[Y;μ']) := by simp only [mul_one]
· calc
H[ ψ'' ∘ X; μ ] + H[ ψ'' ∘ Y; μ' ]
_ = H[ φ.symm ∘ ψ'' ∘ X; μ ] + H[ φ.symm ∘ ψ'' ∘ Y; μ' ] := by
simp_rw [← entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ φ.symm.injective,
← entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ φ.symm.injective]
_ ≤ α * (H[ ψ ∘ X; μ ] + H[ ψ ∘ Y; μ' ]) := hup'.le
_ ≤ α * (c * (H[X ; μ] + H[Y ; μ'])) := by gcongr
_ = (α * c) * (H[X ; μ] + H[Y ; μ']) := by ring
· use ⊥
constructor
· simp only [AddSubgroup.mem_bot, Nat.card_eq_fintype_card, Fintype.card_ofSubsingleton,
Nat.cast_one, log_one]
positivity
· simp only [S, Set.mem_setOf_eq, not_and, not_lt] at hE
exact hE ⟨1, by norm_num, by
norm_num; exact add_le_add (entropy_comp_le μ hX _) (entropy_comp_le μ' hY _)⟩
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq 2 * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 34 * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
34 * d[(QuotientAddGroup.mk' H) ∘ X;μ # (QuotientAddGroup.mk' H) ∘ Y;μ'] := by
rcases PFR_projection' X Y μ μ' ((3 : ℝ) / 5) hX hY (by norm_num) (by norm_num) with ⟨H, h, h'⟩
refine ⟨H, ?_, ?_⟩
· convert h
norm_num
· have : 0 ≤ d[⇑(QuotientAddGroup.mk' H) ∘ X ; μ # ⇑(QuotientAddGroup.mk' H) ∘ Y ; μ'] :=
rdist_nonneg ((measurable_discrete _).comp hX) ((measurable_discrete _).comp hY)
linarith
end F2_projection
open MeasureTheory ProbabilityTheory Real Set
open scoped BigOperators
lemma four_logs {a b c d : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) (hd : 0 < d) :
log ((a*b)/(c*d)) = log a + log b - log c - log d := by
rw [log_div, log_mul, log_mul, sub_sub] <;> positivity
lemma sum_prob_preimage {G H : Type*} {X : Finset H} {A : Set G} [Finite A] {φ : A → X}
{A_ : H → Set G} (hA : A.Nonempty) (hφ : ∀ x : X, A_ x = Subtype.val '' (φ ⁻¹' {x})) :
∑ x in X, (Nat.card (A_ x) : ℝ) / (Nat.card A) = 1 := by
rw [← Finset.sum_div]
apply (div_eq_one_iff_eq <| Nat.cast_ne_zero.mpr <| Nat.pos_iff_ne_zero.mp (@Nat.card_pos _ hA.to_subtype _)).mpr
classical
haveI := Fintype.ofFinite A
rewrite [Nat.card_eq_fintype_card, ← Finset.card_univ, Finset.card_eq_sum_card_fiberwise
<| fun a _ ↦ Finset.mem_univ (φ a), ← Finset.sum_coe_sort]
norm_cast
congr; ext
rewrite [← Set.Finite.toFinset_setOf, (Set.toFinite _).card_toFinset, ← Nat.card_eq_fintype_card,
hφ, Nat.card_image_of_injective Subtype.val_injective]; rfl
/-- Let $\phi : G\to H$ be a homomorphism and $A,B\subseteq G$ be finite subsets. If $x,y\in H$ then let $A_x=A\cap \phi^{-1}(x)$ and $B_y=B\cap \phi^{-1}(y)$. There exist $x,y\in H$ such that $A_x,B_y$ are both non-empty and
\[d[\phi(U_A);\phi(U_B)]\log \frac{\lvert A\rvert\lvert B\rvert}{\lvert A_x\rvert\lvert B_y\rvert}\leq (\mathbb{H}(\phi(U_A))+\mathbb{H}(\phi(U_B)))(d(U_A,U_B)-d(U_{A_x},U_{B_y}).\] -/
lemma single_fibres {G H Ω Ω': Type u}
[AddCommGroup G] [Countable G] [MeasurableSpace G] [MeasurableSingletonClass G]
[AddCommGroup H] [Countable H] [MeasurableSpace H] [MeasurableSingletonClass H]
[MeasureSpace Ω] [MeasureSpace Ω']
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
(φ : G →+ H)
{A B : Set G} [Finite A] [Finite B] {UA : Ω → G} {UB: Ω' → G} (hA : A.Nonempty) (hB : B.Nonempty)
(hUA': Measurable UA) (hUB': Measurable UB) (hUA: IsUniform A UA) (hUB: IsUniform B UB)
(hUA_mem : ∀ ω, UA ω ∈ A) (hUB_mem : ∀ ω, UB ω ∈ B) :
∃ (x y : H) (Ax By: Set G),
Ax = A ∩ φ.toFun ⁻¹' {x} ∧ By = B ∩ φ.toFun ⁻¹' {y} ∧ Ax.Nonempty ∧ By.Nonempty ∧
d[φ.toFun ∘ UA # φ.toFun ∘ UB]
* log ((Nat.card A) * (Nat.card B) / ((Nat.card Ax) * (Nat.card By))) ≤
(H[φ.toFun ∘ UA] + H[φ.toFun ∘ UB]) * (d[UA # UB] - dᵤ[Ax # By]) := by
have : Nonempty A := hA.to_subtype
have : Nonempty B := hB.to_subtype
haveI : FiniteRange UA := finiteRange_of_finset UA A.toFinite.toFinset (by simpa)
haveI : FiniteRange UB := finiteRange_of_finset UB B.toFinite.toFinset (by simpa)
have hUA_coe : IsUniform A.toFinite.toFinset.toSet UA := by rwa [Set.Finite.coe_toFinset]
have hUB_coe : IsUniform B.toFinite.toFinset.toSet UB := by rwa [Set.Finite.coe_toFinset]
let A_ (x : H) : Set G := A ∩ φ.toFun ⁻¹' {x}
let B_ (y : H) : Set G := B ∩ φ.toFun ⁻¹' {y}
let X : Finset H := FiniteRange.toFinset (φ.toFun ∘ UA)
let Y : Finset H := FiniteRange.toFinset (φ.toFun ∘ UB)
haveI h_Ax (x : X) : Nonempty (A_ x.val) := by
obtain ⟨ω, hω⟩ := (FiniteRange.mem_iff _ _).mp x.property
use UA ω; exact Set.mem_inter (hUA_mem ω) (by exact hω)
haveI h_By (y : Y) : Nonempty (B_ y.val) := by
obtain ⟨ω, hω⟩ := (FiniteRange.mem_iff _ _).mp y.property
use UB ω; exact Set.mem_inter (hUB_mem ω) (by exact hω)
have h_AX (a : A) : φ.toFun a.val ∈ X := by
obtain ⟨ω, hω⟩ := hUA_coe.nonempty_preimage_of_mem hUA' (A.toFinite.mem_toFinset.mpr a.property)
exact (FiniteRange.mem_iff _ (φ.toFun a.val)).mpr ⟨ω, congr_arg _ hω⟩
have h_BY (b : B) : φ.toFun b.val ∈ Y := by
obtain ⟨ω, hω⟩ := hUB_coe.nonempty_preimage_of_mem hUB' (B.toFinite.mem_toFinset.mpr b.property)
exact (FiniteRange.mem_iff _ (φ.toFun b.val)).mpr ⟨ω, congr_arg _ hω⟩
let φ_AX (a : A) : X := by use φ.toFun a.val; exact h_AX a
let φ_BY (b : B) : Y := by use φ.toFun b.val; exact h_BY b
have h_φ_AX (x : X) : A_ x.val = φ_AX ⁻¹' {x} := by ext; simp [A_, φ_AX]; simp [Subtype.ext_iff]
have h_φ_BY (y : Y) : B_ y.val = φ_BY ⁻¹' {y} := by ext; simp [B_, φ_BY]; simp [Subtype.ext_iff]
let p (x : H) (y : H) : ℝ :=
(Nat.card (A_ x).Elem) * (Nat.card (B_ y).Elem) / ((Nat.card A.Elem) * (Nat.card B.Elem))
have :
∑ x in X, ∑ y in Y, (p x y) * dᵤ[A_ x # B_ y] ≤ d[UA # UB] - d[φ.toFun ∘ UA # φ.toFun ∘ UB] :=
calc
_ = d[UA | φ.toFun ∘ UA # UB | φ.toFun ∘ UB] := by
rewrite [condRuzsaDist_eq_sum hUA' ((measurable_discrete _).comp hUA')
hUB' ((measurable_discrete _).comp hUB')]
refine Finset.sum_congr rfl <| fun x hx ↦ Finset.sum_congr rfl <| fun y hy ↦ ?_
haveI : Nonempty (A_ x) := h_Ax ⟨x, hx⟩
haveI : Nonempty (B_ y) := h_By ⟨y, hy⟩
let μx := (ℙ : Measure Ω)[|(φ.toFun ∘ UA) ⁻¹' {x}]
let μy := (ℙ : Measure Ω')[|(φ.toFun ∘ UB) ⁻¹' {y}]
have h_μ_p : IsProbabilityMeasure μx ∧ IsProbabilityMeasure μy := by
constructor <;> apply ProbabilityTheory.cond_isProbabilityMeasure <;> rw [Set.preimage_comp]
refine @IsUniform.measure_preimage_ne_zero _ _ _ _ _ _ _ _ _ _ hUA_coe hUA' _ ?_
swap; refine @IsUniform.measure_preimage_ne_zero _ _ _ _ _ _ _ _ _ _ hUB_coe hUB' _ ?_
all_goals rwa [Set.inter_comm, Set.Finite.coe_toFinset]
have h_μ_unif : IsUniform (A_ x) UA μx ∧ IsUniform (B_ y) UB μy := by
have : _ ∧ _ := ⟨hUA.restrict hUA' (φ.toFun ⁻¹' {x}), hUB.restrict hUB' (φ.toFun ⁻¹' {y})⟩
rwa [Set.inter_comm _ A, Set.inter_comm _ B] at this
rewrite [rdist_set_eq_rdist h_μ_p.1 h_μ_p.2 h_μ_unif.1 h_μ_unif.2 hUA' hUB']
show _ = (Measure.real _ (UA ⁻¹' (_ ⁻¹' _))) * (Measure.real _ (UB ⁻¹' (_ ⁻¹' _))) * _
rewrite [hUA_coe.measureReal_preimage hUA', hUB_coe.measureReal_preimage hUB']
simp_rw [p, A_, B_, IsProbabilityMeasure.measureReal_univ, one_mul]
rewrite [mul_div_mul_comm, Set.inter_comm A, Set.inter_comm B]
simp only [Set.Finite.coe_toFinset, Set.Finite.mem_toFinset, Finset.mem_val]; rfl
_ ≤ d[UA # UB] - d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
rewrite [ZeroHom.toFun_eq_coe, AddMonoidHom.toZeroHom_coe]
linarith only [rdist_le_sum_fibre φ hUA' hUB' (μ := ℙ) (μ' := ℙ)]
let M := H[φ.toFun ∘ UA] + H[φ.toFun ∘ UB]
have hM : M = ∑ x in X, ∑ y in Y, Real.negMulLog (p x y) := by
have h_compl {x y} (h_notin : (x, y) ∉ X ×ˢ Y) : Real.negMulLog (p x y) = 0 := by
unfold_let p; beta_reduce
rewrite [Finset.mem_product, not_and_or] at h_notin
suffices A_ x = ∅ ∨ B_ y = ∅ by obtain h | h := this <;> rw [h] <;> simp
refine h_notin.imp ?_ ?_
· rw [← not_nonempty_iff_eq_empty]
rintro h ⟨a, ha, rfl⟩
exact h (h_AX ⟨a, ha⟩)
· rw [← not_nonempty_iff_eq_empty]
rintro h ⟨a, ha, rfl⟩
exact h (h_BY ⟨a, ha⟩)
unfold_let M
unfold entropy
haveI := isProbabilityMeasure_map (μ := ℙ) ((measurable_discrete φ).comp hUA').aemeasurable
haveI := isProbabilityMeasure_map (μ := ℙ) ((measurable_discrete φ).comp hUB').aemeasurable
rewrite [← Finset.sum_product', ← tsum_eq_sum fun _ ↦ h_compl, ← measureEntropy_prod]
apply tsum_congr; intro; congr
rewrite [← Set.singleton_prod_singleton, Measure.smul_apply, Measure.prod_prod,
Measure.map_apply ((measurable_discrete _).comp hUA') (MeasurableSet.singleton _),
Measure.map_apply ((measurable_discrete _).comp hUB') (MeasurableSet.singleton _),
Set.preimage_comp, hUA_coe.measure_preimage hUA',
Set.preimage_comp, hUB_coe.measure_preimage hUB']
simp [p, A_, B_, mul_div_mul_comm, Set.inter_comm, ENNReal.toReal_div]
have h_sum : ∑ x in X, ∑ y in Y,
(p x y) * (M * dᵤ[A_ x # B_ y] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p x y)) ≤
M * d[UA # UB] :=
calc
_ = ∑ x in X, ∑ y in Y, (p x y) * M * dᵤ[A_ x # B_ y] + M * d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
simp_rw [hM, Finset.sum_mul, ← Finset.sum_add_distrib]
refine Finset.sum_congr rfl <| fun _ _ ↦ Finset.sum_congr rfl <| fun _ _ ↦ ?_
simp only [negMulLog, left_distrib, mul_assoc, Finset.sum_mul]
exact congrArg (HAdd.hAdd _) (by group)
_ = M * ∑ x in X, ∑ y in Y, (p x y) * dᵤ[A_ x # B_ y] + M * d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
simp_rw [Finset.mul_sum]
congr; ext; congr; ext; group
_ ≤ M * d[UA # UB] := by
rewrite [← left_distrib]
apply mul_le_mul_of_nonneg_left
· linarith
· unfold_let M
linarith only [entropy_nonneg (φ.toFun ∘ UA) ℙ, entropy_nonneg (φ.toFun ∘ UB) ℙ]
have : ∃ x : X, ∃ y : Y,
M * dᵤ[A_ x.val # B_ y.val] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p x.val y.val) ≤
M * d[UA # UB] := by
let f (xy : H × H) := (p xy.1 xy.2) * (M * d[UA # UB])
let g (xy : H × H) := (p xy.1 xy.2) *
(M * dᵤ[A_ xy.1 # B_ xy.2] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p xy.1 xy.2))
by_contra hc; push_neg at hc
replace hc : ∀ xy ∈ X ×ˢ Y, f xy < g xy := by
refine fun xy h ↦ mul_lt_mul_of_pos_left ?_ ?_
· exact hc ⟨xy.1, (Finset.mem_product.mp h).1⟩ ⟨xy.2, (Finset.mem_product.mp h).2⟩
· haveI : Nonempty _ := h_Ax ⟨xy.1, (Finset.mem_product.mp h).1⟩
haveI : Nonempty _ := h_By ⟨xy.2, (Finset.mem_product.mp h).2⟩
simp only [p, div_pos, mul_pos, Nat.cast_pos, Nat.card_pos]
have h_nonempty : Finset.Nonempty (X ×ˢ Y) := by
use ⟨φ.toFun <| UA <| Classical.choice <| ProbabilityMeasure.nonempty ⟨ℙ, inferInstance⟩,
φ.toFun <| UB <| Classical.choice <| ProbabilityMeasure.nonempty ⟨ℙ, inferInstance⟩⟩
exact Finset.mem_product.mpr ⟨FiniteRange.mem _ _, FiniteRange.mem _ _⟩
replace hc := Finset.sum_lt_sum_of_nonempty h_nonempty hc
have h_p_one : ∑ x in X ×ˢ Y, p x.1 x.2 = 1 := by
simp_rw [Finset.sum_product, p, mul_div_mul_comm, ← Finset.mul_sum,
← sum_prob_preimage hA h_φ_AX, sum_prob_preimage hB h_φ_BY, mul_one]
rewrite [← Finset.sum_mul, h_p_one, one_mul, Finset.sum_product] at hc
exact not_le_of_gt hc h_sum
obtain ⟨x, y, hxy⟩ := this
refine ⟨x, y, A_ x.val, B_ y.val, rfl, rfl, @nonempty_of_nonempty_subtype _ _ (h_Ax x), @nonempty_of_nonempty_subtype _ _ (h_By y), ?_⟩
rewrite [← inv_div, Real.log_inv]
show _ * -log (p x.val y.val) ≤ M * _
linarith only [hxy]
section dim
open Classical
variable {G : Type*} [AddCommGroup G]
/- If G ≅ ℤᵈ then there is a subgroup H of G such that A lies in a coset of H. This is helpful to
give the equivalent definition of `dimension`. Here this is stated in greated generality since the
proof carries over automatically-/
lemma exists_coset_cover (A : Set G) :
∃ (d : ℕ), ∃ (S : Submodule ℤ G) (v : G),
FiniteDimensional.finrank ℤ S = d ∧ ∀ a ∈ A, a - v ∈ S := by
existsi FiniteDimensional.finrank ℤ (⊤ : Submodule ℤ G), ⊤, 0
refine ⟨rfl, fun a _ ↦ trivial⟩
/-- The dimension of the affine span over `ℤ` of a subset of an additive group. -/
noncomputable def dimension (A : Set G) : ℕ := Nat.find (exists_coset_cover A)
lemma dimension_le_of_coset_cover (A : Set G) (S : Submodule ℤ G) (v : G)
(hA : ∀ a ∈ A, a - v ∈ S) : dimension A ≤ FiniteDimensional.finrank ℤ S := by
apply Nat.find_le
existsi S , v
exact ⟨rfl, hA⟩
lemma dimension_le_rank [Module.Finite ℤ G] (A : Set G) :
dimension A ≤ FiniteDimensional.finrank ℤ G := by
obtain ⟨S, v, hs, _⟩ := Nat.find_spec (exists_coset_cover A)
rw [dimension, ←hs]
apply Submodule.finrank_le S
end dim
variable {G : Type u} [AddCommGroup G] [Module.Free ℤ G] [Module.Finite ℤ G] [Countable G] [MeasurableSpace G] [MeasurableSingletonClass G]
open Real MeasureTheory ProbabilityTheory Pointwise Set
/-- Move to Mathlib? `Finsupp.mapRange` of a surjective function is surjective. -/
lemma Finsupp.mapRange_surjective {α : Type u_1} {M : Type u_5} {N : Type u_7} [Zero M] [Zero N] (f : M → N) (hf : f 0 = 0)
(hs : Function.Surjective f) : Function.Surjective (Finsupp.mapRange (α := α) f hf) := by
classical
let g (n : N) : M := if n = 0 then 0 else Function.surjInv hs n
have : Function.RightInverse g f := by
intro n
by_cases h : n = 0
. simp [g, h, hf]
· simp [g, h, Function.surjInv_eq hs n]
have hg : g 0 = 0 := by simp [g]
have hfg : (f ∘ g) 0 = 0 := by simp [hf, hg]
intro F
use Finsupp.mapRange g hg F
rw [← Finsupp.mapRange_comp (h := hfg)]
convert Finsupp.mapRange_id F
convert Function.RightInverse.id this
/-- A free Z-module is torsion-free. Move to Mathlib? -/
lemma torsion_free : AddMonoid.IsTorsionFree G := by
rintro x hx hn
rw [isOfFinAddOrder_iff_nsmul_eq_zero] at hn
rcases hn with ⟨ n, hn, hn' ⟩
apply_fun Module.Free.repr ℤ G at hn'
simp_rw [map_nsmul, map_zero, smul_eq_zero, AddEquivClass.map_eq_zero_iff, hx, or_false] at hn'
linarith
/-- If G is a rank n free Z-module, then G/2G is a finite elementary 2-group of cardinality 2^n. Code is slow, needs to be golfed -/
lemma weak_PFR_quotient_prelim :
let H := G ⧸ (AddMonoidHom.range (zsmulAddGroupHom 2))
ElementaryAddCommGroup H 2 ∧ Finite H ∧ Nat.card H = 2^(FiniteDimensional.finrank ℤ G) := by
set ψ : G →+ G := zsmulAddGroupHom 2
set G₂ := AddMonoidHom.range ψ
set H := G ⧸ G₂
set φ : G →+ H := QuotientAddGroup.mk' G₂
have hH_elem : ElementaryAddCommGroup H 2 := by
apply ElementaryAddCommGroup.quotient_group (by decide)
intro x; rw [AddMonoidHom.mem_range]
use x
rw [zsmulAddGroupHom_apply]
norm_cast
let B := Module.Free.ChooseBasisIndex ℤ G
let bG : Basis B ℤ G := Module.Free.chooseBasis ℤ G
have hB_fin : Fintype B := by infer_instance
have hB_card : Nat.card B = FiniteDimensional.finrank ℤ G := by
rw [FiniteDimensional.finrank_eq_card_basis bG, Nat.card_eq_fintype_card]
have hH_module : Module (ZMod 2) H := by infer_instance
let mod : (B →₀ ℤ) →+ (B →₀ ZMod 2) := Finsupp.mapRange.addMonoidHom (Int.castAddHom (ZMod 2))
let f : G →+ (B →₀ ℤ) := bG.repr
have hker : G₂ ≤ AddMonoidHom.ker (AddMonoidHom.comp mod f) := by
intro x hx
simp only [AddMonoidHom.mem_range, G₂, ψ, zsmulAddGroupHom_apply] at hx
simp_rw [AddMonoidHom.mem_ker, AddMonoidHom.coe_comp, Function.comp_apply, mod,
Finsupp.mapRange.addMonoidHom_apply, Int.coe_castAddHom]
rcases hx with ⟨y, rfl⟩
ext b
simp_rw [map_zsmul, Finsupp.mapRange_apply, Finsupp.coe_smul, Pi.smul_apply, smul_eq_mul,
Int.cast_mul, Int.cast_ofNat, Finsupp.coe_zero, Pi.zero_apply, mul_eq_zero]
left
exact ZMod.nat_cast_self 2
let g : H →+ (B →₀ ZMod 2) := QuotientAddGroup.lift G₂ (AddMonoidHom.comp mod f) hker
have hsur : Function.Surjective g := by
have h1 : Function.Surjective mod := Finsupp.mapRange_surjective (Int.castAddHom (ZMod 2)) (map_zero _) ZMod.int_cast_surjective
have h2 := h1.comp bG.repr.surjective
have h3 : mod ∘ bG.repr = g ∘ (QuotientAddGroup.mk' G₂) := by
ext x b
simp_rw [mod, Function.comp_apply, Finsupp.mapRange.addMonoidHom_apply, Int.coe_castAddHom,
Finsupp.mapRange_apply, QuotientAddGroup.coe_mk', g]
rw [QuotientAddGroup.lift_mk]
simp [mod, f]
rw [h3] at h2
apply Function.Surjective.of_comp h2
have hinj : Function.Injective g := by
rw [injective_iff_map_eq_zero]
intro x hx
rcases QuotientAddGroup.mk'_surjective G₂ x with ⟨y, rfl⟩
simp only [QuotientAddGroup.mk'_apply, g] at hx
rw [QuotientAddGroup.lift_mk] at hx
simp_rw [AddMonoidHom.coe_comp, Function.comp_apply, mod, Finsupp.mapRange.addMonoidHom_apply,
Int.coe_castAddHom, DFunLike.ext_iff,Finsupp.mapRange_apply, Finsupp.coe_zero, Pi.zero_apply,
ZMod.int_cast_zmod_eq_zero_iff_dvd] at hx
replace hx := fun x ↦ Int.mul_ediv_cancel' (hx x)
let z (b : B) := ((Module.Free.chooseBasis ℤ G).repr y) b / 2
let z' := (Finsupp.equivFunOnFinite).symm z
change ∀ b : B, 2 * z' b = (f y) b at hx
let x' := bG.repr.symm z'
rw [QuotientAddGroup.mk'_apply, QuotientAddGroup.eq_zero_iff, AddMonoidHom.mem_range]
simp_rw [ψ, zsmulAddGroupHom_apply]
use x'
change 2 • (bG.repr.symm.toLinearMap.toAddMonoidHom z') = y
rw [← AddMonoidHom.map_zsmul bG.repr.symm.toLinearMap.toAddMonoidHom z' (2 : ℤ)]
rw [← LinearEquiv.symm_apply_apply bG.repr y]
change bG.repr.symm (2 • z') = bG.repr.symm (f y)
congr
ext b
rw [Finsupp.smul_apply, ← hx b, smul_eq_mul]
rcases Function.bijective_iff_has_inverse.mp ⟨ hinj, hsur ⟩ with ⟨ g', hg' ⟩
have bH : Basis B (ZMod 2) H := by
constructor
exact {
toFun := g
invFun := g'
left_inv := hg'.1
right_inv := hg'.2
map_add' := AddMonoidHom.map_add _
map_smul' := by
intro r x
rcases ZMod.int_cast_surjective r with ⟨ n, rfl ⟩
change g ((n : ZMod 2) • x) = (n : ZMod 2) • g x
rw [intCast_smul, intCast_smul]
exact AddMonoidHom.map_zsmul g x n
}
have hH_fin : Fintype H := Module.fintypeOfFintype bH
have hH_card : Nat.card H = 2^(FiniteDimensional.finrank ℤ G) := by
rw [Nat.card_eq_fintype_card, Module.card_fintype bH, ← Nat.card_eq_fintype_card (α := B), hB_card]
congr
exact ⟨ hH_elem, Finite.of_fintype H, hH_card ⟩
open QuotientAddGroup
/-- A version of the third isomorphism theorem: if G₂ ≤ G and H' is a subgroup of G⧸G₂, then there is a canonical isomorphism between H⧸H' and G⧸N, where N is the preimage of H' in G. A bit clunky; may be a better way to do this -/
lemma third_iso {G : Type u} [AddCommGroup G] {G₂ : AddSubgroup G} (H' : AddSubgroup (G ⧸ G₂)) :
let H := G ⧸ G₂
let φ : G →+ H := mk' G₂
let N := AddSubgroup.comap φ H'
∃ e : H ⧸ H' ≃+ G ⧸ N, ∀ x : G, e (mk' H' (φ x))= mk' N x := by
set H := G ⧸ G₂
let φ : G →+ H := mk' G₂
let N := AddSubgroup.comap φ H'
have h1 : G₂ ≤ N := by
intro x hx
rw [← eq_zero_iff] at hx
have : φ x = 0 := hx
simp [N, this, AddSubgroup.zero_mem H']
set H'' := AddSubgroup.map (mk' G₂) N
have h2 : H' = H'' := by
change H' = AddSubgroup.map (mk' G₂) N
rw [AddSubgroup.map_comap_eq, AddMonoidHom.range_top_of_surjective _ (mk'_surjective G₂)]
simp
let e1 : H ⧸ H'' ≃+ G ⧸ N := quotientQuotientEquivQuotient _ _ h1
let e2 := quotientAddEquivOfEq h2
set e := e2.trans e1
use e
intro x
convert (quotientQuotientEquivQuotientAux_mk_mk _ _ h1 x) using 1
lemma single {Ω : Type u} [MeasurableSpace Ω] [DiscreteMeasurableSpace Ω] (μ : Measure Ω)
[IsProbabilityMeasure μ] {A : Set Ω} {z : Ω} (hA : μ.real A = 1) (hz : μ.real {z} > 0) :
z ∈ A := by
contrapose! hz
have : Disjoint {z} A := by simp [hz]
replace this := measureReal_union (μ := μ) this (measurableSet_discrete _)
simp [hA] at this
have h := measureReal_mono (μ := μ) (show insert z A ⊆ Set.univ by simp)
simp [this] at h
assumption
/-- Given two non-empty finite subsets A, B of a rank n free Z-module G, there exists a subgroup N and points x, y in G/N such that the fibers Ax, By of A, B over x, y respectively are non-empty, one has the inequality
$$ \log \frac{|A| |B|}{|A_x| |B_y|} ≤ 34 (d[U_A; U_B] - d[U_{A_x}; U_{B_y}])$$
and one has the dimension bound
$$ n \log 2 ≤ \log |G/N| + 40 d[U_A; U_B].$$
-/
| lemma weak_PFR_asymm_prelim (A B : Set G) [Finite A] [Finite B] (hnA : A.Nonempty) (hnB : B.Nonempty):
∃ (N : AddSubgroup G) (x y : G ⧸ N) (Ax By : Set G), Ax.Nonempty ∧ By.Nonempty ∧
Set.Finite Ax ∧ Set.Finite By ∧ Ax = {z:G | z ∈ A ∧ QuotientAddGroup.mk' N z = x } ∧
By = {z:G | z ∈ B ∧ QuotientAddGroup.mk' N z = y } ∧
(log 2) * FiniteDimensional.finrank ℤ G ≤ log (Nat.card (G ⧸ N)) +
40 * dᵤ[ A # B ] ∧ log (Nat.card A) + log (Nat.card B) - log (Nat.card Ax) - log (Nat.card By)
≤ 34 * (dᵤ[ A # B ] - dᵤ[ Ax # By ]) | weak_PFR_asymm_prelim | 25309ad 20231211 | c0c547a 20240116 | pfr/PFR/WeakPFR.lean | {
"lineInFile": 785,
"tokenPositionInFile": 42027,
"theoremPositionInFile": 24
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n have : Nonempty A := hnA.to_subtype\n have : Nonempty B := hnB.to_subtype\n obtain ⟨ h_elem, h_finite, h_card ⟩ := weak_PFR_quotient_prelim (G := G)\n set ψ : G →+ G := zsmulAddGroupHom 2\n set G₂ := AddMonoidHom.range ψ\n set H := G ⧸ G₂\n let φ : G →+ H := QuotientAddGroup.mk' G₂\n let _mH : MeasurableSpace H := ⊤\n have h_fintype : Fintype H := Fintype.ofFinite H\n have h_torsionfree := torsion_free (G := G)\n\n obtain ⟨ Ω, mΩ, UA, hμ, hUA_mes, hUA_unif, hUA_mem, hUA_fin ⟩ := exists_isUniform_measureSpace' A\n obtain ⟨ Ω', mΩ', UB, hμ', hUB_mes, hUB_unif, hUB_mem, hUB_fin ⟩ :=\n exists_isUniform_measureSpace' B\n\n rcases (PFR_projection (φ.toFun ∘ UA) (φ.toFun ∘ UB) ℙ ℙ (by measurability) (by measurability)) with ⟨H', ⟨ hH1, hH2 ⟩ ⟩\n let N := AddSubgroup.comap φ H'\n set φ' := QuotientAddGroup.mk' N\n have _cGN : Countable (G ⧸ N) := Function.Surjective.countable (QuotientAddGroup.mk'_surjective N)\n have _msGN : MeasurableSingletonClass (G ⧸ N) := by\n constructor\n intro x\n exact MeasurableSpace.map_def.mpr (measurableSet_discrete _)\n\n rcases third_iso H' with ⟨ e : H ⧸ H' ≃+ G ⧸ N, he ⟩\n rcases single_fibres φ' hnA hnB hUA_mes hUB_mes hUA_unif hUB_unif hUA_mem hUB_mem with\n ⟨x, y, Ax, By, hAx, hBy, hnAx, hnBy, hcard_ineq⟩\n\n have : Nonempty Ax := hnAx.to_subtype\n have : Nonempty By := hnBy.to_subtype\n have Axf : Finite Ax := by rw [hAx]; infer_instance\n have Byf : Finite By := by rw [hBy]; infer_instance\n\n have h1 := torsion_dist_shrinking UA UB ℙ ℙ hUA_mes hUB_mes h_torsionfree φ\n have h2 := torsion_dist_shrinking UB UA ℙ ℙ hUB_mes hUA_mes h_torsionfree φ\n rw [rdist_symm] at h2\n rw [<- rdist_set_eq_rdist hμ hμ' hUA_unif hUB_unif hUA_mes hUB_mes] at h1 h2\n -- using explicit .toFun casts as this saves a lot of heartbeats\n change H[φ.toFun ∘ UA] ≤ 10 * dᵤ[A # B] at h1\n change H[φ.toFun ∘ UB] ≤ 10 * dᵤ[A # B] at h2\n replace hH1 : log (Nat.card H') ≤ 40 * dᵤ[A # B] := by\n apply hH1.trans\n linarith\n replace h_card : log 2 * FiniteDimensional.finrank ℤ G ≤ log (Nat.card (G ⧸ N)) + 40 * dᵤ[A # B] := by\n rw [mul_comm, ← log_rpow (by norm_num)]\n norm_cast\n classical\n rwa [← h_card, ← Nat.card_congr e.toEquiv, Nat.card_eq_fintype_card, Nat.card_eq_fintype_card, ← AddSubgroup.index_mul_card H', AddSubgroup.index_eq_card, Nat.cast_mul, log_mul, add_le_add_iff_left, ← Nat.card_eq_fintype_card]\n all_goals norm_cast; exact Fintype.card_ne_zero\n\n\n use N, x, y, Ax, By\n refine ⟨ hnAx, hnBy, Ax.toFinite, By.toFinite, hAx, hBy, h_card, ?_ ⟩\n\n replace hH2 : H[φ'.toFun ∘ UA] + H[φ'.toFun ∘ UB] ≤ 34 * d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] := by\n set X := ((mk' H').toFun ∘ φ.toFun) ∘ UA\n set Y := ((mk' H').toFun ∘ φ.toFun) ∘ UB\n have hX : Measurable X := Measurable.comp (measurable_discrete _) hUA_mes\n have hY : Measurable Y := Measurable.comp (measurable_discrete _) hUB_mes\n change H[X] + H[Y] ≤ 34 * d[X # Y] at hH2\n\n have ha : φ'.toFun ∘ UA = e.toFun ∘ X := by ext x; exact (he (UA x)).symm\n have hb : φ'.toFun ∘ UB = e.toFun ∘ Y := by ext x; exact (he (UB x)).symm\n have he_inj : Function.Injective e.toFun := AddEquiv.injective e\n rw [ha, hb, entropy_comp_of_injective _ hX _ he_inj, entropy_comp_of_injective _ hY _ he_inj]\n have : d[e.toFun ∘ X # e.toFun ∘ Y] = d[X # Y] := rdist_of_inj hX hY e.toAddMonoidHom he_inj\n rwa [this]\n\n set X : Ω → G ⧸ N := φ'.toFun ∘ UA\n set Y : Ω' → G ⧸ N := φ'.toFun ∘ UB\n have hX : Measurable X := Measurable.comp (measurable_discrete _) hUA_mes\n have hY : Measurable Y := Measurable.comp (measurable_discrete _) hUB_mes\n rcases le_iff_lt_or_eq.mp (rdist_nonneg (μ := ℙ) (μ' := ℙ) hX hY) with h | h\n swap\n . rw [← h] at hH2\n have hH2A : H[X] ≥ 0 := entropy_nonneg _ _\n have hH2B : H[Y] ≥ 0 := entropy_nonneg _ _\n have hH2A' : H[X] ≤ 0 := by linarith only [hH2, hH2A, hH2B]\n have hH2B' : H[Y] ≤ 0 := by linarith only [hH2, hH2A, hH2B]\n\n rcases const_of_nonpos_entropy (μ := ℙ) hX hH2A' with ⟨ x', hx ⟩\n rcases const_of_nonpos_entropy (μ := ℙ) hY hH2B' with ⟨ y', hy ⟩\n\n have hAAx {z : G} (hz : z ∈ A) : φ'.toFun z = x' := by\n change (ℙ).real (UA⁻¹' (φ'⁻¹' {x'})) = 1 at hx\n rw [← MeasureTheory.map_measureReal_apply hUA_mes (measurableSet_discrete _)] at hx\n set Af := A.toFinite.toFinset\n have hUAf : IsUniform Af UA := by\n convert hUA_unif; simp only [Af, Set.Finite.coe_toFinset]\n have hnAf : 0 < Nat.card Af := by simp only [Af, Set.Finite.mem_toFinset, Nat.card_pos]\n have hzf : z ∈ Af := by simp [Af, Set.Finite.mem_toFinset, hz]\n have : (Measure.map UA ℙ).real {z} > 0 := by\n rw [IsUniform.measureReal_preimage_of_mem' hUAf hUA_mes hzf]\n positivity\n have _ : IsProbabilityMeasure ((ℙ).map UA) := by\n exact MeasureTheory.isProbabilityMeasure_map (Measurable.aemeasurable hUA_mes)\n replace this := single ((ℙ).map UA) hx this\n rwa [Set.mem_preimage, Set.mem_singleton_iff] at this\n\n have hxx : Ax = A := by\n have h : hnAx.some ∈ Ax := hnAx.some_mem\n simp [hAx] at h ⊢\n have := hAAx h.1\n simp [h.2] at this\n intro z hz\n simp [this]\n convert hAAx hz\n\n have hBBy {z : G} (hz : z ∈ B) : φ'.toFun z = y' := by\n change (ℙ).real (UB⁻¹' (φ'⁻¹' {y'})) = 1 at hy\n rw [← MeasureTheory.map_measureReal_apply hUB_mes (measurableSet_discrete _)] at hy\n set Bf := B.toFinite.toFinset\n have hUBf : IsUniform Bf UB := by convert hUB_unif; simp only [Bf, Set.Finite.coe_toFinset]\n have hnBf : 0 < Nat.card Bf := by simp only [Bf, Set.Finite.mem_toFinset, Nat.card_pos]\n have hzf : z ∈ Bf := by simp [Bf, Set.Finite.mem_toFinset, hz]\n have : (Measure.map UB ℙ).real {z} > 0 := by\n rw [IsUniform.measureReal_preimage_of_mem' hUBf hUB_mes hzf]\n positivity\n have _ : IsProbabilityMeasure ((ℙ).map UB) := by\n exact MeasureTheory.isProbabilityMeasure_map (Measurable.aemeasurable hUB_mes)\n replace this := single ((ℙ).map UB) hy this\n rwa [Set.mem_preimage, Set.mem_singleton_iff] at this\n\n have hyy : By = B := by\n have h : hnBy.some ∈ By := hnBy.some_mem\n simp [hBy] at h ⊢\n have := hBBy h.1\n simp [h.2] at this\n intro z hz\n simp [this]\n convert hBBy hz\n\n simp [hxx, hyy]\n\n have := calc d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] * (log (Nat.card A) + log (Nat.card B) - log (Nat.card Ax) - log (Nat.card By))\n _ = d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] * log ((Nat.card A) * (Nat.card B) / ((Nat.card Ax) * (Nat.card By))) := by\n congr\n convert (four_logs ?_ ?_ ?_ ?_).symm\n all_goals norm_cast; exact Nat.card_pos\n _ ≤ (H[φ'.toFun ∘ UA] + H[φ'.toFun ∘ UB]) * (d[UA # UB] - dᵤ[Ax # By]) := hcard_ineq\n _ ≤ (34 * d[φ'.toFun ∘ UA # φ'.toFun ∘ UB]) * (d[UA # UB] - dᵤ[Ax # By]) := by\n apply mul_le_mul_of_nonneg_right hH2\n have := rdist_le_avg_ent (Measurable.comp (measurable_discrete φ'.toFun) hUA_mes) (Measurable.comp (measurable_discrete φ'.toFun) hUB_mes)\n replace this : 0 < H[φ'.toFun ∘ UA] + H[φ'.toFun ∘ UB] := by linarith\n rw [← mul_le_mul_left this]\n apply le_trans _ hcard_ineq\n rw [mul_zero]\n change 0 ≤ d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] * log ((Nat.card A) * (Nat.card B) / ((Nat.card Ax) * (Nat.card By)))\n rw [← mul_zero d[φ'.toFun ∘ UA # φ'.toFun ∘ UB], mul_le_mul_left h]\n apply Real.log_nonneg\n rw [one_le_div]\n gcongr\n . apply Nat.card_mono\n . exact Set.toFinite A\n rw [hAx]; exact Set.inter_subset_left _ _\n apply Nat.card_mono\n . exact Set.toFinite B\n rw [hBy]; exact Set.inter_subset_left _ _\n norm_cast\n exact mul_pos Nat.card_pos Nat.card_pos\n _ = d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] * (34 * (d[UA # UB] - dᵤ[Ax # By])) := by ring\n _ = d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] * (34 * (dᵤ[A # B] - dᵤ[Ax # By])) := by\n rw [<- rdist_set_eq_rdist hμ hμ' hUA_unif hUB_unif hUA_mes hUB_mes]\n exact (mul_le_mul_left h).mp this",
"proofType": "tactic",
"proofLengthLines": 165,
"proofLengthTokens": 7951
} | pfr |
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Quotient
import Mathlib.GroupTheory.Torsion
import Mathlib.GroupTheory.Torsion
import Mathlib.LinearAlgebra.FreeModule.PID
import PFR.Mathlib.Data.Set.Pointwise.SMul
import PFR.EntropyPFR
import PFR.ImprovedPFR
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Mathlib.GroupTheory.Torsion
/-!
# Weak PFR over the integers
Here we use the entropic form of PFR to deduce a weak form of PFR over the integers.
## Main statement
* `weak_PFR_int`: Let $A\subseteq \mathbb{Z}^d$ and $\lvert A+A\rvert\leq K\lvert A\rvert$.
There exists $A'\subseteq A$ such that $\lvert A'\rvert \geq K^{-17}\lvert A\rvert$ and
$\dim A' \leq (40/\log 2)\log K$.
-/
section AddCommGroup
variable {G : Type*} [AddCommGroup G] {A B : Set G}
open Set
open scoped Pointwise
def IsShift (A B : Set G) : Prop := ∃ x : G, A = x +ᵥ B
lemma IsShift.sub_self_congr : IsShift A B → A - A = B - B := by
rintro ⟨x, rfl⟩; simp [vadd_sub_vadd_comm, singleton_zero]
lemma IsShift.card_congr : IsShift A B → Nat.card A = Nat.card B := by rintro ⟨x, rfl⟩; simp
/-- The property of two sets A, B of a group G not being contained in cosets of the same proper
subgroup -/
def NotInCoset (A B : Set G) : Prop := AddSubgroup.closure ((A - A) ∪ (B - B)) = ⊤
/-- Without loss of generality, one can move (up to translation and embedding) any pair A, B of non-empty sets into a subgroup where they are not in a coset. -/
lemma wlog_notInCoset (hA : A.Nonempty) (hB : B.Nonempty) :
∃ (G' : AddSubgroup G) (A' B' : Set G'), IsShift A A' ∧ IsShift B B' ∧ NotInCoset A' B' := by
obtain ⟨x, hx⟩ := hA
obtain ⟨y, hy⟩ := hB
set G' := AddSubgroup.closure ((A - A) ∪ (B - B))
set A' : Set G' := (↑) ⁻¹' ((-x) +ᵥ A)
set B' : Set G' := (↑) ⁻¹' ((-y) +ᵥ B)
have hxA : -x +ᵥ A ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hx).trans $ (subset_union_left ..).trans
AddSubgroup.subset_closure
have hyB : -y +ᵥ B ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hy).trans $ (subset_union_right ..).trans
AddSubgroup.subset_closure
have hA : IsShift A A' := ⟨x, by rw [Set.image_preimage_eq_of_subset hxA, vadd_neg_vadd]⟩
have hB : IsShift B B' := ⟨y, by rw [Set.image_preimage_eq_of_subset hyB, vadd_neg_vadd]⟩
refine ⟨G', A', B', hA, hB, ?_⟩
unfold NotInCoset
convert AddSubgroup.closure_preimage_eq_top ((A - A) ∪ (B - B))
simp_rw [preimage_union, hA.sub_self_congr, hB.sub_self_congr]
rw [preimage_sub, preimage_sub]
simp [A', B', preimage_image_preimage]
all_goals apply_rules [Subtype.coe_injective, (image_preimage_subset ..).trans, hxA, hyB]
end AddCommGroup
section Torsion
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [MeasurableSpace G] [MeasurableSingletonClass G]
[Countable G] {Ω Ω' : Type u} [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ': Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
/-- If $G$ is torsion-free and $X,Y$ are $G$-valued random variables then $d[X;2Y]\leq 5d[X;Y]$. -/
lemma torsion_free_doubling [FiniteRange X] [FiniteRange Y]
(hX : Measurable X) (hY : Measurable Y) (hG : AddMonoid.IsTorsionFree G) :
d[X ; μ # (Y + Y) ; μ'] ≤ 5 * d[X; μ # Y ; μ'] := by
obtain ⟨A, mA, μA, X', Y'₁, Y'₂, hμA, h_indep, hX'_meas, hY'₁_meas, hY'₂_meas, hX'_ident,
hY'₁_ident, hY'₂_ident, _, _, _⟩ := independent_copies3_nondep_finiteRange hX hY hY μ μ' μ'
have h_meas (i : Fin 3) : Measurable (![X', Y'₁, Y'₂] i) := by fin_cases i <;> assumption
haveI : NoZeroSMulDivisors ℕ G := hG.noZeroNsmulDivisors
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨x, y₁, y₂⟩ ↦ (x, y₁ - y₂, x - 2 • y₁)
show H[f ∘ ⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] = _
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hX'_meas <| Measurable.prod hY'₁_meas hY'₂_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun X' (prod Y'₁ Y'₂) μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 1 2 0 (by decide) (by decide)
rw [this.entropy_pair_eq_add hX'_meas (by exact Measurable.prod hY'₁_meas hY'₂_meas),
IndepFun.entropy_pair_eq_add hY'₁_meas hY'₂_meas (h_indep.indepFun (show 1 ≠ 2 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, two_mul]
have : H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[X ; μ] + H[Y ; μ'] := calc
H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[⟨X', Y'₁⟩ ; μA] := by
let f : G × G → G × G := fun ⟨x, y₁⟩ ↦ (x, x - 2 • y₁)
show H[f ∘ ⟨X', Y'₁⟩ ; μA] = _
apply entropy_comp_of_injective μA (by exact Measurable.prod hX'_meas hY'₁_meas) f
exact fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + H[Y ; μ'] := by
rw [IndepFun.entropy_pair_eq_add hX'_meas hY'₁_meas (h_indep.indepFun (show 0 ≠ 1 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq]
let f : G × G → G × G := fun ⟨x, y⟩ ↦ (x, y - x)
have hf : f.Injective := fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all
have : H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] := calc
H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] = H[f ∘ ⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
show _ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂ - (Y'₁ - Y'₂)⟩ ; μA]
rw [sub_sub_sub_cancel_right, ← sub_add_eq_sub_sub, two_nsmul]
_ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
refine entropy_comp_of_injective μA (Measurable.prod ?_ ?_) f hf
· exact Measurable.sub hY'₁_meas hY'₂_meas
· exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
_ ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] :=
entropy_pair_le_add (hY'₁_meas.sub' hY'₂_meas) (hX'_meas.sub' hY'₁_meas |>.sub' hY'₂_meas) μA
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] + H[X' - 2 • Y'₁ ; μA] ≤
H[⟨X', X' - 2 • Y'₁⟩ ; μA] + H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] := by
haveI : FiniteRange (Y'₁ - Y'₂) := FiniteRange.sub Y'₁ Y'₂
haveI : FiniteRange (2 • Y'₁) := by show FiniteRange ((fun x ↦ 2 • x) ∘ Y'₁); infer_instance
apply entropy_triple_add_entropy_le μA hX'_meas (Measurable.sub hY'₁_meas hY'₂_meas)
exact Measurable.sub' hX'_meas <| Measurable.const_smul hY'₁_meas 2
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨y₁, y₂, x⟩ ↦ (y₁, y₂, x - y₁ - y₂)
show H[f ∘ ⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA]
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hY'₁_meas <| Measurable.prod hY'₂_meas hX'_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun Y'₁ (prod Y'₂ X') μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 2 0 1 (by decide) (by decide)
rw [this.entropy_pair_eq_add hY'₁_meas (by exact Measurable.prod hY'₂_meas hX'_meas),
IndepFun.entropy_pair_eq_add hY'₂_meas hX'_meas (h_indep.indepFun (show 2 ≠ 0 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq]
group
have : H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₂ ; μA] := calc
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₁, X' - Y'₂⟩ ; μA] := by rw [sub_right_comm] ; rfl
_ = H[⟨Y'₁, X' - Y'₂⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₁_meas <| Measurable.sub hX'_meas hY'₂_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₂ ; μA] := by
haveI : FiniteRange (X' - Y'₂) := FiniteRange.sub X' Y'₂
convert IndepFun.entropy_pair_eq_add hY'₁_meas (hX'_meas.sub hY'₂_meas)
<| h_indep.indepFun_sub_right h_meas 1 0 2 (by decide) (by decide)
exact hY'₁_ident.entropy_eq.symm
have : H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₁ ; μA] := calc
H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₂, X' - Y'₁⟩ ; μA] := rfl
_ = H[⟨Y'₂, X' - Y'₁⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₂_meas <| Measurable.sub hX'_meas hY'₁_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₁ ; μA] := by
haveI : FiniteRange (X' - Y'₁) := FiniteRange.sub X' Y'₁
convert IndepFun.entropy_pair_eq_add hY'₂_meas (hX'_meas.sub hY'₁_meas)
<| h_indep.indepFun_sub_right h_meas 2 0 1 (by decide) (by decide)
exact hY'₂_ident.entropy_eq.symm
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] ≤
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] + H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
apply entropy_triple_add_entropy_le μA hY'₁_meas hY'₂_meas
exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
have : H[X' - Y'₁ - Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := calc
H[X' - Y'₁ - Y'₂ ; μA] ≤ H[X' - Y'₁ ; μA] + H[X' - Y'₂ ; μA] - H[X ; μ] := by linarith
_ = 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := by
nth_rw 1 [two_mul, ← hX'_ident.rdist_eq hY'₁_ident, ← hX'_ident.rdist_eq hY'₂_ident]
have h1 : d[X' ; μA # Y'₁ ; μA] = H[X' - Y'₁ ; μA] - H[X' ; μA] / 2 - H[Y'₁ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 1 by decide)).rdist_eq hX'_meas hY'₁_meas
have h2 : d[X' ; μA # Y'₂ ; μA] = H[X' - Y'₂ ; μA] - H[X' ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 2 by decide)).rdist_eq hX'_meas hY'₂_meas
rw [h1, h2, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, hX'_ident.entropy_eq]
group
have : d[X ; μ # 2 • Y ; μ'] ≤
d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := calc
d[X ; μ # 2 • Y ; μ'] = H[X' - 2 • Y'₁ ; μA] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by
have h2Y_ident : IdentDistrib (2 • Y'₁) (2 • Y) (μ := μA) (ν := μ') := by
convert hY'₁_ident.comp <| measurable_discrete <| fun g ↦ 2 • g
have h2Y_indep : IndepFun X' (2 • Y'₁) (μ := μA) := by
convert (h_indep.indepFun (show 0 ≠ 1 by decide)).comp measurable_id
(measurable_const_smul 2)
rw [← hX'_ident.rdist_eq h2Y_ident,
h2Y_indep.rdist_eq hX'_meas <| Measurable.const_smul hY'₁_meas 2,
hX'_ident.entropy_eq, h2Y_ident.entropy_eq]
_ ≤ H[Y'₁ - Y'₂ ; μA] + 2 * d[X ; μ # Y ; μ'] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by linarith
_ = d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := by
have H2Y : H[2 • Y ; μ'] = H[Y ; μ'] := by
let f (g : G) := 2 • g
exact entropy_comp_of_injective μ' hY f (fun _ _ ↦ by simp [f, smul_right_inj])
have : d[Y'₁ ; μA # Y'₂ ; μA] = H[Y'₁ - Y'₂ ; μA] - H[Y'₁ ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 1 ≠ 2 by decide)).rdist_eq hY'₁_meas hY'₂_meas
rw [this, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, H2Y]
group
have : d[Y'₁ ; μA # Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] := by
rw [two_mul]
convert rdist_triangle hY'₁_meas hX'_meas hY'₂_meas (μ := μA) (μ' := μA) (μ'' := μA)
· exact rdist_symm.trans (hY'₁_ident.rdist_eq hX'_ident).symm
· exact (hX'_ident.rdist_eq hY'₂_ident).symm
rw [← two_nsmul]
linarith [abs_le.mp <| diff_ent_le_rdist hX hY (μ := μ) (μ' := μ')]
/-- If $G$ is a torsion-free group and $X,Y$ are $G$-valued random variables and
$\phi : G\to \mathbb{F}_2^d$ is a homomorphism then
\[\mathbb{H}(\phi(X))\leq 10d[X;Y].\] -/
lemma torsion_dist_shrinking {H : Type u} [FiniteRange X] [FiniteRange Y] (hX : Measurable X)
(hY : Measurable Y) [AddCommGroup H] [ElementaryAddCommGroup H 2]
[MeasurableSpace H] [MeasurableSingletonClass H] [Countable H]
(hG : AddMonoid.IsTorsionFree G) (φ : G →+ H) :
H[φ ∘ X ; μ] ≤ 10 * d[X; μ # Y ; μ'] := by
have :=
calc d[φ ∘ X ; μ # φ ∘ (Y + Y); μ'] ≤ d[X; μ # (Y + Y) ; μ'] := rdist_of_hom_le φ hX (Measurable.add hY hY)
_ ≤ 5 * d[X; μ # Y ; μ'] := torsion_free_doubling X Y μ μ' hX hY hG
have eq_zero : φ ∘ (Y + Y) = fun _ ↦ 0 := by ext x ; simp only [Function.comp_apply, Pi.add_apply,
map_add, ElementaryAddCommGroup.add_self]
rwa [eq_zero, rdist_zero_eq_half_ent, div_le_iff zero_lt_two, mul_assoc, mul_comm _ 2, ←mul_assoc,
show (5*2 : ℝ) = 10 by norm_num] at this
end Torsion
instance {G : Type u} [AddCommGroup G] [Fintype G] [MeasurableSpace G] [MeasurableSingletonClass G] (H : AddSubgroup G)
: MeasurableSingletonClass (G ⧸ H) :=
⟨λ _ ↦ by { rw [measurableSet_quotient]; simp [measurableSet_discrete] }⟩
section F2_projection
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [ElementaryAddCommGroup G 2] [Fintype G] [MeasurableSpace G]
[MeasurableSingletonClass G] {Ω Ω' : Type*}
/-- Let $G=\mathbb{F}_2^n$ and $X,Y$ be $G$-valued random variables such that
\[\mathbb{H}(X)+\mathbb{H}(Y)> (20/\alpha) d[X;Y],\]
for some $\alpha > 0$.
There is a non-trivial subgroup $H\leq G$ such that
\[\log \lvert H\rvert <(1+\alpha)/2 (\mathbb{H}(X)+\mathbb{H}(Y))\] and
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))< \alpha (\mathbb{H}(X)+\mathbb{H}(Y))\]
where $\psi:G\to G/H$ is the natural projection homomorphism.
-/
lemma app_ent_PFR' [MeasureSpace Ω] [MeasureSpace Ω'] (X : Ω → G) (Y : Ω' → G)
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
{α : ℝ} (hent : 20 * d[X # Y] < α * (H[X] + H[Y])) (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X] + H[Y]) ∧
H[(QuotientAddGroup.mk' H) ∘ X] + H[(QuotientAddGroup.mk' H) ∘ Y] < α * (H[X] + H[Y]) := by
let p : refPackage Ω Ω' G := {
X₀₁ := X
X₀₂ := Y
hmeas1 := hX
hmeas2 := hY
η := 1/8
hη := by norm_num
hη' := by norm_num }
obtain ⟨H, Ω'', hΩ'', U, _, hUmeas, hUunif, ineq⟩ := entropic_PFR_conjecture_improv p rfl
let ψ := (QuotientAddGroup.mk' H)
use H
haveI : Finite H := Subtype.finite
-- Note that H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y]
have ent_le : H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y] := calc
H[ψ ∘ X] + H[ψ ∘ Y] ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· exact ent_of_proj_le hX hUmeas hUunif
· exact ent_of_proj_le hY hUmeas hUunif
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- Note that (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y]
have log_sub_le : (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y] := calc
(log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) =
(H[U] - H[X]) + (H[U] - H[Y]) := by
rw [IsUniform.entropy_eq' hUunif hUmeas, SetLike.coe_sort_coe]
_ ≤ |(H[U] - H[X])| + |(H[U] - H[Y])| := by gcongr <;> exact le_abs_self _
_ ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hX
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hY
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- then the conclusion follows from the assumption `hent` and basic inequality manipulations
exact ⟨by linarith, by linarith⟩
variable [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ' : Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
lemma app_ent_PFR (α : ℝ) (hent: 20 * d[X;μ # Y;μ'] < α * (H[X; μ] + H[Y; μ'])) (hX : Measurable X)
(hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ']
< α * (H[ X; μ] + H[Y; μ']) :=
@app_ent_PFR' _ _ _ _ _ _ _ _ (MeasureSpace.mk μ) (MeasureSpace.mk μ') _ _ _ _ α hent hX hY
set_option maxHeartbeats 300000 in
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables and $\alpha < 1$ then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq (1 + α) / (2 * (1 - α)) * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 20/\alpha * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection'
(α : ℝ) (hX : Measurable X) (hY : Measurable Y) (αpos : 0 < α) (αone : α < 1) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (H[X ; μ] + H[Y ; μ']) ∧
α * (H[(QuotientAddGroup.mk' H) ∘ X ; μ] + H[(QuotientAddGroup.mk' H) ∘ Y ; μ']) ≤
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] := by
let S := { H : AddSubgroup G | (∃ (c : ℝ), 0 ≤ c ∧
log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (1 - c) * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
c * (H[X; μ] + H[Y;μ'])) ∧
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] <
α * (H[ (QuotientAddGroup.mk' H) ∘ X; μ ] + H[ (QuotientAddGroup.mk' H) ∘ Y; μ']) }
have : 0 ≤ H[X ; μ] + H[Y ; μ'] := by linarith [entropy_nonneg X μ, entropy_nonneg Y μ']
have : 0 < 1 - α := sub_pos.mpr αone
by_cases hE : (⊥ : AddSubgroup G) ∈ S
· classical
obtain ⟨H, ⟨⟨c, hc, hlog, hup⟩, hent⟩, hMaxl⟩ :=
S.toFinite.exists_maximal_wrt id S (Set.nonempty_of_mem hE)
set ψ : G →+ G ⧸ H := QuotientAddGroup.mk' H
have surj : Function.Surjective ψ := QuotientAddGroup.mk'_surjective H
set G' := G ⧸ H
have : ElementaryAddCommGroup G' 2 := ElementaryAddCommGroup.quotient_group (by decide)
(by simp [AddSubgroup.zero_mem])
obtain ⟨H', hlog', hup'⟩ := app_ent_PFR _ _ _ _ α hent ((measurable_discrete _).comp hX)
((measurable_discrete _).comp hY)
have H_ne_bot: H' ≠ ⊥ := by
by_contra!
rcases this with rfl
have inj : Function.Injective (QuotientAddGroup.mk' (⊥ : AddSubgroup G')) :=
(QuotientAddGroup.quotientBot : (G' ⧸ ⊥) ≃+ G').symm.injective
rw [entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ inj,
entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ inj] at hup'
nlinarith [entropy_nonneg (ψ ∘ X) μ, entropy_nonneg (ψ ∘ Y) μ']
let H'' := H'.comap ψ
use H''
rw [← (AddSubgroup.map_comap_eq_self_of_surjective surj _ : H''.map ψ = H')] at hup' hlog'
set H' := H''.map ψ
have Hlt : H < H'' := by
have : H = (⊥ : AddSubgroup G').comap ψ := by
simp only [ψ, AddMonoidHom.comap_bot, QuotientAddGroup.ker_mk']
rw [this, AddSubgroup.comap_lt_comap_of_surjective surj]
exact Ne.bot_lt H_ne_bot
let φ : G' ⧸ H' ≃+ G ⧸ H'' := QuotientAddGroup.quotientQuotientEquivQuotient H H'' Hlt.le
set ψ' : G' →+ G' ⧸ H' := QuotientAddGroup.mk' H'
set ψ'' : G →+ G ⧸ H'' := QuotientAddGroup.mk' H''
have diag : ψ' ∘ ψ = φ.symm ∘ ψ'' := rfl
rw [← Function.comp.assoc, ← Function.comp.assoc, diag, Function.comp.assoc,
Function.comp.assoc] at hup'
have cond : log (Nat.card H'') ≤
(1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := by
have cardprod : Nat.card H'' = Nat.card H' * Nat.card H := by
have hcard₀ := Nat.card_congr <| (AddSubgroup.addSubgroupOfEquivOfLe Hlt.le).toEquiv
have hcard₁ := Nat.card_congr <|
(QuotientAddGroup.quotientKerEquivRange (ψ.restrict H'')).toEquiv
have hcard₂ := AddSubgroup.card_eq_card_quotient_mul_card_addSubgroup (H.addSubgroupOf H'')
rw [ψ.ker_restrict H'', QuotientAddGroup.ker_mk', ψ.restrict_range H''] at hcard₁
simpa only [← Nat.card_eq_fintype_card, hcard₀, hcard₁] using hcard₂
calc
log (Nat.card H'')
_ = log ((Nat.card H' : ℝ) * (Nat.card H : ℝ)) := by rw [cardprod]; norm_cast
_ = log (Nat.card H') + log (Nat.card H) := by
rw [Real.log_mul (Nat.cast_ne_zero.2 (@Nat.card_pos H').ne')
(Nat.cast_ne_zero.2 (@Nat.card_pos H).ne')]
_ ≤ (1 + α) / 2 * (H[⇑ψ ∘ X ; μ] + H[⇑ψ ∘ Y ; μ']) + log (Nat.card H) := by gcongr
_ ≤ (1 + α) / 2 * (c * (H[X; μ] + H[Y;μ'])) +
(1 + α) / (2 * (1 - α)) * (1 - c) * (H[X ; μ] + H[Y ; μ']) := by gcongr
_ = (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X ; μ] + H[Y ; μ']) := by
field_simp; ring
have HS : H'' ∉ S := λ Hs => Hlt.ne (hMaxl H'' Hs Hlt.le)
simp only [S, Set.mem_setOf_eq, not_and, not_lt] at HS
refine ⟨?_, HS ⟨α * c, by positivity, cond, ?_⟩⟩
· calc
log (Nat.card H'')
_ ≤ (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := cond
_ ≤ (1 + α) / (2 * (1 - α)) * 1 * (H[X; μ] + H[Y;μ']) := by gcongr; simp; positivity
_ = (1 + α) / (2 * (1 - α)) * (H[X; μ] + H[Y;μ']) := by simp only [mul_one]
· calc
H[ ψ'' ∘ X; μ ] + H[ ψ'' ∘ Y; μ' ]
_ = H[ φ.symm ∘ ψ'' ∘ X; μ ] + H[ φ.symm ∘ ψ'' ∘ Y; μ' ] := by
simp_rw [← entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ φ.symm.injective,
← entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ φ.symm.injective]
_ ≤ α * (H[ ψ ∘ X; μ ] + H[ ψ ∘ Y; μ' ]) := hup'.le
_ ≤ α * (c * (H[X ; μ] + H[Y ; μ'])) := by gcongr
_ = (α * c) * (H[X ; μ] + H[Y ; μ']) := by ring
· use ⊥
constructor
· simp only [AddSubgroup.mem_bot, Nat.card_eq_fintype_card, Fintype.card_ofSubsingleton,
Nat.cast_one, log_one]
positivity
· simp only [S, Set.mem_setOf_eq, not_and, not_lt] at hE
exact hE ⟨1, by norm_num, by
norm_num; exact add_le_add (entropy_comp_le μ hX _) (entropy_comp_le μ' hY _)⟩
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq 2 * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 34 * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
34 * d[(QuotientAddGroup.mk' H) ∘ X;μ # (QuotientAddGroup.mk' H) ∘ Y;μ'] := by
rcases PFR_projection' X Y μ μ' ((3 : ℝ) / 5) hX hY (by norm_num) (by norm_num) with ⟨H, h, h'⟩
refine ⟨H, ?_, ?_⟩
· convert h
norm_num
· have : 0 ≤ d[⇑(QuotientAddGroup.mk' H) ∘ X ; μ # ⇑(QuotientAddGroup.mk' H) ∘ Y ; μ'] :=
rdist_nonneg ((measurable_discrete _).comp hX) ((measurable_discrete _).comp hY)
linarith
end F2_projection
open MeasureTheory ProbabilityTheory Real Set
open scoped BigOperators
lemma four_logs {a b c d : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) (hd : 0 < d) :
log ((a*b)/(c*d)) = log a + log b - log c - log d := by
rw [log_div, log_mul, log_mul, sub_sub] <;> positivity
lemma sum_prob_preimage {G H : Type*} {X : Finset H} {A : Set G} [Finite A] {φ : A → X}
{A_ : H → Set G} (hA : A.Nonempty) (hφ : ∀ x : X, A_ x = Subtype.val '' (φ ⁻¹' {x})) :
∑ x in X, (Nat.card (A_ x) : ℝ) / (Nat.card A) = 1 := by
rw [← Finset.sum_div]
apply (div_eq_one_iff_eq <| Nat.cast_ne_zero.mpr <| Nat.pos_iff_ne_zero.mp (@Nat.card_pos _ hA.to_subtype _)).mpr
classical
haveI := Fintype.ofFinite A
rewrite [Nat.card_eq_fintype_card, ← Finset.card_univ, Finset.card_eq_sum_card_fiberwise
<| fun a _ ↦ Finset.mem_univ (φ a), ← Finset.sum_coe_sort]
norm_cast
congr; ext
rewrite [← Set.Finite.toFinset_setOf, (Set.toFinite _).card_toFinset, ← Nat.card_eq_fintype_card,
hφ, Nat.card_image_of_injective Subtype.val_injective]; rfl
/-- Let $\phi : G\to H$ be a homomorphism and $A,B\subseteq G$ be finite subsets. If $x,y\in H$ then let $A_x=A\cap \phi^{-1}(x)$ and $B_y=B\cap \phi^{-1}(y)$. There exist $x,y\in H$ such that $A_x,B_y$ are both non-empty and
\[d[\phi(U_A);\phi(U_B)]\log \frac{\lvert A\rvert\lvert B\rvert}{\lvert A_x\rvert\lvert B_y\rvert}\leq (\mathbb{H}(\phi(U_A))+\mathbb{H}(\phi(U_B)))(d(U_A,U_B)-d(U_{A_x},U_{B_y}).\] -/
lemma single_fibres {G H Ω Ω': Type u}
[AddCommGroup G] [Countable G] [MeasurableSpace G] [MeasurableSingletonClass G]
[AddCommGroup H] [Countable H] [MeasurableSpace H] [MeasurableSingletonClass H]
[MeasureSpace Ω] [MeasureSpace Ω']
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
(φ : G →+ H)
{A B : Set G} [Finite A] [Finite B] {UA : Ω → G} {UB: Ω' → G} (hA : A.Nonempty) (hB : B.Nonempty)
(hUA': Measurable UA) (hUB': Measurable UB) (hUA: IsUniform A UA) (hUB: IsUniform B UB)
(hUA_mem : ∀ ω, UA ω ∈ A) (hUB_mem : ∀ ω, UB ω ∈ B) :
∃ (x y : H) (Ax By: Set G),
Ax = A ∩ φ.toFun ⁻¹' {x} ∧ By = B ∩ φ.toFun ⁻¹' {y} ∧ Ax.Nonempty ∧ By.Nonempty ∧
d[φ.toFun ∘ UA # φ.toFun ∘ UB]
* log ((Nat.card A) * (Nat.card B) / ((Nat.card Ax) * (Nat.card By))) ≤
(H[φ.toFun ∘ UA] + H[φ.toFun ∘ UB]) * (d[UA # UB] - dᵤ[Ax # By]) := by
have : Nonempty A := hA.to_subtype
have : Nonempty B := hB.to_subtype
haveI : FiniteRange UA := finiteRange_of_finset UA A.toFinite.toFinset (by simpa)
haveI : FiniteRange UB := finiteRange_of_finset UB B.toFinite.toFinset (by simpa)
have hUA_coe : IsUniform A.toFinite.toFinset.toSet UA := by rwa [Set.Finite.coe_toFinset]
have hUB_coe : IsUniform B.toFinite.toFinset.toSet UB := by rwa [Set.Finite.coe_toFinset]
let A_ (x : H) : Set G := A ∩ φ.toFun ⁻¹' {x}
let B_ (y : H) : Set G := B ∩ φ.toFun ⁻¹' {y}
let X : Finset H := FiniteRange.toFinset (φ.toFun ∘ UA)
let Y : Finset H := FiniteRange.toFinset (φ.toFun ∘ UB)
haveI h_Ax (x : X) : Nonempty (A_ x.val) := by
obtain ⟨ω, hω⟩ := (FiniteRange.mem_iff _ _).mp x.property
use UA ω; exact Set.mem_inter (hUA_mem ω) (by exact hω)
haveI h_By (y : Y) : Nonempty (B_ y.val) := by
obtain ⟨ω, hω⟩ := (FiniteRange.mem_iff _ _).mp y.property
use UB ω; exact Set.mem_inter (hUB_mem ω) (by exact hω)
have h_AX (a : A) : φ.toFun a.val ∈ X := by
obtain ⟨ω, hω⟩ := hUA_coe.nonempty_preimage_of_mem hUA' (A.toFinite.mem_toFinset.mpr a.property)
exact (FiniteRange.mem_iff _ (φ.toFun a.val)).mpr ⟨ω, congr_arg _ hω⟩
have h_BY (b : B) : φ.toFun b.val ∈ Y := by
obtain ⟨ω, hω⟩ := hUB_coe.nonempty_preimage_of_mem hUB' (B.toFinite.mem_toFinset.mpr b.property)
exact (FiniteRange.mem_iff _ (φ.toFun b.val)).mpr ⟨ω, congr_arg _ hω⟩
let φ_AX (a : A) : X := by use φ.toFun a.val; exact h_AX a
let φ_BY (b : B) : Y := by use φ.toFun b.val; exact h_BY b
have h_φ_AX (x : X) : A_ x.val = φ_AX ⁻¹' {x} := by ext; simp [A_, φ_AX]; simp [Subtype.ext_iff]
have h_φ_BY (y : Y) : B_ y.val = φ_BY ⁻¹' {y} := by ext; simp [B_, φ_BY]; simp [Subtype.ext_iff]
let p (x : H) (y : H) : ℝ :=
(Nat.card (A_ x).Elem) * (Nat.card (B_ y).Elem) / ((Nat.card A.Elem) * (Nat.card B.Elem))
have :
∑ x in X, ∑ y in Y, (p x y) * dᵤ[A_ x # B_ y] ≤ d[UA # UB] - d[φ.toFun ∘ UA # φ.toFun ∘ UB] :=
calc
_ = d[UA | φ.toFun ∘ UA # UB | φ.toFun ∘ UB] := by
rewrite [condRuzsaDist_eq_sum hUA' ((measurable_discrete _).comp hUA')
hUB' ((measurable_discrete _).comp hUB')]
refine Finset.sum_congr rfl <| fun x hx ↦ Finset.sum_congr rfl <| fun y hy ↦ ?_
haveI : Nonempty (A_ x) := h_Ax ⟨x, hx⟩
haveI : Nonempty (B_ y) := h_By ⟨y, hy⟩
let μx := (ℙ : Measure Ω)[|(φ.toFun ∘ UA) ⁻¹' {x}]
let μy := (ℙ : Measure Ω')[|(φ.toFun ∘ UB) ⁻¹' {y}]
have h_μ_p : IsProbabilityMeasure μx ∧ IsProbabilityMeasure μy := by
constructor <;> apply ProbabilityTheory.cond_isProbabilityMeasure <;> rw [Set.preimage_comp]
refine @IsUniform.measure_preimage_ne_zero _ _ _ _ _ _ _ _ _ _ hUA_coe hUA' _ ?_
swap; refine @IsUniform.measure_preimage_ne_zero _ _ _ _ _ _ _ _ _ _ hUB_coe hUB' _ ?_
all_goals rwa [Set.inter_comm, Set.Finite.coe_toFinset]
have h_μ_unif : IsUniform (A_ x) UA μx ∧ IsUniform (B_ y) UB μy := by
have : _ ∧ _ := ⟨hUA.restrict hUA' (φ.toFun ⁻¹' {x}), hUB.restrict hUB' (φ.toFun ⁻¹' {y})⟩
rwa [Set.inter_comm _ A, Set.inter_comm _ B] at this
rewrite [rdist_set_eq_rdist h_μ_p.1 h_μ_p.2 h_μ_unif.1 h_μ_unif.2 hUA' hUB']
show _ = (Measure.real _ (UA ⁻¹' (_ ⁻¹' _))) * (Measure.real _ (UB ⁻¹' (_ ⁻¹' _))) * _
rewrite [hUA_coe.measureReal_preimage hUA', hUB_coe.measureReal_preimage hUB']
simp_rw [p, A_, B_, IsProbabilityMeasure.measureReal_univ, one_mul]
rewrite [mul_div_mul_comm, Set.inter_comm A, Set.inter_comm B]
simp only [Set.Finite.coe_toFinset, Set.Finite.mem_toFinset, Finset.mem_val]; rfl
_ ≤ d[UA # UB] - d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
rewrite [ZeroHom.toFun_eq_coe, AddMonoidHom.toZeroHom_coe]
linarith only [rdist_le_sum_fibre φ hUA' hUB' (μ := ℙ) (μ' := ℙ)]
let M := H[φ.toFun ∘ UA] + H[φ.toFun ∘ UB]
have hM : M = ∑ x in X, ∑ y in Y, Real.negMulLog (p x y) := by
have h_compl {x y} (h_notin : (x, y) ∉ X ×ˢ Y) : Real.negMulLog (p x y) = 0 := by
unfold_let p; beta_reduce
rewrite [Finset.mem_product, not_and_or] at h_notin
suffices A_ x = ∅ ∨ B_ y = ∅ by obtain h | h := this <;> rw [h] <;> simp
refine h_notin.imp ?_ ?_
· rw [← not_nonempty_iff_eq_empty]
rintro h ⟨a, ha, rfl⟩
exact h (h_AX ⟨a, ha⟩)
· rw [← not_nonempty_iff_eq_empty]
rintro h ⟨a, ha, rfl⟩
exact h (h_BY ⟨a, ha⟩)
unfold_let M
unfold entropy
haveI := isProbabilityMeasure_map (μ := ℙ) ((measurable_discrete φ).comp hUA').aemeasurable
haveI := isProbabilityMeasure_map (μ := ℙ) ((measurable_discrete φ).comp hUB').aemeasurable
rewrite [← Finset.sum_product', ← tsum_eq_sum fun _ ↦ h_compl, ← measureEntropy_prod]
apply tsum_congr; intro; congr
rewrite [← Set.singleton_prod_singleton, Measure.smul_apply, Measure.prod_prod,
Measure.map_apply ((measurable_discrete _).comp hUA') (MeasurableSet.singleton _),
Measure.map_apply ((measurable_discrete _).comp hUB') (MeasurableSet.singleton _),
Set.preimage_comp, hUA_coe.measure_preimage hUA',
Set.preimage_comp, hUB_coe.measure_preimage hUB']
simp [p, A_, B_, mul_div_mul_comm, Set.inter_comm, ENNReal.toReal_div]
have h_sum : ∑ x in X, ∑ y in Y,
(p x y) * (M * dᵤ[A_ x # B_ y] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p x y)) ≤
M * d[UA # UB] :=
calc
_ = ∑ x in X, ∑ y in Y, (p x y) * M * dᵤ[A_ x # B_ y] + M * d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
simp_rw [hM, Finset.sum_mul, ← Finset.sum_add_distrib]
refine Finset.sum_congr rfl <| fun _ _ ↦ Finset.sum_congr rfl <| fun _ _ ↦ ?_
simp only [negMulLog, left_distrib, mul_assoc, Finset.sum_mul]
exact congrArg (HAdd.hAdd _) (by group)
_ = M * ∑ x in X, ∑ y in Y, (p x y) * dᵤ[A_ x # B_ y] + M * d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
simp_rw [Finset.mul_sum]
congr; ext; congr; ext; group
_ ≤ M * d[UA # UB] := by
rewrite [← left_distrib]
apply mul_le_mul_of_nonneg_left
· linarith
· unfold_let M
linarith only [entropy_nonneg (φ.toFun ∘ UA) ℙ, entropy_nonneg (φ.toFun ∘ UB) ℙ]
have : ∃ x : X, ∃ y : Y,
M * dᵤ[A_ x.val # B_ y.val] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p x.val y.val) ≤
M * d[UA # UB] := by
let f (xy : H × H) := (p xy.1 xy.2) * (M * d[UA # UB])
let g (xy : H × H) := (p xy.1 xy.2) *
(M * dᵤ[A_ xy.1 # B_ xy.2] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p xy.1 xy.2))
by_contra hc; push_neg at hc
replace hc : ∀ xy ∈ X ×ˢ Y, f xy < g xy := by
refine fun xy h ↦ mul_lt_mul_of_pos_left ?_ ?_
· exact hc ⟨xy.1, (Finset.mem_product.mp h).1⟩ ⟨xy.2, (Finset.mem_product.mp h).2⟩
· haveI : Nonempty _ := h_Ax ⟨xy.1, (Finset.mem_product.mp h).1⟩
haveI : Nonempty _ := h_By ⟨xy.2, (Finset.mem_product.mp h).2⟩
simp only [p, div_pos, mul_pos, Nat.cast_pos, Nat.card_pos]
have h_nonempty : Finset.Nonempty (X ×ˢ Y) := by
use ⟨φ.toFun <| UA <| Classical.choice <| ProbabilityMeasure.nonempty ⟨ℙ, inferInstance⟩,
φ.toFun <| UB <| Classical.choice <| ProbabilityMeasure.nonempty ⟨ℙ, inferInstance⟩⟩
exact Finset.mem_product.mpr ⟨FiniteRange.mem _ _, FiniteRange.mem _ _⟩
replace hc := Finset.sum_lt_sum_of_nonempty h_nonempty hc
have h_p_one : ∑ x in X ×ˢ Y, p x.1 x.2 = 1 := by
simp_rw [Finset.sum_product, p, mul_div_mul_comm, ← Finset.mul_sum,
← sum_prob_preimage hA h_φ_AX, sum_prob_preimage hB h_φ_BY, mul_one]
rewrite [← Finset.sum_mul, h_p_one, one_mul, Finset.sum_product] at hc
exact not_le_of_gt hc h_sum
obtain ⟨x, y, hxy⟩ := this
refine ⟨x, y, A_ x.val, B_ y.val, rfl, rfl, @nonempty_of_nonempty_subtype _ _ (h_Ax x), @nonempty_of_nonempty_subtype _ _ (h_By y), ?_⟩
rewrite [← inv_div, Real.log_inv]
show _ * -log (p x.val y.val) ≤ M * _
linarith only [hxy]
section dim
open Classical
variable {G : Type*} [AddCommGroup G]
/- If G ≅ ℤᵈ then there is a subgroup H of G such that A lies in a coset of H. This is helpful to
give the equivalent definition of `dimension`. Here this is stated in greated generality since the
proof carries over automatically-/
lemma exists_coset_cover (A : Set G) :
∃ (d : ℕ), ∃ (S : Submodule ℤ G) (v : G),
FiniteDimensional.finrank ℤ S = d ∧ ∀ a ∈ A, a - v ∈ S := by
existsi FiniteDimensional.finrank ℤ (⊤ : Submodule ℤ G), ⊤, 0
refine ⟨rfl, fun a _ ↦ trivial⟩
/-- The dimension of the affine span over `ℤ` of a subset of an additive group. -/
noncomputable def dimension (A : Set G) : ℕ := Nat.find (exists_coset_cover A)
lemma dimension_le_of_coset_cover (A : Set G) (S : Submodule ℤ G) (v : G)
(hA : ∀ a ∈ A, a - v ∈ S) : dimension A ≤ FiniteDimensional.finrank ℤ S := by
apply Nat.find_le
existsi S , v
exact ⟨rfl, hA⟩
lemma dimension_le_rank [Module.Finite ℤ G] (A : Set G) :
dimension A ≤ FiniteDimensional.finrank ℤ G := by
obtain ⟨S, v, hs, _⟩ := Nat.find_spec (exists_coset_cover A)
rw [dimension, ←hs]
apply Submodule.finrank_le S
end dim
variable {G : Type u} [AddCommGroup G] [Module.Free ℤ G] [Module.Finite ℤ G] [Countable G] [MeasurableSpace G] [MeasurableSingletonClass G]
open Real MeasureTheory ProbabilityTheory Pointwise Set
/-- Move to Mathlib? `Finsupp.mapRange` of a surjective function is surjective. -/
lemma Finsupp.mapRange_surjective {α : Type u_1} {M : Type u_5} {N : Type u_7} [Zero M] [Zero N] (f : M → N) (hf : f 0 = 0)
(hs : Function.Surjective f) : Function.Surjective (Finsupp.mapRange (α := α) f hf) := by
classical
let g (n : N) : M := if n = 0 then 0 else Function.surjInv hs n
have : Function.RightInverse g f := by
intro n
by_cases h : n = 0
. simp [g, h, hf]
· simp [g, h, Function.surjInv_eq hs n]
have hg : g 0 = 0 := by simp [g]
have hfg : (f ∘ g) 0 = 0 := by simp [hf, hg]
intro F
use Finsupp.mapRange g hg F
rw [← Finsupp.mapRange_comp (h := hfg)]
convert Finsupp.mapRange_id F
convert Function.RightInverse.id this
/-- A free Z-module is torsion-free. Move to Mathlib? -/
lemma torsion_free : AddMonoid.IsTorsionFree G := by
rintro x hx hn
rw [isOfFinAddOrder_iff_nsmul_eq_zero] at hn
rcases hn with ⟨ n, hn, hn' ⟩
apply_fun Module.Free.repr ℤ G at hn'
simp_rw [map_nsmul, map_zero, smul_eq_zero, AddEquivClass.map_eq_zero_iff, hx, or_false] at hn'
linarith
/-- If G is a rank n free Z-module, then G/2G is a finite elementary 2-group of cardinality 2^n. Code is slow, needs to be golfed -/
lemma weak_PFR_quotient_prelim :
let H := G ⧸ (AddMonoidHom.range (zsmulAddGroupHom 2))
ElementaryAddCommGroup H 2 ∧ Finite H ∧ Nat.card H = 2^(FiniteDimensional.finrank ℤ G) := by
set ψ : G →+ G := zsmulAddGroupHom 2
set G₂ := AddMonoidHom.range ψ
set H := G ⧸ G₂
set φ : G →+ H := QuotientAddGroup.mk' G₂
have hH_elem : ElementaryAddCommGroup H 2 := by
apply ElementaryAddCommGroup.quotient_group (by decide)
intro x; rw [AddMonoidHom.mem_range]
use x
rw [zsmulAddGroupHom_apply]
norm_cast
let B := Module.Free.ChooseBasisIndex ℤ G
let bG : Basis B ℤ G := Module.Free.chooseBasis ℤ G
have hB_fin : Fintype B := by infer_instance
have hB_card : Nat.card B = FiniteDimensional.finrank ℤ G := by
rw [FiniteDimensional.finrank_eq_card_basis bG, Nat.card_eq_fintype_card]
have hH_module : Module (ZMod 2) H := by infer_instance
let mod : (B →₀ ℤ) →+ (B →₀ ZMod 2) := Finsupp.mapRange.addMonoidHom (Int.castAddHom (ZMod 2))
let f : G →+ (B →₀ ℤ) := bG.repr
have hker : G₂ ≤ AddMonoidHom.ker (AddMonoidHom.comp mod f) := by
intro x hx
simp only [AddMonoidHom.mem_range, G₂, ψ, zsmulAddGroupHom_apply] at hx
simp_rw [AddMonoidHom.mem_ker, AddMonoidHom.coe_comp, Function.comp_apply, mod,
Finsupp.mapRange.addMonoidHom_apply, Int.coe_castAddHom]
rcases hx with ⟨y, rfl⟩
ext b
simp_rw [map_zsmul, Finsupp.mapRange_apply, Finsupp.coe_smul, Pi.smul_apply, smul_eq_mul,
Int.cast_mul, Int.cast_ofNat, Finsupp.coe_zero, Pi.zero_apply, mul_eq_zero]
left
exact ZMod.nat_cast_self 2
let g : H →+ (B →₀ ZMod 2) := QuotientAddGroup.lift G₂ (AddMonoidHom.comp mod f) hker
have hsur : Function.Surjective g := by
have h1 : Function.Surjective mod := Finsupp.mapRange_surjective (Int.castAddHom (ZMod 2)) (map_zero _) ZMod.int_cast_surjective
have h2 := h1.comp bG.repr.surjective
have h3 : mod ∘ bG.repr = g ∘ (QuotientAddGroup.mk' G₂) := by
ext x b
simp_rw [mod, Function.comp_apply, Finsupp.mapRange.addMonoidHom_apply, Int.coe_castAddHom,
Finsupp.mapRange_apply, QuotientAddGroup.coe_mk', g]
rw [QuotientAddGroup.lift_mk]
simp [mod, f]
rw [h3] at h2
apply Function.Surjective.of_comp h2
have hinj : Function.Injective g := by
rw [injective_iff_map_eq_zero]
intro x hx
rcases QuotientAddGroup.mk'_surjective G₂ x with ⟨y, rfl⟩
simp only [QuotientAddGroup.mk'_apply, g] at hx
rw [QuotientAddGroup.lift_mk] at hx
simp_rw [AddMonoidHom.coe_comp, Function.comp_apply, mod, Finsupp.mapRange.addMonoidHom_apply,
Int.coe_castAddHom, DFunLike.ext_iff,Finsupp.mapRange_apply, Finsupp.coe_zero, Pi.zero_apply,
ZMod.int_cast_zmod_eq_zero_iff_dvd] at hx
replace hx := fun x ↦ Int.mul_ediv_cancel' (hx x)
let z (b : B) := ((Module.Free.chooseBasis ℤ G).repr y) b / 2
let z' := (Finsupp.equivFunOnFinite).symm z
change ∀ b : B, 2 * z' b = (f y) b at hx
let x' := bG.repr.symm z'
rw [QuotientAddGroup.mk'_apply, QuotientAddGroup.eq_zero_iff, AddMonoidHom.mem_range]
simp_rw [ψ, zsmulAddGroupHom_apply]
use x'
change 2 • (bG.repr.symm.toLinearMap.toAddMonoidHom z') = y
rw [← AddMonoidHom.map_zsmul bG.repr.symm.toLinearMap.toAddMonoidHom z' (2 : ℤ)]
rw [← LinearEquiv.symm_apply_apply bG.repr y]
change bG.repr.symm (2 • z') = bG.repr.symm (f y)
congr
ext b
rw [Finsupp.smul_apply, ← hx b, smul_eq_mul]
rcases Function.bijective_iff_has_inverse.mp ⟨ hinj, hsur ⟩ with ⟨ g', hg' ⟩
have bH : Basis B (ZMod 2) H := by
constructor
exact {
toFun := g
invFun := g'
left_inv := hg'.1
right_inv := hg'.2
map_add' := AddMonoidHom.map_add _
map_smul' := by
intro r x
rcases ZMod.int_cast_surjective r with ⟨ n, rfl ⟩
change g ((n : ZMod 2) • x) = (n : ZMod 2) • g x
rw [intCast_smul, intCast_smul]
exact AddMonoidHom.map_zsmul g x n
}
have hH_fin : Fintype H := Module.fintypeOfFintype bH
have hH_card : Nat.card H = 2^(FiniteDimensional.finrank ℤ G) := by
rw [Nat.card_eq_fintype_card, Module.card_fintype bH, ← Nat.card_eq_fintype_card (α := B), hB_card]
congr
exact ⟨ hH_elem, Finite.of_fintype H, hH_card ⟩
open QuotientAddGroup
/-- A version of the third isomorphism theorem: if G₂ ≤ G and H' is a subgroup of G⧸G₂, then there is a canonical isomorphism between H⧸H' and G⧸N, where N is the preimage of H' in G. A bit clunky; may be a better way to do this -/
lemma third_iso {G : Type u} [AddCommGroup G] {G₂ : AddSubgroup G} (H' : AddSubgroup (G ⧸ G₂)) :
let H := G ⧸ G₂
let φ : G →+ H := mk' G₂
let N := AddSubgroup.comap φ H'
∃ e : H ⧸ H' ≃+ G ⧸ N, ∀ x : G, e (mk' H' (φ x))= mk' N x := by
set H := G ⧸ G₂
let φ : G →+ H := mk' G₂
let N := AddSubgroup.comap φ H'
have h1 : G₂ ≤ N := by
intro x hx
rw [← eq_zero_iff] at hx
have : φ x = 0 := hx
simp [N, this, AddSubgroup.zero_mem H']
set H'' := AddSubgroup.map (mk' G₂) N
have h2 : H' = H'' := by
change H' = AddSubgroup.map (mk' G₂) N
rw [AddSubgroup.map_comap_eq, AddMonoidHom.range_top_of_surjective _ (mk'_surjective G₂)]
simp
let e1 : H ⧸ H'' ≃+ G ⧸ N := quotientQuotientEquivQuotient _ _ h1
let e2 := quotientAddEquivOfEq h2
set e := e2.trans e1
use e
intro x
convert (quotientQuotientEquivQuotientAux_mk_mk _ _ h1 x) using 1
lemma single {Ω : Type u} [MeasurableSpace Ω] [DiscreteMeasurableSpace Ω] (μ : Measure Ω)
[IsProbabilityMeasure μ] {A : Set Ω} {z : Ω} (hA : μ.real A = 1) (hz : μ.real {z} > 0) :
z ∈ A := by
contrapose! hz
have : Disjoint {z} A := by simp [hz]
replace this := measureReal_union (μ := μ) this (measurableSet_discrete _)
simp [hA] at this
have h := measureReal_mono (μ := μ) (show insert z A ⊆ Set.univ by simp)
simp [this] at h
assumption
/-- Given two non-empty finite subsets A, B of a rank n free Z-module G, there exists a subgroup N and points x, y in G/N such that the fibers Ax, By of A, B over x, y respectively are non-empty, one has the inequality
$$ \log \frac{|A| |B|}{|A_x| |B_y|} ≤ 34 (d[U_A; U_B] - d[U_{A_x}; U_{B_y}])$$
and one has the dimension bound
$$ n \log 2 ≤ \log |G/N| + 40 d[U_A; U_B].$$
-/
lemma weak_PFR_asymm_prelim (A B : Set G) [Finite A] [Finite B] (hnA : A.Nonempty) (hnB : B.Nonempty):
∃ (N : AddSubgroup G) (x y : G ⧸ N) (Ax By : Set G), Ax.Nonempty ∧ By.Nonempty ∧
Set.Finite Ax ∧ Set.Finite By ∧ Ax = {z:G | z ∈ A ∧ QuotientAddGroup.mk' N z = x } ∧
By = {z:G | z ∈ B ∧ QuotientAddGroup.mk' N z = y } ∧
(log 2) * FiniteDimensional.finrank ℤ G ≤ log (Nat.card (G ⧸ N)) +
40 * dᵤ[ A # B ] ∧ log (Nat.card A) + log (Nat.card B) - log (Nat.card Ax) - log (Nat.card By)
≤ 34 * (dᵤ[ A # B ] - dᵤ[ Ax # By ]) := by
have : Nonempty A := hnA.to_subtype
have : Nonempty B := hnB.to_subtype
obtain ⟨ h_elem, h_finite, h_card ⟩ := weak_PFR_quotient_prelim (G := G)
set ψ : G →+ G := zsmulAddGroupHom 2
set G₂ := AddMonoidHom.range ψ
set H := G ⧸ G₂
let φ : G →+ H := QuotientAddGroup.mk' G₂
let _mH : MeasurableSpace H := ⊤
have h_fintype : Fintype H := Fintype.ofFinite H
have h_torsionfree := torsion_free (G := G)
obtain ⟨ Ω, mΩ, UA, hμ, hUA_mes, hUA_unif, hUA_mem, hUA_fin ⟩ := exists_isUniform_measureSpace' A
obtain ⟨ Ω', mΩ', UB, hμ', hUB_mes, hUB_unif, hUB_mem, hUB_fin ⟩ :=
exists_isUniform_measureSpace' B
rcases (PFR_projection (φ.toFun ∘ UA) (φ.toFun ∘ UB) ℙ ℙ (by measurability) (by measurability)) with ⟨H', ⟨ hH1, hH2 ⟩ ⟩
let N := AddSubgroup.comap φ H'
set φ' := QuotientAddGroup.mk' N
have _cGN : Countable (G ⧸ N) := Function.Surjective.countable (QuotientAddGroup.mk'_surjective N)
have _msGN : MeasurableSingletonClass (G ⧸ N) := by
constructor
intro x
exact MeasurableSpace.map_def.mpr (measurableSet_discrete _)
rcases third_iso H' with ⟨ e : H ⧸ H' ≃+ G ⧸ N, he ⟩
rcases single_fibres φ' hnA hnB hUA_mes hUB_mes hUA_unif hUB_unif hUA_mem hUB_mem with
⟨x, y, Ax, By, hAx, hBy, hnAx, hnBy, hcard_ineq⟩
have : Nonempty Ax := hnAx.to_subtype
have : Nonempty By := hnBy.to_subtype
have Axf : Finite Ax := by rw [hAx]; infer_instance
have Byf : Finite By := by rw [hBy]; infer_instance
have h1 := torsion_dist_shrinking UA UB ℙ ℙ hUA_mes hUB_mes h_torsionfree φ
have h2 := torsion_dist_shrinking UB UA ℙ ℙ hUB_mes hUA_mes h_torsionfree φ
rw [rdist_symm] at h2
rw [<- rdist_set_eq_rdist hμ hμ' hUA_unif hUB_unif hUA_mes hUB_mes] at h1 h2
-- using explicit .toFun casts as this saves a lot of heartbeats
change H[φ.toFun ∘ UA] ≤ 10 * dᵤ[A # B] at h1
change H[φ.toFun ∘ UB] ≤ 10 * dᵤ[A # B] at h2
replace hH1 : log (Nat.card H') ≤ 40 * dᵤ[A # B] := by
apply hH1.trans
linarith
replace h_card : log 2 * FiniteDimensional.finrank ℤ G ≤ log (Nat.card (G ⧸ N)) + 40 * dᵤ[A # B] := by
rw [mul_comm, ← log_rpow (by norm_num)]
norm_cast
classical
rwa [← h_card, ← Nat.card_congr e.toEquiv, Nat.card_eq_fintype_card, Nat.card_eq_fintype_card, ← AddSubgroup.index_mul_card H', AddSubgroup.index_eq_card, Nat.cast_mul, log_mul, add_le_add_iff_left, ← Nat.card_eq_fintype_card]
all_goals norm_cast; exact Fintype.card_ne_zero
use N, x, y, Ax, By
refine ⟨ hnAx, hnBy, Ax.toFinite, By.toFinite, hAx, hBy, h_card, ?_ ⟩
replace hH2 : H[φ'.toFun ∘ UA] + H[φ'.toFun ∘ UB] ≤ 34 * d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] := by
set X := ((mk' H').toFun ∘ φ.toFun) ∘ UA
set Y := ((mk' H').toFun ∘ φ.toFun) ∘ UB
have hX : Measurable X := Measurable.comp (measurable_discrete _) hUA_mes
have hY : Measurable Y := Measurable.comp (measurable_discrete _) hUB_mes
change H[X] + H[Y] ≤ 34 * d[X # Y] at hH2
have ha : φ'.toFun ∘ UA = e.toFun ∘ X := by ext x; exact (he (UA x)).symm
have hb : φ'.toFun ∘ UB = e.toFun ∘ Y := by ext x; exact (he (UB x)).symm
have he_inj : Function.Injective e.toFun := AddEquiv.injective e
rw [ha, hb, entropy_comp_of_injective _ hX _ he_inj, entropy_comp_of_injective _ hY _ he_inj]
have : d[e.toFun ∘ X # e.toFun ∘ Y] = d[X # Y] := rdist_of_inj hX hY e.toAddMonoidHom he_inj
rwa [this]
set X : Ω → G ⧸ N := φ'.toFun ∘ UA
set Y : Ω' → G ⧸ N := φ'.toFun ∘ UB
have hX : Measurable X := Measurable.comp (measurable_discrete _) hUA_mes
have hY : Measurable Y := Measurable.comp (measurable_discrete _) hUB_mes
rcases le_iff_lt_or_eq.mp (rdist_nonneg (μ := ℙ) (μ' := ℙ) hX hY) with h | h
swap
. rw [← h] at hH2
have hH2A : H[X] ≥ 0 := entropy_nonneg _ _
have hH2B : H[Y] ≥ 0 := entropy_nonneg _ _
have hH2A' : H[X] ≤ 0 := by linarith only [hH2, hH2A, hH2B]
have hH2B' : H[Y] ≤ 0 := by linarith only [hH2, hH2A, hH2B]
rcases const_of_nonpos_entropy (μ := ℙ) hX hH2A' with ⟨ x', hx ⟩
rcases const_of_nonpos_entropy (μ := ℙ) hY hH2B' with ⟨ y', hy ⟩
have hAAx {z : G} (hz : z ∈ A) : φ'.toFun z = x' := by
change (ℙ).real (UA⁻¹' (φ'⁻¹' {x'})) = 1 at hx
rw [← MeasureTheory.map_measureReal_apply hUA_mes (measurableSet_discrete _)] at hx
set Af := A.toFinite.toFinset
have hUAf : IsUniform Af UA := by
convert hUA_unif; simp only [Af, Set.Finite.coe_toFinset]
have hnAf : 0 < Nat.card Af := by simp only [Af, Set.Finite.mem_toFinset, Nat.card_pos]
have hzf : z ∈ Af := by simp [Af, Set.Finite.mem_toFinset, hz]
have : (Measure.map UA ℙ).real {z} > 0 := by
rw [IsUniform.measureReal_preimage_of_mem' hUAf hUA_mes hzf]
positivity
have _ : IsProbabilityMeasure ((ℙ).map UA) := by
exact MeasureTheory.isProbabilityMeasure_map (Measurable.aemeasurable hUA_mes)
replace this := single ((ℙ).map UA) hx this
rwa [Set.mem_preimage, Set.mem_singleton_iff] at this
have hxx : Ax = A := by
have h : hnAx.some ∈ Ax := hnAx.some_mem
simp [hAx] at h ⊢
have := hAAx h.1
simp [h.2] at this
intro z hz
simp [this]
convert hAAx hz
have hBBy {z : G} (hz : z ∈ B) : φ'.toFun z = y' := by
change (ℙ).real (UB⁻¹' (φ'⁻¹' {y'})) = 1 at hy
rw [← MeasureTheory.map_measureReal_apply hUB_mes (measurableSet_discrete _)] at hy
set Bf := B.toFinite.toFinset
have hUBf : IsUniform Bf UB := by convert hUB_unif; simp only [Bf, Set.Finite.coe_toFinset]
have hnBf : 0 < Nat.card Bf := by simp only [Bf, Set.Finite.mem_toFinset, Nat.card_pos]
have hzf : z ∈ Bf := by simp [Bf, Set.Finite.mem_toFinset, hz]
have : (Measure.map UB ℙ).real {z} > 0 := by
rw [IsUniform.measureReal_preimage_of_mem' hUBf hUB_mes hzf]
positivity
have _ : IsProbabilityMeasure ((ℙ).map UB) := by
exact MeasureTheory.isProbabilityMeasure_map (Measurable.aemeasurable hUB_mes)
replace this := single ((ℙ).map UB) hy this
rwa [Set.mem_preimage, Set.mem_singleton_iff] at this
have hyy : By = B := by
have h : hnBy.some ∈ By := hnBy.some_mem
simp [hBy] at h ⊢
have := hBBy h.1
simp [h.2] at this
intro z hz
simp [this]
convert hBBy hz
simp [hxx, hyy]
have := calc d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] * (log (Nat.card A) + log (Nat.card B) - log (Nat.card Ax) - log (Nat.card By))
_ = d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] * log ((Nat.card A) * (Nat.card B) / ((Nat.card Ax) * (Nat.card By))) := by
congr
convert (four_logs ?_ ?_ ?_ ?_).symm
all_goals norm_cast; exact Nat.card_pos
_ ≤ (H[φ'.toFun ∘ UA] + H[φ'.toFun ∘ UB]) * (d[UA # UB] - dᵤ[Ax # By]) := hcard_ineq
_ ≤ (34 * d[φ'.toFun ∘ UA # φ'.toFun ∘ UB]) * (d[UA # UB] - dᵤ[Ax # By]) := by
apply mul_le_mul_of_nonneg_right hH2
have := rdist_le_avg_ent (Measurable.comp (measurable_discrete φ'.toFun) hUA_mes) (Measurable.comp (measurable_discrete φ'.toFun) hUB_mes)
replace this : 0 < H[φ'.toFun ∘ UA] + H[φ'.toFun ∘ UB] := by linarith
rw [← mul_le_mul_left this]
apply le_trans _ hcard_ineq
rw [mul_zero]
change 0 ≤ d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] * log ((Nat.card A) * (Nat.card B) / ((Nat.card Ax) * (Nat.card By)))
rw [← mul_zero d[φ'.toFun ∘ UA # φ'.toFun ∘ UB], mul_le_mul_left h]
apply Real.log_nonneg
rw [one_le_div]
gcongr
. apply Nat.card_mono
. exact Set.toFinite A
rw [hAx]; exact Set.inter_subset_left _ _
apply Nat.card_mono
. exact Set.toFinite B
rw [hBy]; exact Set.inter_subset_left _ _
norm_cast
exact mul_pos Nat.card_pos Nat.card_pos
_ = d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] * (34 * (d[UA # UB] - dᵤ[Ax # By])) := by ring
_ = d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] * (34 * (dᵤ[A # B] - dᵤ[Ax # By])) := by
rw [<- rdist_set_eq_rdist hμ hμ' hUA_unif hUB_unif hUA_mes hUB_mes]
exact (mul_le_mul_left h).mp this
/-- Separating out the conclusion of `weak_PFR_asymm` for convenience of induction arguments.-/
def WeakPFRAsymmConclusion (A B : Set G) : Prop :=
∃ A' B' : Set G, A' ⊆ A ∧ B' ⊆ B ∧ A'.Nonempty ∧ B'.Nonempty ∧
log (((Nat.card A) * (Nat.card B)) / ((Nat.card A') * (Nat.card B'))) ≤ 34 * dᵤ[A # B] ∧
max (dimension A') (dimension B') ≤ (40 / log 2) * dᵤ[A # B]
/-- The property of two sets A,B of a group G not being contained in cosets of the same proper subgroup -/
def not_in_coset {G: Type u} [AddCommGroup G] (A B : Set G) : Prop := AddSubgroup.closure ((A-A) ∪ (B-B)) = ⊤
/-- In fact one has equality here, but this is tricker to prove and not needed for the argument. -/
| lemma dimension_of_shift {G: Type u} [AddCommGroup G]
{H: AddSubgroup G} (A : Set H) (x : G) :
dimension ((fun a:H ↦ (a:G) + x) '' A) ≤ dimension A | dimension_of_shift | 25309ad 20231211 | 1612a14 20240111 | pfr/PFR/WeakPFR.lean | {
"lineInFile": 968,
"tokenPositionInFile": 51218,
"theoremPositionInFile": 27
} | {
"inFilePremises": true,
"repositoryPremises": false
} | {
"hasProof": true,
"proof": "by\n classical\n rcases Nat.find_spec (exists_coset_cover A) with ⟨ S, v, hrank, hshift ⟩\n change FiniteDimensional.finrank ℤ S = dimension A at hrank\n rw [← hrank]\n convert dimension_le_of_coset_cover _ (Submodule.map H.subtype.toIntLinearMap S) (x+v) ?_\n . apply LinearEquiv.finrank_eq\n exact Submodule.equivMapOfInjective _ (by simpa using Subtype.val_injective) _\n intro a ha\n rw [Set.mem_image] at ha\n rcases ha with ⟨ b, ⟨ hb, hb'⟩ ⟩\n rw [Submodule.mem_map]\n use b - v, hshift b hb\n simp [← hb']\n abel",
"proofType": "tactic",
"proofLengthLines": 15,
"proofLengthTokens": 521
} | pfr |
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Quotient
import Mathlib.GroupTheory.Torsion
import Mathlib.GroupTheory.Torsion
import Mathlib.LinearAlgebra.FreeModule.PID
import PFR.Mathlib.Data.Set.Pointwise.SMul
import PFR.EntropyPFR
import PFR.ImprovedPFR
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Mathlib.GroupTheory.Torsion
/-!
# Weak PFR over the integers
Here we use the entropic form of PFR to deduce a weak form of PFR over the integers.
## Main statement
* `weak_PFR_int`: Let $A\subseteq \mathbb{Z}^d$ and $\lvert A+A\rvert\leq K\lvert A\rvert$.
There exists $A'\subseteq A$ such that $\lvert A'\rvert \geq K^{-17}\lvert A\rvert$ and
$\dim A' \leq (40/\log 2)\log K$.
-/
section AddCommGroup
variable {G : Type*} [AddCommGroup G] {A B : Set G}
open Set
open scoped Pointwise
def IsShift (A B : Set G) : Prop := ∃ x : G, A = x +ᵥ B
lemma IsShift.sub_self_congr : IsShift A B → A - A = B - B := by
rintro ⟨x, rfl⟩; simp [vadd_sub_vadd_comm, singleton_zero]
lemma IsShift.card_congr : IsShift A B → Nat.card A = Nat.card B := by rintro ⟨x, rfl⟩; simp
/-- The property of two sets A, B of a group G not being contained in cosets of the same proper
subgroup -/
def NotInCoset (A B : Set G) : Prop := AddSubgroup.closure ((A - A) ∪ (B - B)) = ⊤
/-- Without loss of generality, one can move (up to translation and embedding) any pair A, B of non-empty sets into a subgroup where they are not in a coset. -/
lemma wlog_notInCoset (hA : A.Nonempty) (hB : B.Nonempty) :
∃ (G' : AddSubgroup G) (A' B' : Set G'), IsShift A A' ∧ IsShift B B' ∧ NotInCoset A' B' := by
obtain ⟨x, hx⟩ := hA
obtain ⟨y, hy⟩ := hB
set G' := AddSubgroup.closure ((A - A) ∪ (B - B))
set A' : Set G' := (↑) ⁻¹' ((-x) +ᵥ A)
set B' : Set G' := (↑) ⁻¹' ((-y) +ᵥ B)
have hxA : -x +ᵥ A ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hx).trans $ (subset_union_left ..).trans
AddSubgroup.subset_closure
have hyB : -y +ᵥ B ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hy).trans $ (subset_union_right ..).trans
AddSubgroup.subset_closure
have hA : IsShift A A' := ⟨x, by rw [Set.image_preimage_eq_of_subset hxA, vadd_neg_vadd]⟩
have hB : IsShift B B' := ⟨y, by rw [Set.image_preimage_eq_of_subset hyB, vadd_neg_vadd]⟩
refine ⟨G', A', B', hA, hB, ?_⟩
unfold NotInCoset
convert AddSubgroup.closure_preimage_eq_top ((A - A) ∪ (B - B))
simp_rw [preimage_union, hA.sub_self_congr, hB.sub_self_congr]
rw [preimage_sub, preimage_sub]
simp [A', B', preimage_image_preimage]
all_goals apply_rules [Subtype.coe_injective, (image_preimage_subset ..).trans, hxA, hyB]
end AddCommGroup
section Torsion
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [MeasurableSpace G] [MeasurableSingletonClass G]
[Countable G] {Ω Ω' : Type u} [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ': Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
/-- If $G$ is torsion-free and $X,Y$ are $G$-valued random variables then $d[X;2Y]\leq 5d[X;Y]$. -/
lemma torsion_free_doubling [FiniteRange X] [FiniteRange Y]
(hX : Measurable X) (hY : Measurable Y) (hG : AddMonoid.IsTorsionFree G) :
d[X ; μ # (Y + Y) ; μ'] ≤ 5 * d[X; μ # Y ; μ'] := by
obtain ⟨A, mA, μA, X', Y'₁, Y'₂, hμA, h_indep, hX'_meas, hY'₁_meas, hY'₂_meas, hX'_ident,
hY'₁_ident, hY'₂_ident, _, _, _⟩ := independent_copies3_nondep_finiteRange hX hY hY μ μ' μ'
have h_meas (i : Fin 3) : Measurable (![X', Y'₁, Y'₂] i) := by fin_cases i <;> assumption
haveI : NoZeroSMulDivisors ℕ G := hG.noZeroNsmulDivisors
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨x, y₁, y₂⟩ ↦ (x, y₁ - y₂, x - 2 • y₁)
show H[f ∘ ⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] = _
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hX'_meas <| Measurable.prod hY'₁_meas hY'₂_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun X' (prod Y'₁ Y'₂) μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 1 2 0 (by decide) (by decide)
rw [this.entropy_pair_eq_add hX'_meas (by exact Measurable.prod hY'₁_meas hY'₂_meas),
IndepFun.entropy_pair_eq_add hY'₁_meas hY'₂_meas (h_indep.indepFun (show 1 ≠ 2 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, two_mul]
have : H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[X ; μ] + H[Y ; μ'] := calc
H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[⟨X', Y'₁⟩ ; μA] := by
let f : G × G → G × G := fun ⟨x, y₁⟩ ↦ (x, x - 2 • y₁)
show H[f ∘ ⟨X', Y'₁⟩ ; μA] = _
apply entropy_comp_of_injective μA (by exact Measurable.prod hX'_meas hY'₁_meas) f
exact fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + H[Y ; μ'] := by
rw [IndepFun.entropy_pair_eq_add hX'_meas hY'₁_meas (h_indep.indepFun (show 0 ≠ 1 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq]
let f : G × G → G × G := fun ⟨x, y⟩ ↦ (x, y - x)
have hf : f.Injective := fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all
have : H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] := calc
H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] = H[f ∘ ⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
show _ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂ - (Y'₁ - Y'₂)⟩ ; μA]
rw [sub_sub_sub_cancel_right, ← sub_add_eq_sub_sub, two_nsmul]
_ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
refine entropy_comp_of_injective μA (Measurable.prod ?_ ?_) f hf
· exact Measurable.sub hY'₁_meas hY'₂_meas
· exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
_ ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] :=
entropy_pair_le_add (hY'₁_meas.sub' hY'₂_meas) (hX'_meas.sub' hY'₁_meas |>.sub' hY'₂_meas) μA
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] + H[X' - 2 • Y'₁ ; μA] ≤
H[⟨X', X' - 2 • Y'₁⟩ ; μA] + H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] := by
haveI : FiniteRange (Y'₁ - Y'₂) := FiniteRange.sub Y'₁ Y'₂
haveI : FiniteRange (2 • Y'₁) := by show FiniteRange ((fun x ↦ 2 • x) ∘ Y'₁); infer_instance
apply entropy_triple_add_entropy_le μA hX'_meas (Measurable.sub hY'₁_meas hY'₂_meas)
exact Measurable.sub' hX'_meas <| Measurable.const_smul hY'₁_meas 2
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨y₁, y₂, x⟩ ↦ (y₁, y₂, x - y₁ - y₂)
show H[f ∘ ⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA]
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hY'₁_meas <| Measurable.prod hY'₂_meas hX'_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun Y'₁ (prod Y'₂ X') μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 2 0 1 (by decide) (by decide)
rw [this.entropy_pair_eq_add hY'₁_meas (by exact Measurable.prod hY'₂_meas hX'_meas),
IndepFun.entropy_pair_eq_add hY'₂_meas hX'_meas (h_indep.indepFun (show 2 ≠ 0 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq]
group
have : H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₂ ; μA] := calc
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₁, X' - Y'₂⟩ ; μA] := by rw [sub_right_comm] ; rfl
_ = H[⟨Y'₁, X' - Y'₂⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₁_meas <| Measurable.sub hX'_meas hY'₂_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₂ ; μA] := by
haveI : FiniteRange (X' - Y'₂) := FiniteRange.sub X' Y'₂
convert IndepFun.entropy_pair_eq_add hY'₁_meas (hX'_meas.sub hY'₂_meas)
<| h_indep.indepFun_sub_right h_meas 1 0 2 (by decide) (by decide)
exact hY'₁_ident.entropy_eq.symm
have : H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₁ ; μA] := calc
H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₂, X' - Y'₁⟩ ; μA] := rfl
_ = H[⟨Y'₂, X' - Y'₁⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₂_meas <| Measurable.sub hX'_meas hY'₁_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₁ ; μA] := by
haveI : FiniteRange (X' - Y'₁) := FiniteRange.sub X' Y'₁
convert IndepFun.entropy_pair_eq_add hY'₂_meas (hX'_meas.sub hY'₁_meas)
<| h_indep.indepFun_sub_right h_meas 2 0 1 (by decide) (by decide)
exact hY'₂_ident.entropy_eq.symm
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] ≤
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] + H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
apply entropy_triple_add_entropy_le μA hY'₁_meas hY'₂_meas
exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
have : H[X' - Y'₁ - Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := calc
H[X' - Y'₁ - Y'₂ ; μA] ≤ H[X' - Y'₁ ; μA] + H[X' - Y'₂ ; μA] - H[X ; μ] := by linarith
_ = 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := by
nth_rw 1 [two_mul, ← hX'_ident.rdist_eq hY'₁_ident, ← hX'_ident.rdist_eq hY'₂_ident]
have h1 : d[X' ; μA # Y'₁ ; μA] = H[X' - Y'₁ ; μA] - H[X' ; μA] / 2 - H[Y'₁ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 1 by decide)).rdist_eq hX'_meas hY'₁_meas
have h2 : d[X' ; μA # Y'₂ ; μA] = H[X' - Y'₂ ; μA] - H[X' ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 2 by decide)).rdist_eq hX'_meas hY'₂_meas
rw [h1, h2, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, hX'_ident.entropy_eq]
group
have : d[X ; μ # 2 • Y ; μ'] ≤
d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := calc
d[X ; μ # 2 • Y ; μ'] = H[X' - 2 • Y'₁ ; μA] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by
have h2Y_ident : IdentDistrib (2 • Y'₁) (2 • Y) (μ := μA) (ν := μ') := by
convert hY'₁_ident.comp <| measurable_discrete <| fun g ↦ 2 • g
have h2Y_indep : IndepFun X' (2 • Y'₁) (μ := μA) := by
convert (h_indep.indepFun (show 0 ≠ 1 by decide)).comp measurable_id
(measurable_const_smul 2)
rw [← hX'_ident.rdist_eq h2Y_ident,
h2Y_indep.rdist_eq hX'_meas <| Measurable.const_smul hY'₁_meas 2,
hX'_ident.entropy_eq, h2Y_ident.entropy_eq]
_ ≤ H[Y'₁ - Y'₂ ; μA] + 2 * d[X ; μ # Y ; μ'] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by linarith
_ = d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := by
have H2Y : H[2 • Y ; μ'] = H[Y ; μ'] := by
let f (g : G) := 2 • g
exact entropy_comp_of_injective μ' hY f (fun _ _ ↦ by simp [f, smul_right_inj])
have : d[Y'₁ ; μA # Y'₂ ; μA] = H[Y'₁ - Y'₂ ; μA] - H[Y'₁ ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 1 ≠ 2 by decide)).rdist_eq hY'₁_meas hY'₂_meas
rw [this, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, H2Y]
group
have : d[Y'₁ ; μA # Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] := by
rw [two_mul]
convert rdist_triangle hY'₁_meas hX'_meas hY'₂_meas (μ := μA) (μ' := μA) (μ'' := μA)
· exact rdist_symm.trans (hY'₁_ident.rdist_eq hX'_ident).symm
· exact (hX'_ident.rdist_eq hY'₂_ident).symm
rw [← two_nsmul]
linarith [abs_le.mp <| diff_ent_le_rdist hX hY (μ := μ) (μ' := μ')]
/-- If $G$ is a torsion-free group and $X,Y$ are $G$-valued random variables and
$\phi : G\to \mathbb{F}_2^d$ is a homomorphism then
\[\mathbb{H}(\phi(X))\leq 10d[X;Y].\] -/
lemma torsion_dist_shrinking {H : Type u} [FiniteRange X] [FiniteRange Y] (hX : Measurable X)
(hY : Measurable Y) [AddCommGroup H] [ElementaryAddCommGroup H 2]
[MeasurableSpace H] [MeasurableSingletonClass H] [Countable H]
(hG : AddMonoid.IsTorsionFree G) (φ : G →+ H) :
H[φ ∘ X ; μ] ≤ 10 * d[X; μ # Y ; μ'] := by
have :=
calc d[φ ∘ X ; μ # φ ∘ (Y + Y); μ'] ≤ d[X; μ # (Y + Y) ; μ'] := rdist_of_hom_le φ hX (Measurable.add hY hY)
_ ≤ 5 * d[X; μ # Y ; μ'] := torsion_free_doubling X Y μ μ' hX hY hG
have eq_zero : φ ∘ (Y + Y) = fun _ ↦ 0 := by ext x ; simp only [Function.comp_apply, Pi.add_apply,
map_add, ElementaryAddCommGroup.add_self]
rwa [eq_zero, rdist_zero_eq_half_ent, div_le_iff zero_lt_two, mul_assoc, mul_comm _ 2, ←mul_assoc,
show (5*2 : ℝ) = 10 by norm_num] at this
end Torsion
instance {G : Type u} [AddCommGroup G] [Fintype G] [MeasurableSpace G] [MeasurableSingletonClass G] (H : AddSubgroup G)
: MeasurableSingletonClass (G ⧸ H) :=
⟨λ _ ↦ by { rw [measurableSet_quotient]; simp [measurableSet_discrete] }⟩
section F2_projection
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [ElementaryAddCommGroup G 2] [Fintype G] [MeasurableSpace G]
[MeasurableSingletonClass G] {Ω Ω' : Type*}
/-- Let $G=\mathbb{F}_2^n$ and $X,Y$ be $G$-valued random variables such that
\[\mathbb{H}(X)+\mathbb{H}(Y)> (20/\alpha) d[X;Y],\]
for some $\alpha > 0$.
There is a non-trivial subgroup $H\leq G$ such that
\[\log \lvert H\rvert <(1+\alpha)/2 (\mathbb{H}(X)+\mathbb{H}(Y))\] and
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))< \alpha (\mathbb{H}(X)+\mathbb{H}(Y))\]
where $\psi:G\to G/H$ is the natural projection homomorphism.
-/
lemma app_ent_PFR' [MeasureSpace Ω] [MeasureSpace Ω'] (X : Ω → G) (Y : Ω' → G)
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
{α : ℝ} (hent : 20 * d[X # Y] < α * (H[X] + H[Y])) (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X] + H[Y]) ∧
H[(QuotientAddGroup.mk' H) ∘ X] + H[(QuotientAddGroup.mk' H) ∘ Y] < α * (H[X] + H[Y]) := by
let p : refPackage Ω Ω' G := {
X₀₁ := X
X₀₂ := Y
hmeas1 := hX
hmeas2 := hY
η := 1/8
hη := by norm_num
hη' := by norm_num }
obtain ⟨H, Ω'', hΩ'', U, _, hUmeas, hUunif, ineq⟩ := entropic_PFR_conjecture_improv p rfl
let ψ := (QuotientAddGroup.mk' H)
use H
haveI : Finite H := Subtype.finite
-- Note that H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y]
have ent_le : H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y] := calc
H[ψ ∘ X] + H[ψ ∘ Y] ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· exact ent_of_proj_le hX hUmeas hUunif
· exact ent_of_proj_le hY hUmeas hUunif
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- Note that (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y]
have log_sub_le : (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y] := calc
(log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) =
(H[U] - H[X]) + (H[U] - H[Y]) := by
rw [IsUniform.entropy_eq' hUunif hUmeas, SetLike.coe_sort_coe]
_ ≤ |(H[U] - H[X])| + |(H[U] - H[Y])| := by gcongr <;> exact le_abs_self _
_ ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hX
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hY
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- then the conclusion follows from the assumption `hent` and basic inequality manipulations
exact ⟨by linarith, by linarith⟩
variable [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ' : Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
lemma app_ent_PFR (α : ℝ) (hent: 20 * d[X;μ # Y;μ'] < α * (H[X; μ] + H[Y; μ'])) (hX : Measurable X)
(hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ']
< α * (H[ X; μ] + H[Y; μ']) :=
@app_ent_PFR' _ _ _ _ _ _ _ _ (MeasureSpace.mk μ) (MeasureSpace.mk μ') _ _ _ _ α hent hX hY
set_option maxHeartbeats 300000 in
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables and $\alpha < 1$ then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq (1 + α) / (2 * (1 - α)) * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 20/\alpha * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection'
(α : ℝ) (hX : Measurable X) (hY : Measurable Y) (αpos : 0 < α) (αone : α < 1) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (H[X ; μ] + H[Y ; μ']) ∧
α * (H[(QuotientAddGroup.mk' H) ∘ X ; μ] + H[(QuotientAddGroup.mk' H) ∘ Y ; μ']) ≤
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] := by
let S := { H : AddSubgroup G | (∃ (c : ℝ), 0 ≤ c ∧
log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (1 - c) * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
c * (H[X; μ] + H[Y;μ'])) ∧
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] <
α * (H[ (QuotientAddGroup.mk' H) ∘ X; μ ] + H[ (QuotientAddGroup.mk' H) ∘ Y; μ']) }
have : 0 ≤ H[X ; μ] + H[Y ; μ'] := by linarith [entropy_nonneg X μ, entropy_nonneg Y μ']
have : 0 < 1 - α := sub_pos.mpr αone
by_cases hE : (⊥ : AddSubgroup G) ∈ S
· classical
obtain ⟨H, ⟨⟨c, hc, hlog, hup⟩, hent⟩, hMaxl⟩ :=
S.toFinite.exists_maximal_wrt id S (Set.nonempty_of_mem hE)
set ψ : G →+ G ⧸ H := QuotientAddGroup.mk' H
have surj : Function.Surjective ψ := QuotientAddGroup.mk'_surjective H
set G' := G ⧸ H
have : ElementaryAddCommGroup G' 2 := ElementaryAddCommGroup.quotient_group (by decide)
(by simp [AddSubgroup.zero_mem])
obtain ⟨H', hlog', hup'⟩ := app_ent_PFR _ _ _ _ α hent ((measurable_discrete _).comp hX)
((measurable_discrete _).comp hY)
have H_ne_bot: H' ≠ ⊥ := by
by_contra!
rcases this with rfl
have inj : Function.Injective (QuotientAddGroup.mk' (⊥ : AddSubgroup G')) :=
(QuotientAddGroup.quotientBot : (G' ⧸ ⊥) ≃+ G').symm.injective
rw [entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ inj,
entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ inj] at hup'
nlinarith [entropy_nonneg (ψ ∘ X) μ, entropy_nonneg (ψ ∘ Y) μ']
let H'' := H'.comap ψ
use H''
rw [← (AddSubgroup.map_comap_eq_self_of_surjective surj _ : H''.map ψ = H')] at hup' hlog'
set H' := H''.map ψ
have Hlt : H < H'' := by
have : H = (⊥ : AddSubgroup G').comap ψ := by
simp only [ψ, AddMonoidHom.comap_bot, QuotientAddGroup.ker_mk']
rw [this, AddSubgroup.comap_lt_comap_of_surjective surj]
exact Ne.bot_lt H_ne_bot
let φ : G' ⧸ H' ≃+ G ⧸ H'' := QuotientAddGroup.quotientQuotientEquivQuotient H H'' Hlt.le
set ψ' : G' →+ G' ⧸ H' := QuotientAddGroup.mk' H'
set ψ'' : G →+ G ⧸ H'' := QuotientAddGroup.mk' H''
have diag : ψ' ∘ ψ = φ.symm ∘ ψ'' := rfl
rw [← Function.comp.assoc, ← Function.comp.assoc, diag, Function.comp.assoc,
Function.comp.assoc] at hup'
have cond : log (Nat.card H'') ≤
(1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := by
have cardprod : Nat.card H'' = Nat.card H' * Nat.card H := by
have hcard₀ := Nat.card_congr <| (AddSubgroup.addSubgroupOfEquivOfLe Hlt.le).toEquiv
have hcard₁ := Nat.card_congr <|
(QuotientAddGroup.quotientKerEquivRange (ψ.restrict H'')).toEquiv
have hcard₂ := AddSubgroup.card_eq_card_quotient_mul_card_addSubgroup (H.addSubgroupOf H'')
rw [ψ.ker_restrict H'', QuotientAddGroup.ker_mk', ψ.restrict_range H''] at hcard₁
simpa only [← Nat.card_eq_fintype_card, hcard₀, hcard₁] using hcard₂
calc
log (Nat.card H'')
_ = log ((Nat.card H' : ℝ) * (Nat.card H : ℝ)) := by rw [cardprod]; norm_cast
_ = log (Nat.card H') + log (Nat.card H) := by
rw [Real.log_mul (Nat.cast_ne_zero.2 (@Nat.card_pos H').ne')
(Nat.cast_ne_zero.2 (@Nat.card_pos H).ne')]
_ ≤ (1 + α) / 2 * (H[⇑ψ ∘ X ; μ] + H[⇑ψ ∘ Y ; μ']) + log (Nat.card H) := by gcongr
_ ≤ (1 + α) / 2 * (c * (H[X; μ] + H[Y;μ'])) +
(1 + α) / (2 * (1 - α)) * (1 - c) * (H[X ; μ] + H[Y ; μ']) := by gcongr
_ = (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X ; μ] + H[Y ; μ']) := by
field_simp; ring
have HS : H'' ∉ S := λ Hs => Hlt.ne (hMaxl H'' Hs Hlt.le)
simp only [S, Set.mem_setOf_eq, not_and, not_lt] at HS
refine ⟨?_, HS ⟨α * c, by positivity, cond, ?_⟩⟩
· calc
log (Nat.card H'')
_ ≤ (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := cond
_ ≤ (1 + α) / (2 * (1 - α)) * 1 * (H[X; μ] + H[Y;μ']) := by gcongr; simp; positivity
_ = (1 + α) / (2 * (1 - α)) * (H[X; μ] + H[Y;μ']) := by simp only [mul_one]
· calc
H[ ψ'' ∘ X; μ ] + H[ ψ'' ∘ Y; μ' ]
_ = H[ φ.symm ∘ ψ'' ∘ X; μ ] + H[ φ.symm ∘ ψ'' ∘ Y; μ' ] := by
simp_rw [← entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ φ.symm.injective,
← entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ φ.symm.injective]
_ ≤ α * (H[ ψ ∘ X; μ ] + H[ ψ ∘ Y; μ' ]) := hup'.le
_ ≤ α * (c * (H[X ; μ] + H[Y ; μ'])) := by gcongr
_ = (α * c) * (H[X ; μ] + H[Y ; μ']) := by ring
· use ⊥
constructor
· simp only [AddSubgroup.mem_bot, Nat.card_eq_fintype_card, Fintype.card_ofSubsingleton,
Nat.cast_one, log_one]
positivity
· simp only [S, Set.mem_setOf_eq, not_and, not_lt] at hE
exact hE ⟨1, by norm_num, by
norm_num; exact add_le_add (entropy_comp_le μ hX _) (entropy_comp_le μ' hY _)⟩
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq 2 * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 34 * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
34 * d[(QuotientAddGroup.mk' H) ∘ X;μ # (QuotientAddGroup.mk' H) ∘ Y;μ'] := by
rcases PFR_projection' X Y μ μ' ((3 : ℝ) / 5) hX hY (by norm_num) (by norm_num) with ⟨H, h, h'⟩
refine ⟨H, ?_, ?_⟩
· convert h
norm_num
· have : 0 ≤ d[⇑(QuotientAddGroup.mk' H) ∘ X ; μ # ⇑(QuotientAddGroup.mk' H) ∘ Y ; μ'] :=
rdist_nonneg ((measurable_discrete _).comp hX) ((measurable_discrete _).comp hY)
linarith
end F2_projection
open MeasureTheory ProbabilityTheory Real Set
open scoped BigOperators
lemma four_logs {a b c d : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) (hd : 0 < d) :
log ((a*b)/(c*d)) = log a + log b - log c - log d := by
rw [log_div, log_mul, log_mul, sub_sub] <;> positivity
lemma sum_prob_preimage {G H : Type*} {X : Finset H} {A : Set G} [Finite A] {φ : A → X}
{A_ : H → Set G} (hA : A.Nonempty) (hφ : ∀ x : X, A_ x = Subtype.val '' (φ ⁻¹' {x})) :
∑ x in X, (Nat.card (A_ x) : ℝ) / (Nat.card A) = 1 := by
rw [← Finset.sum_div]
apply (div_eq_one_iff_eq <| Nat.cast_ne_zero.mpr <| Nat.pos_iff_ne_zero.mp (@Nat.card_pos _ hA.to_subtype _)).mpr
classical
haveI := Fintype.ofFinite A
rewrite [Nat.card_eq_fintype_card, ← Finset.card_univ, Finset.card_eq_sum_card_fiberwise
<| fun a _ ↦ Finset.mem_univ (φ a), ← Finset.sum_coe_sort]
norm_cast
congr; ext
rewrite [← Set.Finite.toFinset_setOf, (Set.toFinite _).card_toFinset, ← Nat.card_eq_fintype_card,
hφ, Nat.card_image_of_injective Subtype.val_injective]; rfl
/-- Let $\phi : G\to H$ be a homomorphism and $A,B\subseteq G$ be finite subsets. If $x,y\in H$ then let $A_x=A\cap \phi^{-1}(x)$ and $B_y=B\cap \phi^{-1}(y)$. There exist $x,y\in H$ such that $A_x,B_y$ are both non-empty and
\[d[\phi(U_A);\phi(U_B)]\log \frac{\lvert A\rvert\lvert B\rvert}{\lvert A_x\rvert\lvert B_y\rvert}\leq (\mathbb{H}(\phi(U_A))+\mathbb{H}(\phi(U_B)))(d(U_A,U_B)-d(U_{A_x},U_{B_y}).\] -/
lemma single_fibres {G H Ω Ω': Type u}
[AddCommGroup G] [Countable G] [MeasurableSpace G] [MeasurableSingletonClass G]
[AddCommGroup H] [Countable H] [MeasurableSpace H] [MeasurableSingletonClass H]
[MeasureSpace Ω] [MeasureSpace Ω']
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
(φ : G →+ H)
{A B : Set G} [Finite A] [Finite B] {UA : Ω → G} {UB: Ω' → G} (hA : A.Nonempty) (hB : B.Nonempty)
(hUA': Measurable UA) (hUB': Measurable UB) (hUA: IsUniform A UA) (hUB: IsUniform B UB)
(hUA_mem : ∀ ω, UA ω ∈ A) (hUB_mem : ∀ ω, UB ω ∈ B) :
∃ (x y : H) (Ax By: Set G),
Ax = A ∩ φ.toFun ⁻¹' {x} ∧ By = B ∩ φ.toFun ⁻¹' {y} ∧ Ax.Nonempty ∧ By.Nonempty ∧
d[φ.toFun ∘ UA # φ.toFun ∘ UB]
* log ((Nat.card A) * (Nat.card B) / ((Nat.card Ax) * (Nat.card By))) ≤
(H[φ.toFun ∘ UA] + H[φ.toFun ∘ UB]) * (d[UA # UB] - dᵤ[Ax # By]) := by
have : Nonempty A := hA.to_subtype
have : Nonempty B := hB.to_subtype
haveI : FiniteRange UA := finiteRange_of_finset UA A.toFinite.toFinset (by simpa)
haveI : FiniteRange UB := finiteRange_of_finset UB B.toFinite.toFinset (by simpa)
have hUA_coe : IsUniform A.toFinite.toFinset.toSet UA := by rwa [Set.Finite.coe_toFinset]
have hUB_coe : IsUniform B.toFinite.toFinset.toSet UB := by rwa [Set.Finite.coe_toFinset]
let A_ (x : H) : Set G := A ∩ φ.toFun ⁻¹' {x}
let B_ (y : H) : Set G := B ∩ φ.toFun ⁻¹' {y}
let X : Finset H := FiniteRange.toFinset (φ.toFun ∘ UA)
let Y : Finset H := FiniteRange.toFinset (φ.toFun ∘ UB)
haveI h_Ax (x : X) : Nonempty (A_ x.val) := by
obtain ⟨ω, hω⟩ := (FiniteRange.mem_iff _ _).mp x.property
use UA ω; exact Set.mem_inter (hUA_mem ω) (by exact hω)
haveI h_By (y : Y) : Nonempty (B_ y.val) := by
obtain ⟨ω, hω⟩ := (FiniteRange.mem_iff _ _).mp y.property
use UB ω; exact Set.mem_inter (hUB_mem ω) (by exact hω)
have h_AX (a : A) : φ.toFun a.val ∈ X := by
obtain ⟨ω, hω⟩ := hUA_coe.nonempty_preimage_of_mem hUA' (A.toFinite.mem_toFinset.mpr a.property)
exact (FiniteRange.mem_iff _ (φ.toFun a.val)).mpr ⟨ω, congr_arg _ hω⟩
have h_BY (b : B) : φ.toFun b.val ∈ Y := by
obtain ⟨ω, hω⟩ := hUB_coe.nonempty_preimage_of_mem hUB' (B.toFinite.mem_toFinset.mpr b.property)
exact (FiniteRange.mem_iff _ (φ.toFun b.val)).mpr ⟨ω, congr_arg _ hω⟩
let φ_AX (a : A) : X := by use φ.toFun a.val; exact h_AX a
let φ_BY (b : B) : Y := by use φ.toFun b.val; exact h_BY b
have h_φ_AX (x : X) : A_ x.val = φ_AX ⁻¹' {x} := by ext; simp [A_, φ_AX]; simp [Subtype.ext_iff]
have h_φ_BY (y : Y) : B_ y.val = φ_BY ⁻¹' {y} := by ext; simp [B_, φ_BY]; simp [Subtype.ext_iff]
let p (x : H) (y : H) : ℝ :=
(Nat.card (A_ x).Elem) * (Nat.card (B_ y).Elem) / ((Nat.card A.Elem) * (Nat.card B.Elem))
have :
∑ x in X, ∑ y in Y, (p x y) * dᵤ[A_ x # B_ y] ≤ d[UA # UB] - d[φ.toFun ∘ UA # φ.toFun ∘ UB] :=
calc
_ = d[UA | φ.toFun ∘ UA # UB | φ.toFun ∘ UB] := by
rewrite [condRuzsaDist_eq_sum hUA' ((measurable_discrete _).comp hUA')
hUB' ((measurable_discrete _).comp hUB')]
refine Finset.sum_congr rfl <| fun x hx ↦ Finset.sum_congr rfl <| fun y hy ↦ ?_
haveI : Nonempty (A_ x) := h_Ax ⟨x, hx⟩
haveI : Nonempty (B_ y) := h_By ⟨y, hy⟩
let μx := (ℙ : Measure Ω)[|(φ.toFun ∘ UA) ⁻¹' {x}]
let μy := (ℙ : Measure Ω')[|(φ.toFun ∘ UB) ⁻¹' {y}]
have h_μ_p : IsProbabilityMeasure μx ∧ IsProbabilityMeasure μy := by
constructor <;> apply ProbabilityTheory.cond_isProbabilityMeasure <;> rw [Set.preimage_comp]
refine @IsUniform.measure_preimage_ne_zero _ _ _ _ _ _ _ _ _ _ hUA_coe hUA' _ ?_
swap; refine @IsUniform.measure_preimage_ne_zero _ _ _ _ _ _ _ _ _ _ hUB_coe hUB' _ ?_
all_goals rwa [Set.inter_comm, Set.Finite.coe_toFinset]
have h_μ_unif : IsUniform (A_ x) UA μx ∧ IsUniform (B_ y) UB μy := by
have : _ ∧ _ := ⟨hUA.restrict hUA' (φ.toFun ⁻¹' {x}), hUB.restrict hUB' (φ.toFun ⁻¹' {y})⟩
rwa [Set.inter_comm _ A, Set.inter_comm _ B] at this
rewrite [rdist_set_eq_rdist h_μ_p.1 h_μ_p.2 h_μ_unif.1 h_μ_unif.2 hUA' hUB']
show _ = (Measure.real _ (UA ⁻¹' (_ ⁻¹' _))) * (Measure.real _ (UB ⁻¹' (_ ⁻¹' _))) * _
rewrite [hUA_coe.measureReal_preimage hUA', hUB_coe.measureReal_preimage hUB']
simp_rw [p, A_, B_, IsProbabilityMeasure.measureReal_univ, one_mul]
rewrite [mul_div_mul_comm, Set.inter_comm A, Set.inter_comm B]
simp only [Set.Finite.coe_toFinset, Set.Finite.mem_toFinset, Finset.mem_val]; rfl
_ ≤ d[UA # UB] - d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
rewrite [ZeroHom.toFun_eq_coe, AddMonoidHom.toZeroHom_coe]
linarith only [rdist_le_sum_fibre φ hUA' hUB' (μ := ℙ) (μ' := ℙ)]
let M := H[φ.toFun ∘ UA] + H[φ.toFun ∘ UB]
have hM : M = ∑ x in X, ∑ y in Y, Real.negMulLog (p x y) := by
have h_compl {x y} (h_notin : (x, y) ∉ X ×ˢ Y) : Real.negMulLog (p x y) = 0 := by
unfold_let p; beta_reduce
rewrite [Finset.mem_product, not_and_or] at h_notin
suffices A_ x = ∅ ∨ B_ y = ∅ by obtain h | h := this <;> rw [h] <;> simp
refine h_notin.imp ?_ ?_
· rw [← not_nonempty_iff_eq_empty]
rintro h ⟨a, ha, rfl⟩
exact h (h_AX ⟨a, ha⟩)
· rw [← not_nonempty_iff_eq_empty]
rintro h ⟨a, ha, rfl⟩
exact h (h_BY ⟨a, ha⟩)
unfold_let M
unfold entropy
haveI := isProbabilityMeasure_map (μ := ℙ) ((measurable_discrete φ).comp hUA').aemeasurable
haveI := isProbabilityMeasure_map (μ := ℙ) ((measurable_discrete φ).comp hUB').aemeasurable
rewrite [← Finset.sum_product', ← tsum_eq_sum fun _ ↦ h_compl, ← measureEntropy_prod]
apply tsum_congr; intro; congr
rewrite [← Set.singleton_prod_singleton, Measure.smul_apply, Measure.prod_prod,
Measure.map_apply ((measurable_discrete _).comp hUA') (MeasurableSet.singleton _),
Measure.map_apply ((measurable_discrete _).comp hUB') (MeasurableSet.singleton _),
Set.preimage_comp, hUA_coe.measure_preimage hUA',
Set.preimage_comp, hUB_coe.measure_preimage hUB']
simp [p, A_, B_, mul_div_mul_comm, Set.inter_comm, ENNReal.toReal_div]
have h_sum : ∑ x in X, ∑ y in Y,
(p x y) * (M * dᵤ[A_ x # B_ y] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p x y)) ≤
M * d[UA # UB] :=
calc
_ = ∑ x in X, ∑ y in Y, (p x y) * M * dᵤ[A_ x # B_ y] + M * d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
simp_rw [hM, Finset.sum_mul, ← Finset.sum_add_distrib]
refine Finset.sum_congr rfl <| fun _ _ ↦ Finset.sum_congr rfl <| fun _ _ ↦ ?_
simp only [negMulLog, left_distrib, mul_assoc, Finset.sum_mul]
exact congrArg (HAdd.hAdd _) (by group)
_ = M * ∑ x in X, ∑ y in Y, (p x y) * dᵤ[A_ x # B_ y] + M * d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
simp_rw [Finset.mul_sum]
congr; ext; congr; ext; group
_ ≤ M * d[UA # UB] := by
rewrite [← left_distrib]
apply mul_le_mul_of_nonneg_left
· linarith
· unfold_let M
linarith only [entropy_nonneg (φ.toFun ∘ UA) ℙ, entropy_nonneg (φ.toFun ∘ UB) ℙ]
have : ∃ x : X, ∃ y : Y,
M * dᵤ[A_ x.val # B_ y.val] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p x.val y.val) ≤
M * d[UA # UB] := by
let f (xy : H × H) := (p xy.1 xy.2) * (M * d[UA # UB])
let g (xy : H × H) := (p xy.1 xy.2) *
(M * dᵤ[A_ xy.1 # B_ xy.2] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p xy.1 xy.2))
by_contra hc; push_neg at hc
replace hc : ∀ xy ∈ X ×ˢ Y, f xy < g xy := by
refine fun xy h ↦ mul_lt_mul_of_pos_left ?_ ?_
· exact hc ⟨xy.1, (Finset.mem_product.mp h).1⟩ ⟨xy.2, (Finset.mem_product.mp h).2⟩
· haveI : Nonempty _ := h_Ax ⟨xy.1, (Finset.mem_product.mp h).1⟩
haveI : Nonempty _ := h_By ⟨xy.2, (Finset.mem_product.mp h).2⟩
simp only [p, div_pos, mul_pos, Nat.cast_pos, Nat.card_pos]
have h_nonempty : Finset.Nonempty (X ×ˢ Y) := by
use ⟨φ.toFun <| UA <| Classical.choice <| ProbabilityMeasure.nonempty ⟨ℙ, inferInstance⟩,
φ.toFun <| UB <| Classical.choice <| ProbabilityMeasure.nonempty ⟨ℙ, inferInstance⟩⟩
exact Finset.mem_product.mpr ⟨FiniteRange.mem _ _, FiniteRange.mem _ _⟩
replace hc := Finset.sum_lt_sum_of_nonempty h_nonempty hc
have h_p_one : ∑ x in X ×ˢ Y, p x.1 x.2 = 1 := by
simp_rw [Finset.sum_product, p, mul_div_mul_comm, ← Finset.mul_sum,
← sum_prob_preimage hA h_φ_AX, sum_prob_preimage hB h_φ_BY, mul_one]
rewrite [← Finset.sum_mul, h_p_one, one_mul, Finset.sum_product] at hc
exact not_le_of_gt hc h_sum
obtain ⟨x, y, hxy⟩ := this
refine ⟨x, y, A_ x.val, B_ y.val, rfl, rfl, @nonempty_of_nonempty_subtype _ _ (h_Ax x), @nonempty_of_nonempty_subtype _ _ (h_By y), ?_⟩
rewrite [← inv_div, Real.log_inv]
show _ * -log (p x.val y.val) ≤ M * _
linarith only [hxy]
section dim
open Classical
variable {G : Type*} [AddCommGroup G]
/- If G ≅ ℤᵈ then there is a subgroup H of G such that A lies in a coset of H. This is helpful to
give the equivalent definition of `dimension`. Here this is stated in greated generality since the
proof carries over automatically-/
lemma exists_coset_cover (A : Set G) :
∃ (d : ℕ), ∃ (S : Submodule ℤ G) (v : G),
FiniteDimensional.finrank ℤ S = d ∧ ∀ a ∈ A, a - v ∈ S := by
existsi FiniteDimensional.finrank ℤ (⊤ : Submodule ℤ G), ⊤, 0
refine ⟨rfl, fun a _ ↦ trivial⟩
/-- The dimension of the affine span over `ℤ` of a subset of an additive group. -/
noncomputable def dimension (A : Set G) : ℕ := Nat.find (exists_coset_cover A)
lemma dimension_le_of_coset_cover (A : Set G) (S : Submodule ℤ G) (v : G)
(hA : ∀ a ∈ A, a - v ∈ S) : dimension A ≤ FiniteDimensional.finrank ℤ S := by
apply Nat.find_le
existsi S , v
exact ⟨rfl, hA⟩
lemma dimension_le_rank [Module.Finite ℤ G] (A : Set G) :
dimension A ≤ FiniteDimensional.finrank ℤ G := by
obtain ⟨S, v, hs, _⟩ := Nat.find_spec (exists_coset_cover A)
rw [dimension, ←hs]
apply Submodule.finrank_le S
end dim
variable {G : Type u} [AddCommGroup G] [Module.Free ℤ G] [Module.Finite ℤ G] [Countable G] [MeasurableSpace G] [MeasurableSingletonClass G]
open Real MeasureTheory ProbabilityTheory Pointwise Set
/-- Move to Mathlib? `Finsupp.mapRange` of a surjective function is surjective. -/
lemma Finsupp.mapRange_surjective {α : Type u_1} {M : Type u_5} {N : Type u_7} [Zero M] [Zero N] (f : M → N) (hf : f 0 = 0)
(hs : Function.Surjective f) : Function.Surjective (Finsupp.mapRange (α := α) f hf) := by
classical
let g (n : N) : M := if n = 0 then 0 else Function.surjInv hs n
have : Function.RightInverse g f := by
intro n
by_cases h : n = 0
. simp [g, h, hf]
· simp [g, h, Function.surjInv_eq hs n]
have hg : g 0 = 0 := by simp [g]
have hfg : (f ∘ g) 0 = 0 := by simp [hf, hg]
intro F
use Finsupp.mapRange g hg F
rw [← Finsupp.mapRange_comp (h := hfg)]
convert Finsupp.mapRange_id F
convert Function.RightInverse.id this
/-- A free Z-module is torsion-free. Move to Mathlib? -/
lemma torsion_free : AddMonoid.IsTorsionFree G := by
rintro x hx hn
rw [isOfFinAddOrder_iff_nsmul_eq_zero] at hn
rcases hn with ⟨ n, hn, hn' ⟩
apply_fun Module.Free.repr ℤ G at hn'
simp_rw [map_nsmul, map_zero, smul_eq_zero, AddEquivClass.map_eq_zero_iff, hx, or_false] at hn'
linarith
/-- If G is a rank n free Z-module, then G/2G is a finite elementary 2-group of cardinality 2^n. Code is slow, needs to be golfed -/
lemma weak_PFR_quotient_prelim :
let H := G ⧸ (AddMonoidHom.range (zsmulAddGroupHom 2))
ElementaryAddCommGroup H 2 ∧ Finite H ∧ Nat.card H = 2^(FiniteDimensional.finrank ℤ G) := by
set ψ : G →+ G := zsmulAddGroupHom 2
set G₂ := AddMonoidHom.range ψ
set H := G ⧸ G₂
set φ : G →+ H := QuotientAddGroup.mk' G₂
have hH_elem : ElementaryAddCommGroup H 2 := by
apply ElementaryAddCommGroup.quotient_group (by decide)
intro x; rw [AddMonoidHom.mem_range]
use x
rw [zsmulAddGroupHom_apply]
norm_cast
let B := Module.Free.ChooseBasisIndex ℤ G
let bG : Basis B ℤ G := Module.Free.chooseBasis ℤ G
have hB_fin : Fintype B := by infer_instance
have hB_card : Nat.card B = FiniteDimensional.finrank ℤ G := by
rw [FiniteDimensional.finrank_eq_card_basis bG, Nat.card_eq_fintype_card]
have hH_module : Module (ZMod 2) H := by infer_instance
let mod : (B →₀ ℤ) →+ (B →₀ ZMod 2) := Finsupp.mapRange.addMonoidHom (Int.castAddHom (ZMod 2))
let f : G →+ (B →₀ ℤ) := bG.repr
have hker : G₂ ≤ AddMonoidHom.ker (AddMonoidHom.comp mod f) := by
intro x hx
simp only [AddMonoidHom.mem_range, G₂, ψ, zsmulAddGroupHom_apply] at hx
simp_rw [AddMonoidHom.mem_ker, AddMonoidHom.coe_comp, Function.comp_apply, mod,
Finsupp.mapRange.addMonoidHom_apply, Int.coe_castAddHom]
rcases hx with ⟨y, rfl⟩
ext b
simp_rw [map_zsmul, Finsupp.mapRange_apply, Finsupp.coe_smul, Pi.smul_apply, smul_eq_mul,
Int.cast_mul, Int.cast_ofNat, Finsupp.coe_zero, Pi.zero_apply, mul_eq_zero]
left
exact ZMod.nat_cast_self 2
let g : H →+ (B →₀ ZMod 2) := QuotientAddGroup.lift G₂ (AddMonoidHom.comp mod f) hker
have hsur : Function.Surjective g := by
have h1 : Function.Surjective mod := Finsupp.mapRange_surjective (Int.castAddHom (ZMod 2)) (map_zero _) ZMod.int_cast_surjective
have h2 := h1.comp bG.repr.surjective
have h3 : mod ∘ bG.repr = g ∘ (QuotientAddGroup.mk' G₂) := by
ext x b
simp_rw [mod, Function.comp_apply, Finsupp.mapRange.addMonoidHom_apply, Int.coe_castAddHom,
Finsupp.mapRange_apply, QuotientAddGroup.coe_mk', g]
rw [QuotientAddGroup.lift_mk]
simp [mod, f]
rw [h3] at h2
apply Function.Surjective.of_comp h2
have hinj : Function.Injective g := by
rw [injective_iff_map_eq_zero]
intro x hx
rcases QuotientAddGroup.mk'_surjective G₂ x with ⟨y, rfl⟩
simp only [QuotientAddGroup.mk'_apply, g] at hx
rw [QuotientAddGroup.lift_mk] at hx
simp_rw [AddMonoidHom.coe_comp, Function.comp_apply, mod, Finsupp.mapRange.addMonoidHom_apply,
Int.coe_castAddHom, DFunLike.ext_iff,Finsupp.mapRange_apply, Finsupp.coe_zero, Pi.zero_apply,
ZMod.int_cast_zmod_eq_zero_iff_dvd] at hx
replace hx := fun x ↦ Int.mul_ediv_cancel' (hx x)
let z (b : B) := ((Module.Free.chooseBasis ℤ G).repr y) b / 2
let z' := (Finsupp.equivFunOnFinite).symm z
change ∀ b : B, 2 * z' b = (f y) b at hx
let x' := bG.repr.symm z'
rw [QuotientAddGroup.mk'_apply, QuotientAddGroup.eq_zero_iff, AddMonoidHom.mem_range]
simp_rw [ψ, zsmulAddGroupHom_apply]
use x'
change 2 • (bG.repr.symm.toLinearMap.toAddMonoidHom z') = y
rw [← AddMonoidHom.map_zsmul bG.repr.symm.toLinearMap.toAddMonoidHom z' (2 : ℤ)]
rw [← LinearEquiv.symm_apply_apply bG.repr y]
change bG.repr.symm (2 • z') = bG.repr.symm (f y)
congr
ext b
rw [Finsupp.smul_apply, ← hx b, smul_eq_mul]
rcases Function.bijective_iff_has_inverse.mp ⟨ hinj, hsur ⟩ with ⟨ g', hg' ⟩
have bH : Basis B (ZMod 2) H := by
constructor
exact {
toFun := g
invFun := g'
left_inv := hg'.1
right_inv := hg'.2
map_add' := AddMonoidHom.map_add _
map_smul' := by
intro r x
rcases ZMod.int_cast_surjective r with ⟨ n, rfl ⟩
change g ((n : ZMod 2) • x) = (n : ZMod 2) • g x
rw [intCast_smul, intCast_smul]
exact AddMonoidHom.map_zsmul g x n
}
have hH_fin : Fintype H := Module.fintypeOfFintype bH
have hH_card : Nat.card H = 2^(FiniteDimensional.finrank ℤ G) := by
rw [Nat.card_eq_fintype_card, Module.card_fintype bH, ← Nat.card_eq_fintype_card (α := B), hB_card]
congr
exact ⟨ hH_elem, Finite.of_fintype H, hH_card ⟩
open QuotientAddGroup
/-- A version of the third isomorphism theorem: if G₂ ≤ G and H' is a subgroup of G⧸G₂, then there is a canonical isomorphism between H⧸H' and G⧸N, where N is the preimage of H' in G. A bit clunky; may be a better way to do this -/
lemma third_iso {G : Type u} [AddCommGroup G] {G₂ : AddSubgroup G} (H' : AddSubgroup (G ⧸ G₂)) :
let H := G ⧸ G₂
let φ : G →+ H := mk' G₂
let N := AddSubgroup.comap φ H'
∃ e : H ⧸ H' ≃+ G ⧸ N, ∀ x : G, e (mk' H' (φ x))= mk' N x := by
set H := G ⧸ G₂
let φ : G →+ H := mk' G₂
let N := AddSubgroup.comap φ H'
have h1 : G₂ ≤ N := by
intro x hx
rw [← eq_zero_iff] at hx
have : φ x = 0 := hx
simp [N, this, AddSubgroup.zero_mem H']
set H'' := AddSubgroup.map (mk' G₂) N
have h2 : H' = H'' := by
change H' = AddSubgroup.map (mk' G₂) N
rw [AddSubgroup.map_comap_eq, AddMonoidHom.range_top_of_surjective _ (mk'_surjective G₂)]
simp
let e1 : H ⧸ H'' ≃+ G ⧸ N := quotientQuotientEquivQuotient _ _ h1
let e2 := quotientAddEquivOfEq h2
set e := e2.trans e1
use e
intro x
convert (quotientQuotientEquivQuotientAux_mk_mk _ _ h1 x) using 1
lemma single {Ω : Type u} [MeasurableSpace Ω] [DiscreteMeasurableSpace Ω] (μ : Measure Ω)
[IsProbabilityMeasure μ] {A : Set Ω} {z : Ω} (hA : μ.real A = 1) (hz : μ.real {z} > 0) :
z ∈ A := by
contrapose! hz
have : Disjoint {z} A := by simp [hz]
replace this := measureReal_union (μ := μ) this (measurableSet_discrete _)
simp [hA] at this
have h := measureReal_mono (μ := μ) (show insert z A ⊆ Set.univ by simp)
simp [this] at h
assumption
/-- Given two non-empty finite subsets A, B of a rank n free Z-module G, there exists a subgroup N and points x, y in G/N such that the fibers Ax, By of A, B over x, y respectively are non-empty, one has the inequality
$$ \log \frac{|A| |B|}{|A_x| |B_y|} ≤ 34 (d[U_A; U_B] - d[U_{A_x}; U_{B_y}])$$
and one has the dimension bound
$$ n \log 2 ≤ \log |G/N| + 40 d[U_A; U_B].$$
-/
lemma weak_PFR_asymm_prelim (A B : Set G) [Finite A] [Finite B] (hnA : A.Nonempty) (hnB : B.Nonempty):
∃ (N : AddSubgroup G) (x y : G ⧸ N) (Ax By : Set G), Ax.Nonempty ∧ By.Nonempty ∧
Set.Finite Ax ∧ Set.Finite By ∧ Ax = {z:G | z ∈ A ∧ QuotientAddGroup.mk' N z = x } ∧
By = {z:G | z ∈ B ∧ QuotientAddGroup.mk' N z = y } ∧
(log 2) * FiniteDimensional.finrank ℤ G ≤ log (Nat.card (G ⧸ N)) +
40 * dᵤ[ A # B ] ∧ log (Nat.card A) + log (Nat.card B) - log (Nat.card Ax) - log (Nat.card By)
≤ 34 * (dᵤ[ A # B ] - dᵤ[ Ax # By ]) := by
have : Nonempty A := hnA.to_subtype
have : Nonempty B := hnB.to_subtype
obtain ⟨ h_elem, h_finite, h_card ⟩ := weak_PFR_quotient_prelim (G := G)
set ψ : G →+ G := zsmulAddGroupHom 2
set G₂ := AddMonoidHom.range ψ
set H := G ⧸ G₂
let φ : G →+ H := QuotientAddGroup.mk' G₂
let _mH : MeasurableSpace H := ⊤
have h_fintype : Fintype H := Fintype.ofFinite H
have h_torsionfree := torsion_free (G := G)
obtain ⟨ Ω, mΩ, UA, hμ, hUA_mes, hUA_unif, hUA_mem, hUA_fin ⟩ := exists_isUniform_measureSpace' A
obtain ⟨ Ω', mΩ', UB, hμ', hUB_mes, hUB_unif, hUB_mem, hUB_fin ⟩ :=
exists_isUniform_measureSpace' B
rcases (PFR_projection (φ.toFun ∘ UA) (φ.toFun ∘ UB) ℙ ℙ (by measurability) (by measurability)) with ⟨H', ⟨ hH1, hH2 ⟩ ⟩
let N := AddSubgroup.comap φ H'
set φ' := QuotientAddGroup.mk' N
have _cGN : Countable (G ⧸ N) := Function.Surjective.countable (QuotientAddGroup.mk'_surjective N)
have _msGN : MeasurableSingletonClass (G ⧸ N) := by
constructor
intro x
exact MeasurableSpace.map_def.mpr (measurableSet_discrete _)
rcases third_iso H' with ⟨ e : H ⧸ H' ≃+ G ⧸ N, he ⟩
rcases single_fibres φ' hnA hnB hUA_mes hUB_mes hUA_unif hUB_unif hUA_mem hUB_mem with
⟨x, y, Ax, By, hAx, hBy, hnAx, hnBy, hcard_ineq⟩
have : Nonempty Ax := hnAx.to_subtype
have : Nonempty By := hnBy.to_subtype
have Axf : Finite Ax := by rw [hAx]; infer_instance
have Byf : Finite By := by rw [hBy]; infer_instance
have h1 := torsion_dist_shrinking UA UB ℙ ℙ hUA_mes hUB_mes h_torsionfree φ
have h2 := torsion_dist_shrinking UB UA ℙ ℙ hUB_mes hUA_mes h_torsionfree φ
rw [rdist_symm] at h2
rw [<- rdist_set_eq_rdist hμ hμ' hUA_unif hUB_unif hUA_mes hUB_mes] at h1 h2
-- using explicit .toFun casts as this saves a lot of heartbeats
change H[φ.toFun ∘ UA] ≤ 10 * dᵤ[A # B] at h1
change H[φ.toFun ∘ UB] ≤ 10 * dᵤ[A # B] at h2
replace hH1 : log (Nat.card H') ≤ 40 * dᵤ[A # B] := by
apply hH1.trans
linarith
replace h_card : log 2 * FiniteDimensional.finrank ℤ G ≤ log (Nat.card (G ⧸ N)) + 40 * dᵤ[A # B] := by
rw [mul_comm, ← log_rpow (by norm_num)]
norm_cast
classical
rwa [← h_card, ← Nat.card_congr e.toEquiv, Nat.card_eq_fintype_card, Nat.card_eq_fintype_card, ← AddSubgroup.index_mul_card H', AddSubgroup.index_eq_card, Nat.cast_mul, log_mul, add_le_add_iff_left, ← Nat.card_eq_fintype_card]
all_goals norm_cast; exact Fintype.card_ne_zero
use N, x, y, Ax, By
refine ⟨ hnAx, hnBy, Ax.toFinite, By.toFinite, hAx, hBy, h_card, ?_ ⟩
replace hH2 : H[φ'.toFun ∘ UA] + H[φ'.toFun ∘ UB] ≤ 34 * d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] := by
set X := ((mk' H').toFun ∘ φ.toFun) ∘ UA
set Y := ((mk' H').toFun ∘ φ.toFun) ∘ UB
have hX : Measurable X := Measurable.comp (measurable_discrete _) hUA_mes
have hY : Measurable Y := Measurable.comp (measurable_discrete _) hUB_mes
change H[X] + H[Y] ≤ 34 * d[X # Y] at hH2
have ha : φ'.toFun ∘ UA = e.toFun ∘ X := by ext x; exact (he (UA x)).symm
have hb : φ'.toFun ∘ UB = e.toFun ∘ Y := by ext x; exact (he (UB x)).symm
have he_inj : Function.Injective e.toFun := AddEquiv.injective e
rw [ha, hb, entropy_comp_of_injective _ hX _ he_inj, entropy_comp_of_injective _ hY _ he_inj]
have : d[e.toFun ∘ X # e.toFun ∘ Y] = d[X # Y] := rdist_of_inj hX hY e.toAddMonoidHom he_inj
rwa [this]
set X : Ω → G ⧸ N := φ'.toFun ∘ UA
set Y : Ω' → G ⧸ N := φ'.toFun ∘ UB
have hX : Measurable X := Measurable.comp (measurable_discrete _) hUA_mes
have hY : Measurable Y := Measurable.comp (measurable_discrete _) hUB_mes
rcases le_iff_lt_or_eq.mp (rdist_nonneg (μ := ℙ) (μ' := ℙ) hX hY) with h | h
swap
. rw [← h] at hH2
have hH2A : H[X] ≥ 0 := entropy_nonneg _ _
have hH2B : H[Y] ≥ 0 := entropy_nonneg _ _
have hH2A' : H[X] ≤ 0 := by linarith only [hH2, hH2A, hH2B]
have hH2B' : H[Y] ≤ 0 := by linarith only [hH2, hH2A, hH2B]
rcases const_of_nonpos_entropy (μ := ℙ) hX hH2A' with ⟨ x', hx ⟩
rcases const_of_nonpos_entropy (μ := ℙ) hY hH2B' with ⟨ y', hy ⟩
have hAAx {z : G} (hz : z ∈ A) : φ'.toFun z = x' := by
change (ℙ).real (UA⁻¹' (φ'⁻¹' {x'})) = 1 at hx
rw [← MeasureTheory.map_measureReal_apply hUA_mes (measurableSet_discrete _)] at hx
set Af := A.toFinite.toFinset
have hUAf : IsUniform Af UA := by
convert hUA_unif; simp only [Af, Set.Finite.coe_toFinset]
have hnAf : 0 < Nat.card Af := by simp only [Af, Set.Finite.mem_toFinset, Nat.card_pos]
have hzf : z ∈ Af := by simp [Af, Set.Finite.mem_toFinset, hz]
have : (Measure.map UA ℙ).real {z} > 0 := by
rw [IsUniform.measureReal_preimage_of_mem' hUAf hUA_mes hzf]
positivity
have _ : IsProbabilityMeasure ((ℙ).map UA) := by
exact MeasureTheory.isProbabilityMeasure_map (Measurable.aemeasurable hUA_mes)
replace this := single ((ℙ).map UA) hx this
rwa [Set.mem_preimage, Set.mem_singleton_iff] at this
have hxx : Ax = A := by
have h : hnAx.some ∈ Ax := hnAx.some_mem
simp [hAx] at h ⊢
have := hAAx h.1
simp [h.2] at this
intro z hz
simp [this]
convert hAAx hz
have hBBy {z : G} (hz : z ∈ B) : φ'.toFun z = y' := by
change (ℙ).real (UB⁻¹' (φ'⁻¹' {y'})) = 1 at hy
rw [← MeasureTheory.map_measureReal_apply hUB_mes (measurableSet_discrete _)] at hy
set Bf := B.toFinite.toFinset
have hUBf : IsUniform Bf UB := by convert hUB_unif; simp only [Bf, Set.Finite.coe_toFinset]
have hnBf : 0 < Nat.card Bf := by simp only [Bf, Set.Finite.mem_toFinset, Nat.card_pos]
have hzf : z ∈ Bf := by simp [Bf, Set.Finite.mem_toFinset, hz]
have : (Measure.map UB ℙ).real {z} > 0 := by
rw [IsUniform.measureReal_preimage_of_mem' hUBf hUB_mes hzf]
positivity
have _ : IsProbabilityMeasure ((ℙ).map UB) := by
exact MeasureTheory.isProbabilityMeasure_map (Measurable.aemeasurable hUB_mes)
replace this := single ((ℙ).map UB) hy this
rwa [Set.mem_preimage, Set.mem_singleton_iff] at this
have hyy : By = B := by
have h : hnBy.some ∈ By := hnBy.some_mem
simp [hBy] at h ⊢
have := hBBy h.1
simp [h.2] at this
intro z hz
simp [this]
convert hBBy hz
simp [hxx, hyy]
have := calc d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] * (log (Nat.card A) + log (Nat.card B) - log (Nat.card Ax) - log (Nat.card By))
_ = d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] * log ((Nat.card A) * (Nat.card B) / ((Nat.card Ax) * (Nat.card By))) := by
congr
convert (four_logs ?_ ?_ ?_ ?_).symm
all_goals norm_cast; exact Nat.card_pos
_ ≤ (H[φ'.toFun ∘ UA] + H[φ'.toFun ∘ UB]) * (d[UA # UB] - dᵤ[Ax # By]) := hcard_ineq
_ ≤ (34 * d[φ'.toFun ∘ UA # φ'.toFun ∘ UB]) * (d[UA # UB] - dᵤ[Ax # By]) := by
apply mul_le_mul_of_nonneg_right hH2
have := rdist_le_avg_ent (Measurable.comp (measurable_discrete φ'.toFun) hUA_mes) (Measurable.comp (measurable_discrete φ'.toFun) hUB_mes)
replace this : 0 < H[φ'.toFun ∘ UA] + H[φ'.toFun ∘ UB] := by linarith
rw [← mul_le_mul_left this]
apply le_trans _ hcard_ineq
rw [mul_zero]
change 0 ≤ d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] * log ((Nat.card A) * (Nat.card B) / ((Nat.card Ax) * (Nat.card By)))
rw [← mul_zero d[φ'.toFun ∘ UA # φ'.toFun ∘ UB], mul_le_mul_left h]
apply Real.log_nonneg
rw [one_le_div]
gcongr
. apply Nat.card_mono
. exact Set.toFinite A
rw [hAx]; exact Set.inter_subset_left _ _
apply Nat.card_mono
. exact Set.toFinite B
rw [hBy]; exact Set.inter_subset_left _ _
norm_cast
exact mul_pos Nat.card_pos Nat.card_pos
_ = d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] * (34 * (d[UA # UB] - dᵤ[Ax # By])) := by ring
_ = d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] * (34 * (dᵤ[A # B] - dᵤ[Ax # By])) := by
rw [<- rdist_set_eq_rdist hμ hμ' hUA_unif hUB_unif hUA_mes hUB_mes]
exact (mul_le_mul_left h).mp this
/-- Separating out the conclusion of `weak_PFR_asymm` for convenience of induction arguments.-/
def WeakPFRAsymmConclusion (A B : Set G) : Prop :=
∃ A' B' : Set G, A' ⊆ A ∧ B' ⊆ B ∧ A'.Nonempty ∧ B'.Nonempty ∧
log (((Nat.card A) * (Nat.card B)) / ((Nat.card A') * (Nat.card B'))) ≤ 34 * dᵤ[A # B] ∧
max (dimension A') (dimension B') ≤ (40 / log 2) * dᵤ[A # B]
/-- The property of two sets A,B of a group G not being contained in cosets of the same proper subgroup -/
def not_in_coset {G: Type u} [AddCommGroup G] (A B : Set G) : Prop := AddSubgroup.closure ((A-A) ∪ (B-B)) = ⊤
/-- In fact one has equality here, but this is tricker to prove and not needed for the argument. -/
lemma dimension_of_shift {G: Type u} [AddCommGroup G]
{H: AddSubgroup G} (A : Set H) (x : G) :
dimension ((fun a:H ↦ (a:G) + x) '' A) ≤ dimension A := by
classical
rcases Nat.find_spec (exists_coset_cover A) with ⟨ S, v, hrank, hshift ⟩
change FiniteDimensional.finrank ℤ S = dimension A at hrank
rw [← hrank]
convert dimension_le_of_coset_cover _ (Submodule.map H.subtype.toIntLinearMap S) (x+v) ?_
. apply LinearEquiv.finrank_eq
exact Submodule.equivMapOfInjective _ (by simpa using Subtype.val_injective) _
intro a ha
rw [Set.mem_image] at ha
rcases ha with ⟨ b, ⟨ hb, hb'⟩ ⟩
rw [Submodule.mem_map]
use b - v, hshift b hb
simp [← hb']
abel
| lemma conclusion_transfers {A B : Set G}
(G': AddSubgroup G) (A' B' : Set G')
(hA : IsShift A A') (hB : IsShift B B') [Finite A'] [Finite B'] (hA' : A'.Nonempty) (hB' : B'.Nonempty)
(h : WeakPFRAsymmConclusion A' B') : WeakPFRAsymmConclusion A B | conclusion_transfers | 25309ad 20231211 | 1612a14 20240111 | pfr/PFR/WeakPFR.lean | {
"lineInFile": 986,
"tokenPositionInFile": 51896,
"theoremPositionInFile": 28
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n have : Nonempty A' := hA'.to_subtype\n have : Nonempty B' := hB'.to_subtype\n rcases h with ⟨A'', B'', hA'', hB'', hA''_non, hB''_non, hcard_ineq, hdim_ineq⟩\n rcases hA with ⟨ x, hA ⟩\n set f : G' → G := fun a ↦ (a : G) + x\n have hf : Function.Injective f := by\n intro y z hyz\n simp [f] at hyz\n exact hyz\n have hA' : A = f '' A' := by\n simp_rw [hA, ← Set.image_vadd, Set.image_image, vadd_eq_add, f, add_comm]; rfl\n rcases hB with ⟨ y, hB ⟩\n set g : G' → G := fun a ↦ (a : G) + y\n have hg : Function.Injective g := by\n intro y z hyz\n simp [g] at hyz\n exact hyz\n have hB' : B = g '' B' := by\n simp_rw [hB, ← Set.image_vadd, Set.image_image, vadd_eq_add, g, add_comm]; rfl\n use f '' A'', g '' B''\n have : dᵤ[A # B] = dᵤ[A' # B'] := by\n rw [<-rdist_set_of_inj _ _ (φ := G'.subtype) Subtype.val_injective, <-rdist_set_add_const (G'.subtype '' A') (G'.subtype '' B') x y]\n congr\n . rw [hA]\n ext y\n simp [Set.mem_vadd_set]\n constructor\n . rintro ⟨ z, ⟨ ⟨ w, hw ⟩, rfl ⟩ ⟩\n have : x + z + -x ∈ G' := by simp [w]\n use this\n simp\n convert hw\n rintro ⟨ h, ha ⟩\n use y + -x\n constructor\n . use h\n abel\n rw [hB]\n ext x\n simp [Set.mem_vadd_set]\n constructor\n . rintro ⟨ z, ⟨ ⟨ w, hw ⟩, rfl ⟩ ⟩\n have : y + z + -y ∈ G' := by simp [w]\n use this\n simp\n convert hw\n rintro ⟨ h, ha ⟩\n use x + -y\n constructor\n . use h\n abel\n\n\n refine ⟨ ?_, ?_, ?_, ?_, ?_, ?_ ⟩\n . simp [hA', hf, hA'']\n . simp [hB', hg, hB'']\n . simp [hA''_non]\n . simp [hB''_non]\n . convert hcard_ineq using 2\n . congr 3\n . rw [hA', Nat.card_image_of_injective hf]\n . rw [hB', Nat.card_image_of_injective hg]\n . rw [Nat.card_image_of_injective hf]\n rw [Nat.card_image_of_injective hg]\n convert LE.le.trans _ hdim_ineq using 2\n norm_cast\n apply max_le_max\n . exact dimension_of_shift A'' x\n · exact dimension_of_shift B'' y",
"proofType": "tactic",
"proofLengthLines": 70,
"proofLengthTokens": 1975
} | pfr |
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Quotient
import Mathlib.GroupTheory.Torsion
import Mathlib.GroupTheory.Torsion
import Mathlib.LinearAlgebra.FreeModule.PID
import PFR.Mathlib.Data.Set.Pointwise.SMul
import PFR.EntropyPFR
import PFR.ImprovedPFR
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Mathlib.GroupTheory.Torsion
/-!
# Weak PFR over the integers
Here we use the entropic form of PFR to deduce a weak form of PFR over the integers.
## Main statement
* `weak_PFR_int`: Let $A\subseteq \mathbb{Z}^d$ and $\lvert A+A\rvert\leq K\lvert A\rvert$.
There exists $A'\subseteq A$ such that $\lvert A'\rvert \geq K^{-17}\lvert A\rvert$ and
$\dim A' \leq (40/\log 2)\log K$.
-/
section AddCommGroup
variable {G : Type*} [AddCommGroup G] {A B : Set G}
open Set
open scoped Pointwise
def IsShift (A B : Set G) : Prop := ∃ x : G, A = x +ᵥ B
lemma IsShift.sub_self_congr : IsShift A B → A - A = B - B := by
rintro ⟨x, rfl⟩; simp [vadd_sub_vadd_comm, singleton_zero]
lemma IsShift.card_congr : IsShift A B → Nat.card A = Nat.card B := by rintro ⟨x, rfl⟩; simp
/-- The property of two sets A, B of a group G not being contained in cosets of the same proper
subgroup -/
def NotInCoset (A B : Set G) : Prop := AddSubgroup.closure ((A - A) ∪ (B - B)) = ⊤
/-- Without loss of generality, one can move (up to translation and embedding) any pair A, B of non-empty sets into a subgroup where they are not in a coset. -/
lemma wlog_notInCoset (hA : A.Nonempty) (hB : B.Nonempty) :
∃ (G' : AddSubgroup G) (A' B' : Set G'), IsShift A A' ∧ IsShift B B' ∧ NotInCoset A' B' := by
obtain ⟨x, hx⟩ := hA
obtain ⟨y, hy⟩ := hB
set G' := AddSubgroup.closure ((A - A) ∪ (B - B))
set A' : Set G' := (↑) ⁻¹' ((-x) +ᵥ A)
set B' : Set G' := (↑) ⁻¹' ((-y) +ᵥ B)
have hxA : -x +ᵥ A ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hx).trans $ (subset_union_left ..).trans
AddSubgroup.subset_closure
have hyB : -y +ᵥ B ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hy).trans $ (subset_union_right ..).trans
AddSubgroup.subset_closure
have hA : IsShift A A' := ⟨x, by rw [Set.image_preimage_eq_of_subset hxA, vadd_neg_vadd]⟩
have hB : IsShift B B' := ⟨y, by rw [Set.image_preimage_eq_of_subset hyB, vadd_neg_vadd]⟩
refine ⟨G', A', B', hA, hB, ?_⟩
unfold NotInCoset
convert AddSubgroup.closure_preimage_eq_top ((A - A) ∪ (B - B))
simp_rw [preimage_union, hA.sub_self_congr, hB.sub_self_congr]
rw [preimage_sub, preimage_sub]
simp [A', B', preimage_image_preimage]
all_goals apply_rules [Subtype.coe_injective, (image_preimage_subset ..).trans, hxA, hyB]
end AddCommGroup
section Torsion
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [MeasurableSpace G] [MeasurableSingletonClass G]
[Countable G] {Ω Ω' : Type u} [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ': Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
/-- If $G$ is torsion-free and $X,Y$ are $G$-valued random variables then $d[X;2Y]\leq 5d[X;Y]$. -/
lemma torsion_free_doubling [FiniteRange X] [FiniteRange Y]
(hX : Measurable X) (hY : Measurable Y) (hG : AddMonoid.IsTorsionFree G) :
d[X ; μ # (Y + Y) ; μ'] ≤ 5 * d[X; μ # Y ; μ'] := by
obtain ⟨A, mA, μA, X', Y'₁, Y'₂, hμA, h_indep, hX'_meas, hY'₁_meas, hY'₂_meas, hX'_ident,
hY'₁_ident, hY'₂_ident, _, _, _⟩ := independent_copies3_nondep_finiteRange hX hY hY μ μ' μ'
have h_meas (i : Fin 3) : Measurable (![X', Y'₁, Y'₂] i) := by fin_cases i <;> assumption
haveI : NoZeroSMulDivisors ℕ G := hG.noZeroNsmulDivisors
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨x, y₁, y₂⟩ ↦ (x, y₁ - y₂, x - 2 • y₁)
show H[f ∘ ⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] = _
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hX'_meas <| Measurable.prod hY'₁_meas hY'₂_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun X' (prod Y'₁ Y'₂) μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 1 2 0 (by decide) (by decide)
rw [this.entropy_pair_eq_add hX'_meas (by exact Measurable.prod hY'₁_meas hY'₂_meas),
IndepFun.entropy_pair_eq_add hY'₁_meas hY'₂_meas (h_indep.indepFun (show 1 ≠ 2 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, two_mul]
have : H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[X ; μ] + H[Y ; μ'] := calc
H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[⟨X', Y'₁⟩ ; μA] := by
let f : G × G → G × G := fun ⟨x, y₁⟩ ↦ (x, x - 2 • y₁)
show H[f ∘ ⟨X', Y'₁⟩ ; μA] = _
apply entropy_comp_of_injective μA (by exact Measurable.prod hX'_meas hY'₁_meas) f
exact fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + H[Y ; μ'] := by
rw [IndepFun.entropy_pair_eq_add hX'_meas hY'₁_meas (h_indep.indepFun (show 0 ≠ 1 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq]
let f : G × G → G × G := fun ⟨x, y⟩ ↦ (x, y - x)
have hf : f.Injective := fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all
have : H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] := calc
H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] = H[f ∘ ⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
show _ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂ - (Y'₁ - Y'₂)⟩ ; μA]
rw [sub_sub_sub_cancel_right, ← sub_add_eq_sub_sub, two_nsmul]
_ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
refine entropy_comp_of_injective μA (Measurable.prod ?_ ?_) f hf
· exact Measurable.sub hY'₁_meas hY'₂_meas
· exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
_ ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] :=
entropy_pair_le_add (hY'₁_meas.sub' hY'₂_meas) (hX'_meas.sub' hY'₁_meas |>.sub' hY'₂_meas) μA
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] + H[X' - 2 • Y'₁ ; μA] ≤
H[⟨X', X' - 2 • Y'₁⟩ ; μA] + H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] := by
haveI : FiniteRange (Y'₁ - Y'₂) := FiniteRange.sub Y'₁ Y'₂
haveI : FiniteRange (2 • Y'₁) := by show FiniteRange ((fun x ↦ 2 • x) ∘ Y'₁); infer_instance
apply entropy_triple_add_entropy_le μA hX'_meas (Measurable.sub hY'₁_meas hY'₂_meas)
exact Measurable.sub' hX'_meas <| Measurable.const_smul hY'₁_meas 2
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨y₁, y₂, x⟩ ↦ (y₁, y₂, x - y₁ - y₂)
show H[f ∘ ⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA]
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hY'₁_meas <| Measurable.prod hY'₂_meas hX'_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun Y'₁ (prod Y'₂ X') μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 2 0 1 (by decide) (by decide)
rw [this.entropy_pair_eq_add hY'₁_meas (by exact Measurable.prod hY'₂_meas hX'_meas),
IndepFun.entropy_pair_eq_add hY'₂_meas hX'_meas (h_indep.indepFun (show 2 ≠ 0 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq]
group
have : H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₂ ; μA] := calc
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₁, X' - Y'₂⟩ ; μA] := by rw [sub_right_comm] ; rfl
_ = H[⟨Y'₁, X' - Y'₂⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₁_meas <| Measurable.sub hX'_meas hY'₂_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₂ ; μA] := by
haveI : FiniteRange (X' - Y'₂) := FiniteRange.sub X' Y'₂
convert IndepFun.entropy_pair_eq_add hY'₁_meas (hX'_meas.sub hY'₂_meas)
<| h_indep.indepFun_sub_right h_meas 1 0 2 (by decide) (by decide)
exact hY'₁_ident.entropy_eq.symm
have : H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₁ ; μA] := calc
H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₂, X' - Y'₁⟩ ; μA] := rfl
_ = H[⟨Y'₂, X' - Y'₁⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₂_meas <| Measurable.sub hX'_meas hY'₁_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₁ ; μA] := by
haveI : FiniteRange (X' - Y'₁) := FiniteRange.sub X' Y'₁
convert IndepFun.entropy_pair_eq_add hY'₂_meas (hX'_meas.sub hY'₁_meas)
<| h_indep.indepFun_sub_right h_meas 2 0 1 (by decide) (by decide)
exact hY'₂_ident.entropy_eq.symm
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] ≤
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] + H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
apply entropy_triple_add_entropy_le μA hY'₁_meas hY'₂_meas
exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
have : H[X' - Y'₁ - Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := calc
H[X' - Y'₁ - Y'₂ ; μA] ≤ H[X' - Y'₁ ; μA] + H[X' - Y'₂ ; μA] - H[X ; μ] := by linarith
_ = 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := by
nth_rw 1 [two_mul, ← hX'_ident.rdist_eq hY'₁_ident, ← hX'_ident.rdist_eq hY'₂_ident]
have h1 : d[X' ; μA # Y'₁ ; μA] = H[X' - Y'₁ ; μA] - H[X' ; μA] / 2 - H[Y'₁ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 1 by decide)).rdist_eq hX'_meas hY'₁_meas
have h2 : d[X' ; μA # Y'₂ ; μA] = H[X' - Y'₂ ; μA] - H[X' ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 2 by decide)).rdist_eq hX'_meas hY'₂_meas
rw [h1, h2, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, hX'_ident.entropy_eq]
group
have : d[X ; μ # 2 • Y ; μ'] ≤
d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := calc
d[X ; μ # 2 • Y ; μ'] = H[X' - 2 • Y'₁ ; μA] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by
have h2Y_ident : IdentDistrib (2 • Y'₁) (2 • Y) (μ := μA) (ν := μ') := by
convert hY'₁_ident.comp <| measurable_discrete <| fun g ↦ 2 • g
have h2Y_indep : IndepFun X' (2 • Y'₁) (μ := μA) := by
convert (h_indep.indepFun (show 0 ≠ 1 by decide)).comp measurable_id
(measurable_const_smul 2)
rw [← hX'_ident.rdist_eq h2Y_ident,
h2Y_indep.rdist_eq hX'_meas <| Measurable.const_smul hY'₁_meas 2,
hX'_ident.entropy_eq, h2Y_ident.entropy_eq]
_ ≤ H[Y'₁ - Y'₂ ; μA] + 2 * d[X ; μ # Y ; μ'] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by linarith
_ = d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := by
have H2Y : H[2 • Y ; μ'] = H[Y ; μ'] := by
let f (g : G) := 2 • g
exact entropy_comp_of_injective μ' hY f (fun _ _ ↦ by simp [f, smul_right_inj])
have : d[Y'₁ ; μA # Y'₂ ; μA] = H[Y'₁ - Y'₂ ; μA] - H[Y'₁ ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 1 ≠ 2 by decide)).rdist_eq hY'₁_meas hY'₂_meas
rw [this, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, H2Y]
group
have : d[Y'₁ ; μA # Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] := by
rw [two_mul]
convert rdist_triangle hY'₁_meas hX'_meas hY'₂_meas (μ := μA) (μ' := μA) (μ'' := μA)
· exact rdist_symm.trans (hY'₁_ident.rdist_eq hX'_ident).symm
· exact (hX'_ident.rdist_eq hY'₂_ident).symm
rw [← two_nsmul]
linarith [abs_le.mp <| diff_ent_le_rdist hX hY (μ := μ) (μ' := μ')]
/-- If $G$ is a torsion-free group and $X,Y$ are $G$-valued random variables and
$\phi : G\to \mathbb{F}_2^d$ is a homomorphism then
\[\mathbb{H}(\phi(X))\leq 10d[X;Y].\] -/
lemma torsion_dist_shrinking {H : Type u} [FiniteRange X] [FiniteRange Y] (hX : Measurable X)
(hY : Measurable Y) [AddCommGroup H] [ElementaryAddCommGroup H 2]
[MeasurableSpace H] [MeasurableSingletonClass H] [Countable H]
(hG : AddMonoid.IsTorsionFree G) (φ : G →+ H) :
H[φ ∘ X ; μ] ≤ 10 * d[X; μ # Y ; μ'] := by
have :=
calc d[φ ∘ X ; μ # φ ∘ (Y + Y); μ'] ≤ d[X; μ # (Y + Y) ; μ'] := rdist_of_hom_le φ hX (Measurable.add hY hY)
_ ≤ 5 * d[X; μ # Y ; μ'] := torsion_free_doubling X Y μ μ' hX hY hG
have eq_zero : φ ∘ (Y + Y) = fun _ ↦ 0 := by ext x ; simp only [Function.comp_apply, Pi.add_apply,
map_add, ElementaryAddCommGroup.add_self]
rwa [eq_zero, rdist_zero_eq_half_ent, div_le_iff zero_lt_two, mul_assoc, mul_comm _ 2, ←mul_assoc,
show (5*2 : ℝ) = 10 by norm_num] at this
end Torsion
instance {G : Type u} [AddCommGroup G] [Fintype G] [MeasurableSpace G] [MeasurableSingletonClass G] (H : AddSubgroup G)
: MeasurableSingletonClass (G ⧸ H) :=
⟨λ _ ↦ by { rw [measurableSet_quotient]; simp [measurableSet_discrete] }⟩
section F2_projection
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [ElementaryAddCommGroup G 2] [Fintype G] [MeasurableSpace G]
[MeasurableSingletonClass G] {Ω Ω' : Type*}
/-- Let $G=\mathbb{F}_2^n$ and $X,Y$ be $G$-valued random variables such that
\[\mathbb{H}(X)+\mathbb{H}(Y)> (20/\alpha) d[X;Y],\]
for some $\alpha > 0$.
There is a non-trivial subgroup $H\leq G$ such that
\[\log \lvert H\rvert <(1+\alpha)/2 (\mathbb{H}(X)+\mathbb{H}(Y))\] and
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))< \alpha (\mathbb{H}(X)+\mathbb{H}(Y))\]
where $\psi:G\to G/H$ is the natural projection homomorphism.
-/
lemma app_ent_PFR' [MeasureSpace Ω] [MeasureSpace Ω'] (X : Ω → G) (Y : Ω' → G)
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
{α : ℝ} (hent : 20 * d[X # Y] < α * (H[X] + H[Y])) (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X] + H[Y]) ∧
H[(QuotientAddGroup.mk' H) ∘ X] + H[(QuotientAddGroup.mk' H) ∘ Y] < α * (H[X] + H[Y]) := by
let p : refPackage Ω Ω' G := {
X₀₁ := X
X₀₂ := Y
hmeas1 := hX
hmeas2 := hY
η := 1/8
hη := by norm_num
hη' := by norm_num }
obtain ⟨H, Ω'', hΩ'', U, _, hUmeas, hUunif, ineq⟩ := entropic_PFR_conjecture_improv p rfl
let ψ := (QuotientAddGroup.mk' H)
use H
haveI : Finite H := Subtype.finite
-- Note that H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y]
have ent_le : H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y] := calc
H[ψ ∘ X] + H[ψ ∘ Y] ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· exact ent_of_proj_le hX hUmeas hUunif
· exact ent_of_proj_le hY hUmeas hUunif
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- Note that (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y]
have log_sub_le : (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y] := calc
(log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) =
(H[U] - H[X]) + (H[U] - H[Y]) := by
rw [IsUniform.entropy_eq' hUunif hUmeas, SetLike.coe_sort_coe]
_ ≤ |(H[U] - H[X])| + |(H[U] - H[Y])| := by gcongr <;> exact le_abs_self _
_ ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hX
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hY
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- then the conclusion follows from the assumption `hent` and basic inequality manipulations
exact ⟨by linarith, by linarith⟩
variable [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ' : Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
lemma app_ent_PFR (α : ℝ) (hent: 20 * d[X;μ # Y;μ'] < α * (H[X; μ] + H[Y; μ'])) (hX : Measurable X)
(hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ']
< α * (H[ X; μ] + H[Y; μ']) :=
@app_ent_PFR' _ _ _ _ _ _ _ _ (MeasureSpace.mk μ) (MeasureSpace.mk μ') _ _ _ _ α hent hX hY
set_option maxHeartbeats 300000 in
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables and $\alpha < 1$ then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq (1 + α) / (2 * (1 - α)) * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 20/\alpha * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection'
(α : ℝ) (hX : Measurable X) (hY : Measurable Y) (αpos : 0 < α) (αone : α < 1) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (H[X ; μ] + H[Y ; μ']) ∧
α * (H[(QuotientAddGroup.mk' H) ∘ X ; μ] + H[(QuotientAddGroup.mk' H) ∘ Y ; μ']) ≤
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] := by
let S := { H : AddSubgroup G | (∃ (c : ℝ), 0 ≤ c ∧
log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (1 - c) * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
c * (H[X; μ] + H[Y;μ'])) ∧
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] <
α * (H[ (QuotientAddGroup.mk' H) ∘ X; μ ] + H[ (QuotientAddGroup.mk' H) ∘ Y; μ']) }
have : 0 ≤ H[X ; μ] + H[Y ; μ'] := by linarith [entropy_nonneg X μ, entropy_nonneg Y μ']
have : 0 < 1 - α := sub_pos.mpr αone
by_cases hE : (⊥ : AddSubgroup G) ∈ S
· classical
obtain ⟨H, ⟨⟨c, hc, hlog, hup⟩, hent⟩, hMaxl⟩ :=
S.toFinite.exists_maximal_wrt id S (Set.nonempty_of_mem hE)
set ψ : G →+ G ⧸ H := QuotientAddGroup.mk' H
have surj : Function.Surjective ψ := QuotientAddGroup.mk'_surjective H
set G' := G ⧸ H
have : ElementaryAddCommGroup G' 2 := ElementaryAddCommGroup.quotient_group (by decide)
(by simp [AddSubgroup.zero_mem])
obtain ⟨H', hlog', hup'⟩ := app_ent_PFR _ _ _ _ α hent ((measurable_discrete _).comp hX)
((measurable_discrete _).comp hY)
have H_ne_bot: H' ≠ ⊥ := by
by_contra!
rcases this with rfl
have inj : Function.Injective (QuotientAddGroup.mk' (⊥ : AddSubgroup G')) :=
(QuotientAddGroup.quotientBot : (G' ⧸ ⊥) ≃+ G').symm.injective
rw [entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ inj,
entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ inj] at hup'
nlinarith [entropy_nonneg (ψ ∘ X) μ, entropy_nonneg (ψ ∘ Y) μ']
let H'' := H'.comap ψ
use H''
rw [← (AddSubgroup.map_comap_eq_self_of_surjective surj _ : H''.map ψ = H')] at hup' hlog'
set H' := H''.map ψ
have Hlt : H < H'' := by
have : H = (⊥ : AddSubgroup G').comap ψ := by
simp only [ψ, AddMonoidHom.comap_bot, QuotientAddGroup.ker_mk']
rw [this, AddSubgroup.comap_lt_comap_of_surjective surj]
exact Ne.bot_lt H_ne_bot
let φ : G' ⧸ H' ≃+ G ⧸ H'' := QuotientAddGroup.quotientQuotientEquivQuotient H H'' Hlt.le
set ψ' : G' →+ G' ⧸ H' := QuotientAddGroup.mk' H'
set ψ'' : G →+ G ⧸ H'' := QuotientAddGroup.mk' H''
have diag : ψ' ∘ ψ = φ.symm ∘ ψ'' := rfl
rw [← Function.comp.assoc, ← Function.comp.assoc, diag, Function.comp.assoc,
Function.comp.assoc] at hup'
have cond : log (Nat.card H'') ≤
(1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := by
have cardprod : Nat.card H'' = Nat.card H' * Nat.card H := by
have hcard₀ := Nat.card_congr <| (AddSubgroup.addSubgroupOfEquivOfLe Hlt.le).toEquiv
have hcard₁ := Nat.card_congr <|
(QuotientAddGroup.quotientKerEquivRange (ψ.restrict H'')).toEquiv
have hcard₂ := AddSubgroup.card_eq_card_quotient_mul_card_addSubgroup (H.addSubgroupOf H'')
rw [ψ.ker_restrict H'', QuotientAddGroup.ker_mk', ψ.restrict_range H''] at hcard₁
simpa only [← Nat.card_eq_fintype_card, hcard₀, hcard₁] using hcard₂
calc
log (Nat.card H'')
_ = log ((Nat.card H' : ℝ) * (Nat.card H : ℝ)) := by rw [cardprod]; norm_cast
_ = log (Nat.card H') + log (Nat.card H) := by
rw [Real.log_mul (Nat.cast_ne_zero.2 (@Nat.card_pos H').ne')
(Nat.cast_ne_zero.2 (@Nat.card_pos H).ne')]
_ ≤ (1 + α) / 2 * (H[⇑ψ ∘ X ; μ] + H[⇑ψ ∘ Y ; μ']) + log (Nat.card H) := by gcongr
_ ≤ (1 + α) / 2 * (c * (H[X; μ] + H[Y;μ'])) +
(1 + α) / (2 * (1 - α)) * (1 - c) * (H[X ; μ] + H[Y ; μ']) := by gcongr
_ = (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X ; μ] + H[Y ; μ']) := by
field_simp; ring
have HS : H'' ∉ S := λ Hs => Hlt.ne (hMaxl H'' Hs Hlt.le)
simp only [S, Set.mem_setOf_eq, not_and, not_lt] at HS
refine ⟨?_, HS ⟨α * c, by positivity, cond, ?_⟩⟩
· calc
log (Nat.card H'')
_ ≤ (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := cond
_ ≤ (1 + α) / (2 * (1 - α)) * 1 * (H[X; μ] + H[Y;μ']) := by gcongr; simp; positivity
_ = (1 + α) / (2 * (1 - α)) * (H[X; μ] + H[Y;μ']) := by simp only [mul_one]
· calc
H[ ψ'' ∘ X; μ ] + H[ ψ'' ∘ Y; μ' ]
_ = H[ φ.symm ∘ ψ'' ∘ X; μ ] + H[ φ.symm ∘ ψ'' ∘ Y; μ' ] := by
simp_rw [← entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ φ.symm.injective,
← entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ φ.symm.injective]
_ ≤ α * (H[ ψ ∘ X; μ ] + H[ ψ ∘ Y; μ' ]) := hup'.le
_ ≤ α * (c * (H[X ; μ] + H[Y ; μ'])) := by gcongr
_ = (α * c) * (H[X ; μ] + H[Y ; μ']) := by ring
· use ⊥
constructor
· simp only [AddSubgroup.mem_bot, Nat.card_eq_fintype_card, Fintype.card_ofSubsingleton,
Nat.cast_one, log_one]
positivity
· simp only [S, Set.mem_setOf_eq, not_and, not_lt] at hE
exact hE ⟨1, by norm_num, by
norm_num; exact add_le_add (entropy_comp_le μ hX _) (entropy_comp_le μ' hY _)⟩
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq 2 * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 34 * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
34 * d[(QuotientAddGroup.mk' H) ∘ X;μ # (QuotientAddGroup.mk' H) ∘ Y;μ'] := by
rcases PFR_projection' X Y μ μ' ((3 : ℝ) / 5) hX hY (by norm_num) (by norm_num) with ⟨H, h, h'⟩
refine ⟨H, ?_, ?_⟩
· convert h
norm_num
· have : 0 ≤ d[⇑(QuotientAddGroup.mk' H) ∘ X ; μ # ⇑(QuotientAddGroup.mk' H) ∘ Y ; μ'] :=
rdist_nonneg ((measurable_discrete _).comp hX) ((measurable_discrete _).comp hY)
linarith
end F2_projection
open MeasureTheory ProbabilityTheory Real Set
open scoped BigOperators
lemma four_logs {a b c d : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) (hd : 0 < d) :
log ((a*b)/(c*d)) = log a + log b - log c - log d := by
rw [log_div, log_mul, log_mul, sub_sub] <;> positivity
lemma sum_prob_preimage {G H : Type*} {X : Finset H} {A : Set G} [Finite A] {φ : A → X}
{A_ : H → Set G} (hA : A.Nonempty) (hφ : ∀ x : X, A_ x = Subtype.val '' (φ ⁻¹' {x})) :
∑ x in X, (Nat.card (A_ x) : ℝ) / (Nat.card A) = 1 := by
rw [← Finset.sum_div]
apply (div_eq_one_iff_eq <| Nat.cast_ne_zero.mpr <| Nat.pos_iff_ne_zero.mp (@Nat.card_pos _ hA.to_subtype _)).mpr
classical
haveI := Fintype.ofFinite A
rewrite [Nat.card_eq_fintype_card, ← Finset.card_univ, Finset.card_eq_sum_card_fiberwise
<| fun a _ ↦ Finset.mem_univ (φ a), ← Finset.sum_coe_sort]
norm_cast
congr; ext
rewrite [← Set.Finite.toFinset_setOf, (Set.toFinite _).card_toFinset, ← Nat.card_eq_fintype_card,
hφ, Nat.card_image_of_injective Subtype.val_injective]; rfl
/-- Let $\phi : G\to H$ be a homomorphism and $A,B\subseteq G$ be finite subsets. If $x,y\in H$ then let $A_x=A\cap \phi^{-1}(x)$ and $B_y=B\cap \phi^{-1}(y)$. There exist $x,y\in H$ such that $A_x,B_y$ are both non-empty and
\[d[\phi(U_A);\phi(U_B)]\log \frac{\lvert A\rvert\lvert B\rvert}{\lvert A_x\rvert\lvert B_y\rvert}\leq (\mathbb{H}(\phi(U_A))+\mathbb{H}(\phi(U_B)))(d(U_A,U_B)-d(U_{A_x},U_{B_y}).\] -/
lemma single_fibres {G H Ω Ω': Type u}
[AddCommGroup G] [Countable G] [MeasurableSpace G] [MeasurableSingletonClass G]
[AddCommGroup H] [Countable H] [MeasurableSpace H] [MeasurableSingletonClass H]
[MeasureSpace Ω] [MeasureSpace Ω']
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
(φ : G →+ H)
{A B : Set G} [Finite A] [Finite B] {UA : Ω → G} {UB: Ω' → G} (hA : A.Nonempty) (hB : B.Nonempty)
(hUA': Measurable UA) (hUB': Measurable UB) (hUA: IsUniform A UA) (hUB: IsUniform B UB)
(hUA_mem : ∀ ω, UA ω ∈ A) (hUB_mem : ∀ ω, UB ω ∈ B) :
∃ (x y : H) (Ax By: Set G),
Ax = A ∩ φ.toFun ⁻¹' {x} ∧ By = B ∩ φ.toFun ⁻¹' {y} ∧ Ax.Nonempty ∧ By.Nonempty ∧
d[φ.toFun ∘ UA # φ.toFun ∘ UB]
* log ((Nat.card A) * (Nat.card B) / ((Nat.card Ax) * (Nat.card By))) ≤
(H[φ.toFun ∘ UA] + H[φ.toFun ∘ UB]) * (d[UA # UB] - dᵤ[Ax # By]) := by
have : Nonempty A := hA.to_subtype
have : Nonempty B := hB.to_subtype
haveI : FiniteRange UA := finiteRange_of_finset UA A.toFinite.toFinset (by simpa)
haveI : FiniteRange UB := finiteRange_of_finset UB B.toFinite.toFinset (by simpa)
have hUA_coe : IsUniform A.toFinite.toFinset.toSet UA := by rwa [Set.Finite.coe_toFinset]
have hUB_coe : IsUniform B.toFinite.toFinset.toSet UB := by rwa [Set.Finite.coe_toFinset]
let A_ (x : H) : Set G := A ∩ φ.toFun ⁻¹' {x}
let B_ (y : H) : Set G := B ∩ φ.toFun ⁻¹' {y}
let X : Finset H := FiniteRange.toFinset (φ.toFun ∘ UA)
let Y : Finset H := FiniteRange.toFinset (φ.toFun ∘ UB)
haveI h_Ax (x : X) : Nonempty (A_ x.val) := by
obtain ⟨ω, hω⟩ := (FiniteRange.mem_iff _ _).mp x.property
use UA ω; exact Set.mem_inter (hUA_mem ω) (by exact hω)
haveI h_By (y : Y) : Nonempty (B_ y.val) := by
obtain ⟨ω, hω⟩ := (FiniteRange.mem_iff _ _).mp y.property
use UB ω; exact Set.mem_inter (hUB_mem ω) (by exact hω)
have h_AX (a : A) : φ.toFun a.val ∈ X := by
obtain ⟨ω, hω⟩ := hUA_coe.nonempty_preimage_of_mem hUA' (A.toFinite.mem_toFinset.mpr a.property)
exact (FiniteRange.mem_iff _ (φ.toFun a.val)).mpr ⟨ω, congr_arg _ hω⟩
have h_BY (b : B) : φ.toFun b.val ∈ Y := by
obtain ⟨ω, hω⟩ := hUB_coe.nonempty_preimage_of_mem hUB' (B.toFinite.mem_toFinset.mpr b.property)
exact (FiniteRange.mem_iff _ (φ.toFun b.val)).mpr ⟨ω, congr_arg _ hω⟩
let φ_AX (a : A) : X := by use φ.toFun a.val; exact h_AX a
let φ_BY (b : B) : Y := by use φ.toFun b.val; exact h_BY b
have h_φ_AX (x : X) : A_ x.val = φ_AX ⁻¹' {x} := by ext; simp [A_, φ_AX]; simp [Subtype.ext_iff]
have h_φ_BY (y : Y) : B_ y.val = φ_BY ⁻¹' {y} := by ext; simp [B_, φ_BY]; simp [Subtype.ext_iff]
let p (x : H) (y : H) : ℝ :=
(Nat.card (A_ x).Elem) * (Nat.card (B_ y).Elem) / ((Nat.card A.Elem) * (Nat.card B.Elem))
have :
∑ x in X, ∑ y in Y, (p x y) * dᵤ[A_ x # B_ y] ≤ d[UA # UB] - d[φ.toFun ∘ UA # φ.toFun ∘ UB] :=
calc
_ = d[UA | φ.toFun ∘ UA # UB | φ.toFun ∘ UB] := by
rewrite [condRuzsaDist_eq_sum hUA' ((measurable_discrete _).comp hUA')
hUB' ((measurable_discrete _).comp hUB')]
refine Finset.sum_congr rfl <| fun x hx ↦ Finset.sum_congr rfl <| fun y hy ↦ ?_
haveI : Nonempty (A_ x) := h_Ax ⟨x, hx⟩
haveI : Nonempty (B_ y) := h_By ⟨y, hy⟩
let μx := (ℙ : Measure Ω)[|(φ.toFun ∘ UA) ⁻¹' {x}]
let μy := (ℙ : Measure Ω')[|(φ.toFun ∘ UB) ⁻¹' {y}]
have h_μ_p : IsProbabilityMeasure μx ∧ IsProbabilityMeasure μy := by
constructor <;> apply ProbabilityTheory.cond_isProbabilityMeasure <;> rw [Set.preimage_comp]
refine @IsUniform.measure_preimage_ne_zero _ _ _ _ _ _ _ _ _ _ hUA_coe hUA' _ ?_
swap; refine @IsUniform.measure_preimage_ne_zero _ _ _ _ _ _ _ _ _ _ hUB_coe hUB' _ ?_
all_goals rwa [Set.inter_comm, Set.Finite.coe_toFinset]
have h_μ_unif : IsUniform (A_ x) UA μx ∧ IsUniform (B_ y) UB μy := by
have : _ ∧ _ := ⟨hUA.restrict hUA' (φ.toFun ⁻¹' {x}), hUB.restrict hUB' (φ.toFun ⁻¹' {y})⟩
rwa [Set.inter_comm _ A, Set.inter_comm _ B] at this
rewrite [rdist_set_eq_rdist h_μ_p.1 h_μ_p.2 h_μ_unif.1 h_μ_unif.2 hUA' hUB']
show _ = (Measure.real _ (UA ⁻¹' (_ ⁻¹' _))) * (Measure.real _ (UB ⁻¹' (_ ⁻¹' _))) * _
rewrite [hUA_coe.measureReal_preimage hUA', hUB_coe.measureReal_preimage hUB']
simp_rw [p, A_, B_, IsProbabilityMeasure.measureReal_univ, one_mul]
rewrite [mul_div_mul_comm, Set.inter_comm A, Set.inter_comm B]
simp only [Set.Finite.coe_toFinset, Set.Finite.mem_toFinset, Finset.mem_val]; rfl
_ ≤ d[UA # UB] - d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
rewrite [ZeroHom.toFun_eq_coe, AddMonoidHom.toZeroHom_coe]
linarith only [rdist_le_sum_fibre φ hUA' hUB' (μ := ℙ) (μ' := ℙ)]
let M := H[φ.toFun ∘ UA] + H[φ.toFun ∘ UB]
have hM : M = ∑ x in X, ∑ y in Y, Real.negMulLog (p x y) := by
have h_compl {x y} (h_notin : (x, y) ∉ X ×ˢ Y) : Real.negMulLog (p x y) = 0 := by
unfold_let p; beta_reduce
rewrite [Finset.mem_product, not_and_or] at h_notin
suffices A_ x = ∅ ∨ B_ y = ∅ by obtain h | h := this <;> rw [h] <;> simp
refine h_notin.imp ?_ ?_
· rw [← not_nonempty_iff_eq_empty]
rintro h ⟨a, ha, rfl⟩
exact h (h_AX ⟨a, ha⟩)
· rw [← not_nonempty_iff_eq_empty]
rintro h ⟨a, ha, rfl⟩
exact h (h_BY ⟨a, ha⟩)
unfold_let M
unfold entropy
haveI := isProbabilityMeasure_map (μ := ℙ) ((measurable_discrete φ).comp hUA').aemeasurable
haveI := isProbabilityMeasure_map (μ := ℙ) ((measurable_discrete φ).comp hUB').aemeasurable
rewrite [← Finset.sum_product', ← tsum_eq_sum fun _ ↦ h_compl, ← measureEntropy_prod]
apply tsum_congr; intro; congr
rewrite [← Set.singleton_prod_singleton, Measure.smul_apply, Measure.prod_prod,
Measure.map_apply ((measurable_discrete _).comp hUA') (MeasurableSet.singleton _),
Measure.map_apply ((measurable_discrete _).comp hUB') (MeasurableSet.singleton _),
Set.preimage_comp, hUA_coe.measure_preimage hUA',
Set.preimage_comp, hUB_coe.measure_preimage hUB']
simp [p, A_, B_, mul_div_mul_comm, Set.inter_comm, ENNReal.toReal_div]
have h_sum : ∑ x in X, ∑ y in Y,
(p x y) * (M * dᵤ[A_ x # B_ y] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p x y)) ≤
M * d[UA # UB] :=
calc
_ = ∑ x in X, ∑ y in Y, (p x y) * M * dᵤ[A_ x # B_ y] + M * d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
simp_rw [hM, Finset.sum_mul, ← Finset.sum_add_distrib]
refine Finset.sum_congr rfl <| fun _ _ ↦ Finset.sum_congr rfl <| fun _ _ ↦ ?_
simp only [negMulLog, left_distrib, mul_assoc, Finset.sum_mul]
exact congrArg (HAdd.hAdd _) (by group)
_ = M * ∑ x in X, ∑ y in Y, (p x y) * dᵤ[A_ x # B_ y] + M * d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
simp_rw [Finset.mul_sum]
congr; ext; congr; ext; group
_ ≤ M * d[UA # UB] := by
rewrite [← left_distrib]
apply mul_le_mul_of_nonneg_left
· linarith
· unfold_let M
linarith only [entropy_nonneg (φ.toFun ∘ UA) ℙ, entropy_nonneg (φ.toFun ∘ UB) ℙ]
have : ∃ x : X, ∃ y : Y,
M * dᵤ[A_ x.val # B_ y.val] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p x.val y.val) ≤
M * d[UA # UB] := by
let f (xy : H × H) := (p xy.1 xy.2) * (M * d[UA # UB])
let g (xy : H × H) := (p xy.1 xy.2) *
(M * dᵤ[A_ xy.1 # B_ xy.2] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p xy.1 xy.2))
by_contra hc; push_neg at hc
replace hc : ∀ xy ∈ X ×ˢ Y, f xy < g xy := by
refine fun xy h ↦ mul_lt_mul_of_pos_left ?_ ?_
· exact hc ⟨xy.1, (Finset.mem_product.mp h).1⟩ ⟨xy.2, (Finset.mem_product.mp h).2⟩
· haveI : Nonempty _ := h_Ax ⟨xy.1, (Finset.mem_product.mp h).1⟩
haveI : Nonempty _ := h_By ⟨xy.2, (Finset.mem_product.mp h).2⟩
simp only [p, div_pos, mul_pos, Nat.cast_pos, Nat.card_pos]
have h_nonempty : Finset.Nonempty (X ×ˢ Y) := by
use ⟨φ.toFun <| UA <| Classical.choice <| ProbabilityMeasure.nonempty ⟨ℙ, inferInstance⟩,
φ.toFun <| UB <| Classical.choice <| ProbabilityMeasure.nonempty ⟨ℙ, inferInstance⟩⟩
exact Finset.mem_product.mpr ⟨FiniteRange.mem _ _, FiniteRange.mem _ _⟩
replace hc := Finset.sum_lt_sum_of_nonempty h_nonempty hc
have h_p_one : ∑ x in X ×ˢ Y, p x.1 x.2 = 1 := by
simp_rw [Finset.sum_product, p, mul_div_mul_comm, ← Finset.mul_sum,
← sum_prob_preimage hA h_φ_AX, sum_prob_preimage hB h_φ_BY, mul_one]
rewrite [← Finset.sum_mul, h_p_one, one_mul, Finset.sum_product] at hc
exact not_le_of_gt hc h_sum
obtain ⟨x, y, hxy⟩ := this
refine ⟨x, y, A_ x.val, B_ y.val, rfl, rfl, @nonempty_of_nonempty_subtype _ _ (h_Ax x), @nonempty_of_nonempty_subtype _ _ (h_By y), ?_⟩
rewrite [← inv_div, Real.log_inv]
show _ * -log (p x.val y.val) ≤ M * _
linarith only [hxy]
section dim
open Classical
variable {G : Type*} [AddCommGroup G]
/- If G ≅ ℤᵈ then there is a subgroup H of G such that A lies in a coset of H. This is helpful to
give the equivalent definition of `dimension`. Here this is stated in greated generality since the
proof carries over automatically-/
lemma exists_coset_cover (A : Set G) :
∃ (d : ℕ), ∃ (S : Submodule ℤ G) (v : G),
FiniteDimensional.finrank ℤ S = d ∧ ∀ a ∈ A, a - v ∈ S := by
existsi FiniteDimensional.finrank ℤ (⊤ : Submodule ℤ G), ⊤, 0
refine ⟨rfl, fun a _ ↦ trivial⟩
/-- The dimension of the affine span over `ℤ` of a subset of an additive group. -/
noncomputable def dimension (A : Set G) : ℕ := Nat.find (exists_coset_cover A)
lemma dimension_le_of_coset_cover (A : Set G) (S : Submodule ℤ G) (v : G)
(hA : ∀ a ∈ A, a - v ∈ S) : dimension A ≤ FiniteDimensional.finrank ℤ S := by
apply Nat.find_le
existsi S , v
exact ⟨rfl, hA⟩
lemma dimension_le_rank [Module.Finite ℤ G] (A : Set G) :
dimension A ≤ FiniteDimensional.finrank ℤ G := by
obtain ⟨S, v, hs, _⟩ := Nat.find_spec (exists_coset_cover A)
rw [dimension, ←hs]
apply Submodule.finrank_le S
end dim
variable {G : Type u} [AddCommGroup G] [Module.Free ℤ G] [Module.Finite ℤ G] [Countable G] [MeasurableSpace G] [MeasurableSingletonClass G]
open Real MeasureTheory ProbabilityTheory Pointwise Set
/-- Move to Mathlib? `Finsupp.mapRange` of a surjective function is surjective. -/
lemma Finsupp.mapRange_surjective {α : Type u_1} {M : Type u_5} {N : Type u_7} [Zero M] [Zero N] (f : M → N) (hf : f 0 = 0)
(hs : Function.Surjective f) : Function.Surjective (Finsupp.mapRange (α := α) f hf) := by
classical
let g (n : N) : M := if n = 0 then 0 else Function.surjInv hs n
have : Function.RightInverse g f := by
intro n
by_cases h : n = 0
. simp [g, h, hf]
· simp [g, h, Function.surjInv_eq hs n]
have hg : g 0 = 0 := by simp [g]
have hfg : (f ∘ g) 0 = 0 := by simp [hf, hg]
intro F
use Finsupp.mapRange g hg F
rw [← Finsupp.mapRange_comp (h := hfg)]
convert Finsupp.mapRange_id F
convert Function.RightInverse.id this
/-- A free Z-module is torsion-free. Move to Mathlib? -/
lemma torsion_free : AddMonoid.IsTorsionFree G := by
rintro x hx hn
rw [isOfFinAddOrder_iff_nsmul_eq_zero] at hn
rcases hn with ⟨ n, hn, hn' ⟩
apply_fun Module.Free.repr ℤ G at hn'
simp_rw [map_nsmul, map_zero, smul_eq_zero, AddEquivClass.map_eq_zero_iff, hx, or_false] at hn'
linarith
/-- If G is a rank n free Z-module, then G/2G is a finite elementary 2-group of cardinality 2^n. Code is slow, needs to be golfed -/
lemma weak_PFR_quotient_prelim :
let H := G ⧸ (AddMonoidHom.range (zsmulAddGroupHom 2))
ElementaryAddCommGroup H 2 ∧ Finite H ∧ Nat.card H = 2^(FiniteDimensional.finrank ℤ G) := by
set ψ : G →+ G := zsmulAddGroupHom 2
set G₂ := AddMonoidHom.range ψ
set H := G ⧸ G₂
set φ : G →+ H := QuotientAddGroup.mk' G₂
have hH_elem : ElementaryAddCommGroup H 2 := by
apply ElementaryAddCommGroup.quotient_group (by decide)
intro x; rw [AddMonoidHom.mem_range]
use x
rw [zsmulAddGroupHom_apply]
norm_cast
let B := Module.Free.ChooseBasisIndex ℤ G
let bG : Basis B ℤ G := Module.Free.chooseBasis ℤ G
have hB_fin : Fintype B := by infer_instance
have hB_card : Nat.card B = FiniteDimensional.finrank ℤ G := by
rw [FiniteDimensional.finrank_eq_card_basis bG, Nat.card_eq_fintype_card]
have hH_module : Module (ZMod 2) H := by infer_instance
let mod : (B →₀ ℤ) →+ (B →₀ ZMod 2) := Finsupp.mapRange.addMonoidHom (Int.castAddHom (ZMod 2))
let f : G →+ (B →₀ ℤ) := bG.repr
have hker : G₂ ≤ AddMonoidHom.ker (AddMonoidHom.comp mod f) := by
intro x hx
simp only [AddMonoidHom.mem_range, G₂, ψ, zsmulAddGroupHom_apply] at hx
simp_rw [AddMonoidHom.mem_ker, AddMonoidHom.coe_comp, Function.comp_apply, mod,
Finsupp.mapRange.addMonoidHom_apply, Int.coe_castAddHom]
rcases hx with ⟨y, rfl⟩
ext b
simp_rw [map_zsmul, Finsupp.mapRange_apply, Finsupp.coe_smul, Pi.smul_apply, smul_eq_mul,
Int.cast_mul, Int.cast_ofNat, Finsupp.coe_zero, Pi.zero_apply, mul_eq_zero]
left
exact ZMod.nat_cast_self 2
let g : H →+ (B →₀ ZMod 2) := QuotientAddGroup.lift G₂ (AddMonoidHom.comp mod f) hker
have hsur : Function.Surjective g := by
have h1 : Function.Surjective mod := Finsupp.mapRange_surjective (Int.castAddHom (ZMod 2)) (map_zero _) ZMod.int_cast_surjective
have h2 := h1.comp bG.repr.surjective
have h3 : mod ∘ bG.repr = g ∘ (QuotientAddGroup.mk' G₂) := by
ext x b
simp_rw [mod, Function.comp_apply, Finsupp.mapRange.addMonoidHom_apply, Int.coe_castAddHom,
Finsupp.mapRange_apply, QuotientAddGroup.coe_mk', g]
rw [QuotientAddGroup.lift_mk]
simp [mod, f]
rw [h3] at h2
apply Function.Surjective.of_comp h2
have hinj : Function.Injective g := by
rw [injective_iff_map_eq_zero]
intro x hx
rcases QuotientAddGroup.mk'_surjective G₂ x with ⟨y, rfl⟩
simp only [QuotientAddGroup.mk'_apply, g] at hx
rw [QuotientAddGroup.lift_mk] at hx
simp_rw [AddMonoidHom.coe_comp, Function.comp_apply, mod, Finsupp.mapRange.addMonoidHom_apply,
Int.coe_castAddHom, DFunLike.ext_iff,Finsupp.mapRange_apply, Finsupp.coe_zero, Pi.zero_apply,
ZMod.int_cast_zmod_eq_zero_iff_dvd] at hx
replace hx := fun x ↦ Int.mul_ediv_cancel' (hx x)
let z (b : B) := ((Module.Free.chooseBasis ℤ G).repr y) b / 2
let z' := (Finsupp.equivFunOnFinite).symm z
change ∀ b : B, 2 * z' b = (f y) b at hx
let x' := bG.repr.symm z'
rw [QuotientAddGroup.mk'_apply, QuotientAddGroup.eq_zero_iff, AddMonoidHom.mem_range]
simp_rw [ψ, zsmulAddGroupHom_apply]
use x'
change 2 • (bG.repr.symm.toLinearMap.toAddMonoidHom z') = y
rw [← AddMonoidHom.map_zsmul bG.repr.symm.toLinearMap.toAddMonoidHom z' (2 : ℤ)]
rw [← LinearEquiv.symm_apply_apply bG.repr y]
change bG.repr.symm (2 • z') = bG.repr.symm (f y)
congr
ext b
rw [Finsupp.smul_apply, ← hx b, smul_eq_mul]
rcases Function.bijective_iff_has_inverse.mp ⟨ hinj, hsur ⟩ with ⟨ g', hg' ⟩
have bH : Basis B (ZMod 2) H := by
constructor
exact {
toFun := g
invFun := g'
left_inv := hg'.1
right_inv := hg'.2
map_add' := AddMonoidHom.map_add _
map_smul' := by
intro r x
rcases ZMod.int_cast_surjective r with ⟨ n, rfl ⟩
change g ((n : ZMod 2) • x) = (n : ZMod 2) • g x
rw [intCast_smul, intCast_smul]
exact AddMonoidHom.map_zsmul g x n
}
have hH_fin : Fintype H := Module.fintypeOfFintype bH
have hH_card : Nat.card H = 2^(FiniteDimensional.finrank ℤ G) := by
rw [Nat.card_eq_fintype_card, Module.card_fintype bH, ← Nat.card_eq_fintype_card (α := B), hB_card]
congr
exact ⟨ hH_elem, Finite.of_fintype H, hH_card ⟩
open QuotientAddGroup
/-- A version of the third isomorphism theorem: if G₂ ≤ G and H' is a subgroup of G⧸G₂, then there is a canonical isomorphism between H⧸H' and G⧸N, where N is the preimage of H' in G. A bit clunky; may be a better way to do this -/
lemma third_iso {G : Type u} [AddCommGroup G] {G₂ : AddSubgroup G} (H' : AddSubgroup (G ⧸ G₂)) :
let H := G ⧸ G₂
let φ : G →+ H := mk' G₂
let N := AddSubgroup.comap φ H'
∃ e : H ⧸ H' ≃+ G ⧸ N, ∀ x : G, e (mk' H' (φ x))= mk' N x := by
set H := G ⧸ G₂
let φ : G →+ H := mk' G₂
let N := AddSubgroup.comap φ H'
have h1 : G₂ ≤ N := by
intro x hx
rw [← eq_zero_iff] at hx
have : φ x = 0 := hx
simp [N, this, AddSubgroup.zero_mem H']
set H'' := AddSubgroup.map (mk' G₂) N
have h2 : H' = H'' := by
change H' = AddSubgroup.map (mk' G₂) N
rw [AddSubgroup.map_comap_eq, AddMonoidHom.range_top_of_surjective _ (mk'_surjective G₂)]
simp
let e1 : H ⧸ H'' ≃+ G ⧸ N := quotientQuotientEquivQuotient _ _ h1
let e2 := quotientAddEquivOfEq h2
set e := e2.trans e1
use e
intro x
convert (quotientQuotientEquivQuotientAux_mk_mk _ _ h1 x) using 1
lemma single {Ω : Type u} [MeasurableSpace Ω] [DiscreteMeasurableSpace Ω] (μ : Measure Ω)
[IsProbabilityMeasure μ] {A : Set Ω} {z : Ω} (hA : μ.real A = 1) (hz : μ.real {z} > 0) :
z ∈ A := by
contrapose! hz
have : Disjoint {z} A := by simp [hz]
replace this := measureReal_union (μ := μ) this (measurableSet_discrete _)
simp [hA] at this
have h := measureReal_mono (μ := μ) (show insert z A ⊆ Set.univ by simp)
simp [this] at h
assumption
/-- Given two non-empty finite subsets A, B of a rank n free Z-module G, there exists a subgroup N and points x, y in G/N such that the fibers Ax, By of A, B over x, y respectively are non-empty, one has the inequality
$$ \log \frac{|A| |B|}{|A_x| |B_y|} ≤ 34 (d[U_A; U_B] - d[U_{A_x}; U_{B_y}])$$
and one has the dimension bound
$$ n \log 2 ≤ \log |G/N| + 40 d[U_A; U_B].$$
-/
lemma weak_PFR_asymm_prelim (A B : Set G) [Finite A] [Finite B] (hnA : A.Nonempty) (hnB : B.Nonempty):
∃ (N : AddSubgroup G) (x y : G ⧸ N) (Ax By : Set G), Ax.Nonempty ∧ By.Nonempty ∧
Set.Finite Ax ∧ Set.Finite By ∧ Ax = {z:G | z ∈ A ∧ QuotientAddGroup.mk' N z = x } ∧
By = {z:G | z ∈ B ∧ QuotientAddGroup.mk' N z = y } ∧
(log 2) * FiniteDimensional.finrank ℤ G ≤ log (Nat.card (G ⧸ N)) +
40 * dᵤ[ A # B ] ∧ log (Nat.card A) + log (Nat.card B) - log (Nat.card Ax) - log (Nat.card By)
≤ 34 * (dᵤ[ A # B ] - dᵤ[ Ax # By ]) := by
have : Nonempty A := hnA.to_subtype
have : Nonempty B := hnB.to_subtype
obtain ⟨ h_elem, h_finite, h_card ⟩ := weak_PFR_quotient_prelim (G := G)
set ψ : G →+ G := zsmulAddGroupHom 2
set G₂ := AddMonoidHom.range ψ
set H := G ⧸ G₂
let φ : G →+ H := QuotientAddGroup.mk' G₂
let _mH : MeasurableSpace H := ⊤
have h_fintype : Fintype H := Fintype.ofFinite H
have h_torsionfree := torsion_free (G := G)
obtain ⟨ Ω, mΩ, UA, hμ, hUA_mes, hUA_unif, hUA_mem, hUA_fin ⟩ := exists_isUniform_measureSpace' A
obtain ⟨ Ω', mΩ', UB, hμ', hUB_mes, hUB_unif, hUB_mem, hUB_fin ⟩ :=
exists_isUniform_measureSpace' B
rcases (PFR_projection (φ.toFun ∘ UA) (φ.toFun ∘ UB) ℙ ℙ (by measurability) (by measurability)) with ⟨H', ⟨ hH1, hH2 ⟩ ⟩
let N := AddSubgroup.comap φ H'
set φ' := QuotientAddGroup.mk' N
have _cGN : Countable (G ⧸ N) := Function.Surjective.countable (QuotientAddGroup.mk'_surjective N)
have _msGN : MeasurableSingletonClass (G ⧸ N) := by
constructor
intro x
exact MeasurableSpace.map_def.mpr (measurableSet_discrete _)
rcases third_iso H' with ⟨ e : H ⧸ H' ≃+ G ⧸ N, he ⟩
rcases single_fibres φ' hnA hnB hUA_mes hUB_mes hUA_unif hUB_unif hUA_mem hUB_mem with
⟨x, y, Ax, By, hAx, hBy, hnAx, hnBy, hcard_ineq⟩
have : Nonempty Ax := hnAx.to_subtype
have : Nonempty By := hnBy.to_subtype
have Axf : Finite Ax := by rw [hAx]; infer_instance
have Byf : Finite By := by rw [hBy]; infer_instance
have h1 := torsion_dist_shrinking UA UB ℙ ℙ hUA_mes hUB_mes h_torsionfree φ
have h2 := torsion_dist_shrinking UB UA ℙ ℙ hUB_mes hUA_mes h_torsionfree φ
rw [rdist_symm] at h2
rw [<- rdist_set_eq_rdist hμ hμ' hUA_unif hUB_unif hUA_mes hUB_mes] at h1 h2
-- using explicit .toFun casts as this saves a lot of heartbeats
change H[φ.toFun ∘ UA] ≤ 10 * dᵤ[A # B] at h1
change H[φ.toFun ∘ UB] ≤ 10 * dᵤ[A # B] at h2
replace hH1 : log (Nat.card H') ≤ 40 * dᵤ[A # B] := by
apply hH1.trans
linarith
replace h_card : log 2 * FiniteDimensional.finrank ℤ G ≤ log (Nat.card (G ⧸ N)) + 40 * dᵤ[A # B] := by
rw [mul_comm, ← log_rpow (by norm_num)]
norm_cast
classical
rwa [← h_card, ← Nat.card_congr e.toEquiv, Nat.card_eq_fintype_card, Nat.card_eq_fintype_card, ← AddSubgroup.index_mul_card H', AddSubgroup.index_eq_card, Nat.cast_mul, log_mul, add_le_add_iff_left, ← Nat.card_eq_fintype_card]
all_goals norm_cast; exact Fintype.card_ne_zero
use N, x, y, Ax, By
refine ⟨ hnAx, hnBy, Ax.toFinite, By.toFinite, hAx, hBy, h_card, ?_ ⟩
replace hH2 : H[φ'.toFun ∘ UA] + H[φ'.toFun ∘ UB] ≤ 34 * d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] := by
set X := ((mk' H').toFun ∘ φ.toFun) ∘ UA
set Y := ((mk' H').toFun ∘ φ.toFun) ∘ UB
have hX : Measurable X := Measurable.comp (measurable_discrete _) hUA_mes
have hY : Measurable Y := Measurable.comp (measurable_discrete _) hUB_mes
change H[X] + H[Y] ≤ 34 * d[X # Y] at hH2
have ha : φ'.toFun ∘ UA = e.toFun ∘ X := by ext x; exact (he (UA x)).symm
have hb : φ'.toFun ∘ UB = e.toFun ∘ Y := by ext x; exact (he (UB x)).symm
have he_inj : Function.Injective e.toFun := AddEquiv.injective e
rw [ha, hb, entropy_comp_of_injective _ hX _ he_inj, entropy_comp_of_injective _ hY _ he_inj]
have : d[e.toFun ∘ X # e.toFun ∘ Y] = d[X # Y] := rdist_of_inj hX hY e.toAddMonoidHom he_inj
rwa [this]
set X : Ω → G ⧸ N := φ'.toFun ∘ UA
set Y : Ω' → G ⧸ N := φ'.toFun ∘ UB
have hX : Measurable X := Measurable.comp (measurable_discrete _) hUA_mes
have hY : Measurable Y := Measurable.comp (measurable_discrete _) hUB_mes
rcases le_iff_lt_or_eq.mp (rdist_nonneg (μ := ℙ) (μ' := ℙ) hX hY) with h | h
swap
. rw [← h] at hH2
have hH2A : H[X] ≥ 0 := entropy_nonneg _ _
have hH2B : H[Y] ≥ 0 := entropy_nonneg _ _
have hH2A' : H[X] ≤ 0 := by linarith only [hH2, hH2A, hH2B]
have hH2B' : H[Y] ≤ 0 := by linarith only [hH2, hH2A, hH2B]
rcases const_of_nonpos_entropy (μ := ℙ) hX hH2A' with ⟨ x', hx ⟩
rcases const_of_nonpos_entropy (μ := ℙ) hY hH2B' with ⟨ y', hy ⟩
have hAAx {z : G} (hz : z ∈ A) : φ'.toFun z = x' := by
change (ℙ).real (UA⁻¹' (φ'⁻¹' {x'})) = 1 at hx
rw [← MeasureTheory.map_measureReal_apply hUA_mes (measurableSet_discrete _)] at hx
set Af := A.toFinite.toFinset
have hUAf : IsUniform Af UA := by
convert hUA_unif; simp only [Af, Set.Finite.coe_toFinset]
have hnAf : 0 < Nat.card Af := by simp only [Af, Set.Finite.mem_toFinset, Nat.card_pos]
have hzf : z ∈ Af := by simp [Af, Set.Finite.mem_toFinset, hz]
have : (Measure.map UA ℙ).real {z} > 0 := by
rw [IsUniform.measureReal_preimage_of_mem' hUAf hUA_mes hzf]
positivity
have _ : IsProbabilityMeasure ((ℙ).map UA) := by
exact MeasureTheory.isProbabilityMeasure_map (Measurable.aemeasurable hUA_mes)
replace this := single ((ℙ).map UA) hx this
rwa [Set.mem_preimage, Set.mem_singleton_iff] at this
have hxx : Ax = A := by
have h : hnAx.some ∈ Ax := hnAx.some_mem
simp [hAx] at h ⊢
have := hAAx h.1
simp [h.2] at this
intro z hz
simp [this]
convert hAAx hz
have hBBy {z : G} (hz : z ∈ B) : φ'.toFun z = y' := by
change (ℙ).real (UB⁻¹' (φ'⁻¹' {y'})) = 1 at hy
rw [← MeasureTheory.map_measureReal_apply hUB_mes (measurableSet_discrete _)] at hy
set Bf := B.toFinite.toFinset
have hUBf : IsUniform Bf UB := by convert hUB_unif; simp only [Bf, Set.Finite.coe_toFinset]
have hnBf : 0 < Nat.card Bf := by simp only [Bf, Set.Finite.mem_toFinset, Nat.card_pos]
have hzf : z ∈ Bf := by simp [Bf, Set.Finite.mem_toFinset, hz]
have : (Measure.map UB ℙ).real {z} > 0 := by
rw [IsUniform.measureReal_preimage_of_mem' hUBf hUB_mes hzf]
positivity
have _ : IsProbabilityMeasure ((ℙ).map UB) := by
exact MeasureTheory.isProbabilityMeasure_map (Measurable.aemeasurable hUB_mes)
replace this := single ((ℙ).map UB) hy this
rwa [Set.mem_preimage, Set.mem_singleton_iff] at this
have hyy : By = B := by
have h : hnBy.some ∈ By := hnBy.some_mem
simp [hBy] at h ⊢
have := hBBy h.1
simp [h.2] at this
intro z hz
simp [this]
convert hBBy hz
simp [hxx, hyy]
have := calc d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] * (log (Nat.card A) + log (Nat.card B) - log (Nat.card Ax) - log (Nat.card By))
_ = d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] * log ((Nat.card A) * (Nat.card B) / ((Nat.card Ax) * (Nat.card By))) := by
congr
convert (four_logs ?_ ?_ ?_ ?_).symm
all_goals norm_cast; exact Nat.card_pos
_ ≤ (H[φ'.toFun ∘ UA] + H[φ'.toFun ∘ UB]) * (d[UA # UB] - dᵤ[Ax # By]) := hcard_ineq
_ ≤ (34 * d[φ'.toFun ∘ UA # φ'.toFun ∘ UB]) * (d[UA # UB] - dᵤ[Ax # By]) := by
apply mul_le_mul_of_nonneg_right hH2
have := rdist_le_avg_ent (Measurable.comp (measurable_discrete φ'.toFun) hUA_mes) (Measurable.comp (measurable_discrete φ'.toFun) hUB_mes)
replace this : 0 < H[φ'.toFun ∘ UA] + H[φ'.toFun ∘ UB] := by linarith
rw [← mul_le_mul_left this]
apply le_trans _ hcard_ineq
rw [mul_zero]
change 0 ≤ d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] * log ((Nat.card A) * (Nat.card B) / ((Nat.card Ax) * (Nat.card By)))
rw [← mul_zero d[φ'.toFun ∘ UA # φ'.toFun ∘ UB], mul_le_mul_left h]
apply Real.log_nonneg
rw [one_le_div]
gcongr
. apply Nat.card_mono
. exact Set.toFinite A
rw [hAx]; exact Set.inter_subset_left _ _
apply Nat.card_mono
. exact Set.toFinite B
rw [hBy]; exact Set.inter_subset_left _ _
norm_cast
exact mul_pos Nat.card_pos Nat.card_pos
_ = d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] * (34 * (d[UA # UB] - dᵤ[Ax # By])) := by ring
_ = d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] * (34 * (dᵤ[A # B] - dᵤ[Ax # By])) := by
rw [<- rdist_set_eq_rdist hμ hμ' hUA_unif hUB_unif hUA_mes hUB_mes]
exact (mul_le_mul_left h).mp this
/-- Separating out the conclusion of `weak_PFR_asymm` for convenience of induction arguments.-/
def WeakPFRAsymmConclusion (A B : Set G) : Prop :=
∃ A' B' : Set G, A' ⊆ A ∧ B' ⊆ B ∧ A'.Nonempty ∧ B'.Nonempty ∧
log (((Nat.card A) * (Nat.card B)) / ((Nat.card A') * (Nat.card B'))) ≤ 34 * dᵤ[A # B] ∧
max (dimension A') (dimension B') ≤ (40 / log 2) * dᵤ[A # B]
/-- The property of two sets A,B of a group G not being contained in cosets of the same proper subgroup -/
def not_in_coset {G: Type u} [AddCommGroup G] (A B : Set G) : Prop := AddSubgroup.closure ((A-A) ∪ (B-B)) = ⊤
/-- In fact one has equality here, but this is tricker to prove and not needed for the argument. -/
lemma dimension_of_shift {G: Type u} [AddCommGroup G]
{H: AddSubgroup G} (A : Set H) (x : G) :
dimension ((fun a:H ↦ (a:G) + x) '' A) ≤ dimension A := by
classical
rcases Nat.find_spec (exists_coset_cover A) with ⟨ S, v, hrank, hshift ⟩
change FiniteDimensional.finrank ℤ S = dimension A at hrank
rw [← hrank]
convert dimension_le_of_coset_cover _ (Submodule.map H.subtype.toIntLinearMap S) (x+v) ?_
. apply LinearEquiv.finrank_eq
exact Submodule.equivMapOfInjective _ (by simpa using Subtype.val_injective) _
intro a ha
rw [Set.mem_image] at ha
rcases ha with ⟨ b, ⟨ hb, hb'⟩ ⟩
rw [Submodule.mem_map]
use b - v, hshift b hb
simp [← hb']
abel
lemma conclusion_transfers {A B : Set G}
(G': AddSubgroup G) (A' B' : Set G')
(hA : IsShift A A') (hB : IsShift B B') [Finite A'] [Finite B'] (hA' : A'.Nonempty) (hB' : B'.Nonempty)
(h : WeakPFRAsymmConclusion A' B') : WeakPFRAsymmConclusion A B := by
have : Nonempty A' := hA'.to_subtype
have : Nonempty B' := hB'.to_subtype
rcases h with ⟨A'', B'', hA'', hB'', hA''_non, hB''_non, hcard_ineq, hdim_ineq⟩
rcases hA with ⟨ x, hA ⟩
set f : G' → G := fun a ↦ (a : G) + x
have hf : Function.Injective f := by
intro y z hyz
simp [f] at hyz
exact hyz
have hA' : A = f '' A' := by
simp_rw [hA, ← Set.image_vadd, Set.image_image, vadd_eq_add, f, add_comm]; rfl
rcases hB with ⟨ y, hB ⟩
set g : G' → G := fun a ↦ (a : G) + y
have hg : Function.Injective g := by
intro y z hyz
simp [g] at hyz
exact hyz
have hB' : B = g '' B' := by
simp_rw [hB, ← Set.image_vadd, Set.image_image, vadd_eq_add, g, add_comm]; rfl
use f '' A'', g '' B''
have : dᵤ[A # B] = dᵤ[A' # B'] := by
rw [<-rdist_set_of_inj _ _ (φ := G'.subtype) Subtype.val_injective, <-rdist_set_add_const (G'.subtype '' A') (G'.subtype '' B') x y]
congr
. rw [hA]
ext y
simp [Set.mem_vadd_set]
constructor
. rintro ⟨ z, ⟨ ⟨ w, hw ⟩, rfl ⟩ ⟩
have : x + z + -x ∈ G' := by simp [w]
use this
simp
convert hw
rintro ⟨ h, ha ⟩
use y + -x
constructor
. use h
abel
rw [hB]
ext x
simp [Set.mem_vadd_set]
constructor
. rintro ⟨ z, ⟨ ⟨ w, hw ⟩, rfl ⟩ ⟩
have : y + z + -y ∈ G' := by simp [w]
use this
simp
convert hw
rintro ⟨ h, ha ⟩
use x + -y
constructor
. use h
abel
refine ⟨ ?_, ?_, ?_, ?_, ?_, ?_ ⟩
. simp [hA', hf, hA'']
. simp [hB', hg, hB'']
. simp [hA''_non]
. simp [hB''_non]
. convert hcard_ineq using 2
. congr 3
. rw [hA', Nat.card_image_of_injective hf]
. rw [hB', Nat.card_image_of_injective hg]
. rw [Nat.card_image_of_injective hf]
rw [Nat.card_image_of_injective hg]
convert LE.le.trans _ hdim_ineq using 2
norm_cast
apply max_le_max
. exact dimension_of_shift A'' x
· exact dimension_of_shift B'' y
/-- If $A,B\subseteq \mathbb{Z}^d$ are finite non-empty sets then there exist non-empty $A'\subseteq A$ and $B'\subseteq B$ such that
\[\log\frac{\lvert A\rvert\lvert B\rvert}{\lvert A'\rvert\lvert B'\rvert}\leq 34 d[U_A;U_B]\]
such that $\max(\dim A',\dim B')\leq \frac{40}{\log 2} d[U_A;U_B]$. -/
| lemma weak_PFR_asymm (A B : Set G) [Finite A] [Finite B] (hA : A.Nonempty) (hB : B.Nonempty) : WeakPFRAsymmConclusion A B | weak_PFR_asymm | 25309ad 20231211 | c0c547a 20240116 | pfr/PFR/WeakPFR.lean | {
"lineInFile": 1063,
"tokenPositionInFile": 54433,
"theoremPositionInFile": 29
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n let P : ℕ → Prop := fun M ↦ (∀ (G : Type u) (hG_comm : AddCommGroup G) (_hG_free : Module.Free ℤ G) (_hG_fin : Module.Finite ℤ G) (_hG_count : Countable G) (hG_mes : MeasurableSpace G) (_hG_sing: MeasurableSingletonClass G) (A B: Set G) (_hA_fin: Finite A) (_hB_fin: Finite B) (_hA_non: A.Nonempty) (_hB_non: B.Nonempty) (_hM : (Nat.card A) + (Nat.card B) ≤ M), WeakPFRAsymmConclusion A B)\n suffices ∀ M, (∀ M', M' < M → P M') → P M by\n set M := (Nat.card A) + (Nat.card B)\n have hM : (Nat.card A) + (Nat.card B) ≤ M := Nat.le_refl _\n convert (Nat.strong_induction_on (p := P) M this) G ‹_› ‹_› ‹_› ‹_› _ ‹_› A B ‹_› ‹_› ‹_› ‹_› hM\n intro M h_induct\n -- wlog we can assume A, B are not in cosets of a smaller subgroup\n suffices ∀ (G : Type u) (hG_comm : AddCommGroup G) (_hG_free : Module.Free ℤ G)\n (_hG_fin : Module.Finite ℤ G) (_hG_count : Countable G) (hG_mes : MeasurableSpace G)\n (_hG_sing : MeasurableSingletonClass G) (A B : Set G) (_hA_fin : Finite A) (_hB_fin : Finite B) (_hA_non : A.Nonempty) (_hB_non : B.Nonempty) (_hM : Nat.card A + Nat.card B ≤ M)\n (_hnot : NotInCoset A B), WeakPFRAsymmConclusion A B by\n intro G hG_comm hG_free hG_fin hG_count hG_mes hG_sing A B hA_fin hB_fin hA_non hB_non hM\n obtain ⟨ G', A', B', hAA', hBB', hnot' ⟩ := wlog_notInCoset hA_non hB_non\n have hG'_fin : Module.Finite ℤ G' :=\n Module.Finite.iff_fg (N := AddSubgroup.toIntSubmodule G').2 (IsNoetherian.noetherian _)\n\n have hG'_free : Module.Free ℤ G' := by\n rcases Submodule.nonempty_basis_of_pid (Module.Free.chooseBasis ℤ G) (AddSubgroup.toIntSubmodule G') with ⟨ n, ⟨ b ⟩ ⟩\n exact Module.Free.of_basis b\n have hAA'_card: Nat.card A = Nat.card A' := (Nat.card_image_of_injective Subtype.val_injective _) ▸ hAA'.card_congr\n have hBB'_card: Nat.card B = Nat.card B' := (Nat.card_image_of_injective Subtype.val_injective _) ▸ hBB'.card_congr\n have hA_non' : Nonempty A := Set.nonempty_coe_sort.mpr hA_non\n have hB_non' : Nonempty B := Set.nonempty_coe_sort.mpr hB_non\n\n rw [hAA'_card, hBB'_card] at hM\n\n have hA'_nonfin : A'.Nonempty ∧ Finite A' := by\n have := Nat.card_pos (α := A)\n rw [hAA'_card, Nat.card_pos_iff] at this\n exact ⟨@nonempty_of_nonempty_subtype _ _ this.1, this.2⟩\n have hB'_nonfin : B'.Nonempty ∧ Finite B' := by\n have := Nat.card_pos (α := B)\n rw [hBB'_card, Nat.card_pos_iff] at this\n exact ⟨@nonempty_of_nonempty_subtype _ _ this.1, this.2⟩\n obtain ⟨ hA'_non, hA'_fin ⟩ := hA'_nonfin\n obtain ⟨ hB'_non, hB'_fin ⟩ := hB'_nonfin\n\n replace this := this G' _ hG'_free hG'_fin (by infer_instance) (by infer_instance) (by infer_instance) A' B' hA'_fin hB'_fin hA'_non hB'_non hM hnot'\n exact conclusion_transfers G' A' B' hAA' hBB' hA'_non hB'_non this\n intro G hG_comm hG_free hG_fin hG_count hG_mes hG_sing A B hA_fin hB_fin hA_non hB_non hM hnot\n rcases weak_PFR_asymm_prelim A B hA_non hB_non with ⟨ N, x, y, Ax, By, hAx_non, hBy_non, hAx_fin, hBy_fin, hAx, hBy, hdim, hcard⟩\n have hAxA : Ax ⊆ A := by rw [hAx]; simp\n have hByB : By ⊆ B := by rw [hBy]; simp\n have hA_pos : (0 : ℝ) < Nat.card A := Nat.cast_pos.mpr (@Nat.card_pos _ hA_non.to_subtype _)\n have hB_pos : (0 : ℝ) < Nat.card B := Nat.cast_pos.mpr (@Nat.card_pos _ hB_non.to_subtype _)\n\n rcases lt_or_ge (Nat.card Ax + Nat.card By) (Nat.card A + Nat.card B) with h | h\n . replace h := h_induct (Nat.card Ax + Nat.card By) (h.trans_le hM) G hG_comm hG_free hG_fin hG_count hG_mes hG_sing Ax By (Set.finite_coe_iff.mpr hAx_fin) (Set.finite_coe_iff.mpr hBy_fin) hAx_non hBy_non (Eq.le rfl)\n rcases h with ⟨ A', B', hA', hB', hA'_non, hB'_non, hcard_ineq, hdim_ineq ⟩\n use A', B'\n have hAx_fin' := Set.finite_coe_iff.mpr hAx_fin\n have hBy_fin' := Set.finite_coe_iff.mpr hBy_fin\n have hA'_fin' := Set.finite_coe_iff.mpr (Set.Finite.subset hAx_fin hA')\n have hB'_fin' := Set.finite_coe_iff.mpr (Set.Finite.subset hBy_fin hB')\n have hAx_non' := Set.nonempty_coe_sort.mpr hAx_non\n have hBy_non' := Set.nonempty_coe_sort.mpr hBy_non\n have hA'_non' := Set.nonempty_coe_sort.mpr hA'_non\n have hB'_non' := Set.nonempty_coe_sort.mpr hB'_non\n have hAx_pos : (0 : ℝ) < Nat.card Ax := Nat.cast_pos.mpr Nat.card_pos\n have hBy_pos : (0 : ℝ) < Nat.card By := Nat.cast_pos.mpr Nat.card_pos\n have hA'_pos : (0 : ℝ) < Nat.card A' := Nat.cast_pos.mpr Nat.card_pos\n have hB'_pos : (0 : ℝ) < Nat.card B' := Nat.cast_pos.mpr Nat.card_pos\n have hAxA_le : (Nat.card Ax : ℝ) ≤ (Nat.card A : ℝ) := Nat.cast_le.mpr (Nat.card_mono A.toFinite hAxA)\n have hByB_le : (Nat.card By : ℝ) ≤ (Nat.card B : ℝ) := Nat.cast_le.mpr (Nat.card_mono B.toFinite hByB)\n\n refine ⟨ hA'.trans hAxA, hB'.trans hByB, hA'_non, hB'_non, ?_, ?_ ⟩\n . rw [four_logs hA_pos hB_pos hA'_pos hB'_pos]\n rw [four_logs hAx_pos hBy_pos hA'_pos hB'_pos] at hcard_ineq\n linarith only [hcard, hcard_ineq]\n apply hdim_ineq.trans\n gcongr\n linarith only [Real.log_le_log hAx_pos hAxA_le, Real.log_le_log hBy_pos hByB_le, hcard]\n use A, B\n refine ⟨ Eq.subset rfl, Eq.subset rfl, hA_non, hB_non, ?_, ?_ ⟩\n . have := hA_non.to_subtype\n have := hB_non.to_subtype\n apply LE.le.trans _ <| mul_nonneg (by norm_num) <| rdist_set_nonneg A B\n rw [div_self (by positivity)]\n simp\n have hAx_eq : Ax = A := by\n apply Set.Finite.eq_of_subset_of_card_le A.toFinite hAxA\n linarith only [h, Nat.card_mono B.toFinite hByB]\n have hBy_eq : By = B := by\n apply Set.Finite.eq_of_subset_of_card_le B.toFinite hByB\n linarith only [h, Nat.card_mono A.toFinite hAxA]\n have hN : N = ⊤ := by\n have : (A-A) ∪ (B-B) ⊆ N := by\n rw [← hAx_eq, ← hBy_eq, hAx, hBy]\n intro z hz\n simp [Set.mem_sub] at hz\n convert (QuotientAddGroup.eq_zero_iff z).mp ?_\n . infer_instance\n rcases hz with ⟨ a, ⟨ -, ha⟩, a', ⟨-, ha'⟩, haa' ⟩ | ⟨ b, ⟨ -, hb⟩, b', ⟨ -,hb'⟩, hbb' ⟩\n . rw [← haa']; simp [ha, ha']\n rw [← hbb']; simp [hb, hb']\n rw [← AddSubgroup.closure_le, hnot] at this\n exact top_le_iff.mp this\n have : Nat.card (G ⧸ N) = 1 := by\n rw [Nat.card_eq_one_iff_unique]\n constructor\n . rw [hN]\n exact QuotientAddGroup.subsingleton_quotient_top\n infer_instance\n simp [this] at hdim\n rw [← le_div_iff' (by positivity)] at hdim\n convert LE.le.trans ?_ hdim using 1\n . field_simp\n simp\n exact ⟨ dimension_le_rank A, dimension_le_rank B ⟩",
"proofType": "tactic",
"proofLengthLines": 110,
"proofLengthTokens": 6393
} | pfr |
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Quotient
import Mathlib.GroupTheory.Torsion
import Mathlib.GroupTheory.Torsion
import Mathlib.LinearAlgebra.FreeModule.PID
import PFR.Mathlib.Data.Set.Pointwise.SMul
import PFR.EntropyPFR
import PFR.ImprovedPFR
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Mathlib.GroupTheory.Torsion
/-!
# Weak PFR over the integers
Here we use the entropic form of PFR to deduce a weak form of PFR over the integers.
## Main statement
* `weak_PFR_int`: Let $A\subseteq \mathbb{Z}^d$ and $\lvert A+A\rvert\leq K\lvert A\rvert$.
There exists $A'\subseteq A$ such that $\lvert A'\rvert \geq K^{-17}\lvert A\rvert$ and
$\dim A' \leq (40/\log 2)\log K$.
-/
section AddCommGroup
variable {G : Type*} [AddCommGroup G] {A B : Set G}
open Set
open scoped Pointwise
def IsShift (A B : Set G) : Prop := ∃ x : G, A = x +ᵥ B
lemma IsShift.sub_self_congr : IsShift A B → A - A = B - B := by
rintro ⟨x, rfl⟩; simp [vadd_sub_vadd_comm, singleton_zero]
lemma IsShift.card_congr : IsShift A B → Nat.card A = Nat.card B := by rintro ⟨x, rfl⟩; simp
/-- The property of two sets A, B of a group G not being contained in cosets of the same proper
subgroup -/
def NotInCoset (A B : Set G) : Prop := AddSubgroup.closure ((A - A) ∪ (B - B)) = ⊤
/-- Without loss of generality, one can move (up to translation and embedding) any pair A, B of non-empty sets into a subgroup where they are not in a coset. -/
lemma wlog_notInCoset (hA : A.Nonempty) (hB : B.Nonempty) :
∃ (G' : AddSubgroup G) (A' B' : Set G'), IsShift A A' ∧ IsShift B B' ∧ NotInCoset A' B' := by
obtain ⟨x, hx⟩ := hA
obtain ⟨y, hy⟩ := hB
set G' := AddSubgroup.closure ((A - A) ∪ (B - B))
set A' : Set G' := (↑) ⁻¹' ((-x) +ᵥ A)
set B' : Set G' := (↑) ⁻¹' ((-y) +ᵥ B)
have hxA : -x +ᵥ A ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hx).trans $ (subset_union_left ..).trans
AddSubgroup.subset_closure
have hyB : -y +ᵥ B ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hy).trans $ (subset_union_right ..).trans
AddSubgroup.subset_closure
have hA : IsShift A A' := ⟨x, by rw [Set.image_preimage_eq_of_subset hxA, vadd_neg_vadd]⟩
have hB : IsShift B B' := ⟨y, by rw [Set.image_preimage_eq_of_subset hyB, vadd_neg_vadd]⟩
refine ⟨G', A', B', hA, hB, ?_⟩
unfold NotInCoset
convert AddSubgroup.closure_preimage_eq_top ((A - A) ∪ (B - B))
simp_rw [preimage_union, hA.sub_self_congr, hB.sub_self_congr]
rw [preimage_sub, preimage_sub]
simp [A', B', preimage_image_preimage]
all_goals apply_rules [Subtype.coe_injective, (image_preimage_subset ..).trans, hxA, hyB]
end AddCommGroup
section Torsion
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [MeasurableSpace G] [MeasurableSingletonClass G]
[Countable G] {Ω Ω' : Type u} [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ': Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
/-- If $G$ is torsion-free and $X,Y$ are $G$-valued random variables then $d[X;2Y]\leq 5d[X;Y]$. -/
lemma torsion_free_doubling [FiniteRange X] [FiniteRange Y]
(hX : Measurable X) (hY : Measurable Y) (hG : AddMonoid.IsTorsionFree G) :
d[X ; μ # (Y + Y) ; μ'] ≤ 5 * d[X; μ # Y ; μ'] := by
obtain ⟨A, mA, μA, X', Y'₁, Y'₂, hμA, h_indep, hX'_meas, hY'₁_meas, hY'₂_meas, hX'_ident,
hY'₁_ident, hY'₂_ident, _, _, _⟩ := independent_copies3_nondep_finiteRange hX hY hY μ μ' μ'
have h_meas (i : Fin 3) : Measurable (![X', Y'₁, Y'₂] i) := by fin_cases i <;> assumption
haveI : NoZeroSMulDivisors ℕ G := hG.noZeroNsmulDivisors
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨x, y₁, y₂⟩ ↦ (x, y₁ - y₂, x - 2 • y₁)
show H[f ∘ ⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] = _
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hX'_meas <| Measurable.prod hY'₁_meas hY'₂_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun X' (prod Y'₁ Y'₂) μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 1 2 0 (by decide) (by decide)
rw [this.entropy_pair_eq_add hX'_meas (by exact Measurable.prod hY'₁_meas hY'₂_meas),
IndepFun.entropy_pair_eq_add hY'₁_meas hY'₂_meas (h_indep.indepFun (show 1 ≠ 2 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, two_mul]
have : H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[X ; μ] + H[Y ; μ'] := calc
H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[⟨X', Y'₁⟩ ; μA] := by
let f : G × G → G × G := fun ⟨x, y₁⟩ ↦ (x, x - 2 • y₁)
show H[f ∘ ⟨X', Y'₁⟩ ; μA] = _
apply entropy_comp_of_injective μA (by exact Measurable.prod hX'_meas hY'₁_meas) f
exact fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + H[Y ; μ'] := by
rw [IndepFun.entropy_pair_eq_add hX'_meas hY'₁_meas (h_indep.indepFun (show 0 ≠ 1 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq]
let f : G × G → G × G := fun ⟨x, y⟩ ↦ (x, y - x)
have hf : f.Injective := fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all
have : H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] := calc
H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] = H[f ∘ ⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
show _ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂ - (Y'₁ - Y'₂)⟩ ; μA]
rw [sub_sub_sub_cancel_right, ← sub_add_eq_sub_sub, two_nsmul]
_ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
refine entropy_comp_of_injective μA (Measurable.prod ?_ ?_) f hf
· exact Measurable.sub hY'₁_meas hY'₂_meas
· exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
_ ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] :=
entropy_pair_le_add (hY'₁_meas.sub' hY'₂_meas) (hX'_meas.sub' hY'₁_meas |>.sub' hY'₂_meas) μA
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] + H[X' - 2 • Y'₁ ; μA] ≤
H[⟨X', X' - 2 • Y'₁⟩ ; μA] + H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] := by
haveI : FiniteRange (Y'₁ - Y'₂) := FiniteRange.sub Y'₁ Y'₂
haveI : FiniteRange (2 • Y'₁) := by show FiniteRange ((fun x ↦ 2 • x) ∘ Y'₁); infer_instance
apply entropy_triple_add_entropy_le μA hX'_meas (Measurable.sub hY'₁_meas hY'₂_meas)
exact Measurable.sub' hX'_meas <| Measurable.const_smul hY'₁_meas 2
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨y₁, y₂, x⟩ ↦ (y₁, y₂, x - y₁ - y₂)
show H[f ∘ ⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA]
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hY'₁_meas <| Measurable.prod hY'₂_meas hX'_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun Y'₁ (prod Y'₂ X') μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 2 0 1 (by decide) (by decide)
rw [this.entropy_pair_eq_add hY'₁_meas (by exact Measurable.prod hY'₂_meas hX'_meas),
IndepFun.entropy_pair_eq_add hY'₂_meas hX'_meas (h_indep.indepFun (show 2 ≠ 0 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq]
group
have : H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₂ ; μA] := calc
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₁, X' - Y'₂⟩ ; μA] := by rw [sub_right_comm] ; rfl
_ = H[⟨Y'₁, X' - Y'₂⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₁_meas <| Measurable.sub hX'_meas hY'₂_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₂ ; μA] := by
haveI : FiniteRange (X' - Y'₂) := FiniteRange.sub X' Y'₂
convert IndepFun.entropy_pair_eq_add hY'₁_meas (hX'_meas.sub hY'₂_meas)
<| h_indep.indepFun_sub_right h_meas 1 0 2 (by decide) (by decide)
exact hY'₁_ident.entropy_eq.symm
have : H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₁ ; μA] := calc
H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₂, X' - Y'₁⟩ ; μA] := rfl
_ = H[⟨Y'₂, X' - Y'₁⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₂_meas <| Measurable.sub hX'_meas hY'₁_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₁ ; μA] := by
haveI : FiniteRange (X' - Y'₁) := FiniteRange.sub X' Y'₁
convert IndepFun.entropy_pair_eq_add hY'₂_meas (hX'_meas.sub hY'₁_meas)
<| h_indep.indepFun_sub_right h_meas 2 0 1 (by decide) (by decide)
exact hY'₂_ident.entropy_eq.symm
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] ≤
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] + H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
apply entropy_triple_add_entropy_le μA hY'₁_meas hY'₂_meas
exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
have : H[X' - Y'₁ - Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := calc
H[X' - Y'₁ - Y'₂ ; μA] ≤ H[X' - Y'₁ ; μA] + H[X' - Y'₂ ; μA] - H[X ; μ] := by linarith
_ = 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := by
nth_rw 1 [two_mul, ← hX'_ident.rdist_eq hY'₁_ident, ← hX'_ident.rdist_eq hY'₂_ident]
have h1 : d[X' ; μA # Y'₁ ; μA] = H[X' - Y'₁ ; μA] - H[X' ; μA] / 2 - H[Y'₁ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 1 by decide)).rdist_eq hX'_meas hY'₁_meas
have h2 : d[X' ; μA # Y'₂ ; μA] = H[X' - Y'₂ ; μA] - H[X' ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 2 by decide)).rdist_eq hX'_meas hY'₂_meas
rw [h1, h2, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, hX'_ident.entropy_eq]
group
have : d[X ; μ # 2 • Y ; μ'] ≤
d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := calc
d[X ; μ # 2 • Y ; μ'] = H[X' - 2 • Y'₁ ; μA] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by
have h2Y_ident : IdentDistrib (2 • Y'₁) (2 • Y) (μ := μA) (ν := μ') := by
convert hY'₁_ident.comp <| measurable_discrete <| fun g ↦ 2 • g
have h2Y_indep : IndepFun X' (2 • Y'₁) (μ := μA) := by
convert (h_indep.indepFun (show 0 ≠ 1 by decide)).comp measurable_id
(measurable_const_smul 2)
rw [← hX'_ident.rdist_eq h2Y_ident,
h2Y_indep.rdist_eq hX'_meas <| Measurable.const_smul hY'₁_meas 2,
hX'_ident.entropy_eq, h2Y_ident.entropy_eq]
_ ≤ H[Y'₁ - Y'₂ ; μA] + 2 * d[X ; μ # Y ; μ'] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by linarith
_ = d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := by
have H2Y : H[2 • Y ; μ'] = H[Y ; μ'] := by
let f (g : G) := 2 • g
exact entropy_comp_of_injective μ' hY f (fun _ _ ↦ by simp [f, smul_right_inj])
have : d[Y'₁ ; μA # Y'₂ ; μA] = H[Y'₁ - Y'₂ ; μA] - H[Y'₁ ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 1 ≠ 2 by decide)).rdist_eq hY'₁_meas hY'₂_meas
rw [this, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, H2Y]
group
have : d[Y'₁ ; μA # Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] := by
rw [two_mul]
convert rdist_triangle hY'₁_meas hX'_meas hY'₂_meas (μ := μA) (μ' := μA) (μ'' := μA)
· exact rdist_symm.trans (hY'₁_ident.rdist_eq hX'_ident).symm
· exact (hX'_ident.rdist_eq hY'₂_ident).symm
rw [← two_nsmul]
linarith [abs_le.mp <| diff_ent_le_rdist hX hY (μ := μ) (μ' := μ')]
/-- If $G$ is a torsion-free group and $X,Y$ are $G$-valued random variables and
$\phi : G\to \mathbb{F}_2^d$ is a homomorphism then
\[\mathbb{H}(\phi(X))\leq 10d[X;Y].\] -/
lemma torsion_dist_shrinking {H : Type u} [FiniteRange X] [FiniteRange Y] (hX : Measurable X)
(hY : Measurable Y) [AddCommGroup H] [ElementaryAddCommGroup H 2]
[MeasurableSpace H] [MeasurableSingletonClass H] [Countable H]
(hG : AddMonoid.IsTorsionFree G) (φ : G →+ H) :
H[φ ∘ X ; μ] ≤ 10 * d[X; μ # Y ; μ'] := by
have :=
calc d[φ ∘ X ; μ # φ ∘ (Y + Y); μ'] ≤ d[X; μ # (Y + Y) ; μ'] := rdist_of_hom_le φ hX (Measurable.add hY hY)
_ ≤ 5 * d[X; μ # Y ; μ'] := torsion_free_doubling X Y μ μ' hX hY hG
have eq_zero : φ ∘ (Y + Y) = fun _ ↦ 0 := by ext x ; simp only [Function.comp_apply, Pi.add_apply,
map_add, ElementaryAddCommGroup.add_self]
rwa [eq_zero, rdist_zero_eq_half_ent, div_le_iff zero_lt_two, mul_assoc, mul_comm _ 2, ←mul_assoc,
show (5*2 : ℝ) = 10 by norm_num] at this
end Torsion
instance {G : Type u} [AddCommGroup G] [Fintype G] [MeasurableSpace G] [MeasurableSingletonClass G] (H : AddSubgroup G)
: MeasurableSingletonClass (G ⧸ H) :=
⟨λ _ ↦ by { rw [measurableSet_quotient]; simp [measurableSet_discrete] }⟩
section F2_projection
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [ElementaryAddCommGroup G 2] [Fintype G] [MeasurableSpace G]
[MeasurableSingletonClass G] {Ω Ω' : Type*}
/-- Let $G=\mathbb{F}_2^n$ and $X,Y$ be $G$-valued random variables such that
\[\mathbb{H}(X)+\mathbb{H}(Y)> (20/\alpha) d[X;Y],\]
for some $\alpha > 0$.
There is a non-trivial subgroup $H\leq G$ such that
\[\log \lvert H\rvert <(1+\alpha)/2 (\mathbb{H}(X)+\mathbb{H}(Y))\] and
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))< \alpha (\mathbb{H}(X)+\mathbb{H}(Y))\]
where $\psi:G\to G/H$ is the natural projection homomorphism.
-/
lemma app_ent_PFR' [MeasureSpace Ω] [MeasureSpace Ω'] (X : Ω → G) (Y : Ω' → G)
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
{α : ℝ} (hent : 20 * d[X # Y] < α * (H[X] + H[Y])) (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X] + H[Y]) ∧
H[(QuotientAddGroup.mk' H) ∘ X] + H[(QuotientAddGroup.mk' H) ∘ Y] < α * (H[X] + H[Y]) := by
let p : refPackage Ω Ω' G := {
X₀₁ := X
X₀₂ := Y
hmeas1 := hX
hmeas2 := hY
η := 1/8
hη := by norm_num
hη' := by norm_num }
obtain ⟨H, Ω'', hΩ'', U, _, hUmeas, hUunif, ineq⟩ := entropic_PFR_conjecture_improv p rfl
let ψ := (QuotientAddGroup.mk' H)
use H
haveI : Finite H := Subtype.finite
-- Note that H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y]
have ent_le : H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y] := calc
H[ψ ∘ X] + H[ψ ∘ Y] ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· exact ent_of_proj_le hX hUmeas hUunif
· exact ent_of_proj_le hY hUmeas hUunif
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- Note that (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y]
have log_sub_le : (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y] := calc
(log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) =
(H[U] - H[X]) + (H[U] - H[Y]) := by
rw [IsUniform.entropy_eq' hUunif hUmeas, SetLike.coe_sort_coe]
_ ≤ |(H[U] - H[X])| + |(H[U] - H[Y])| := by gcongr <;> exact le_abs_self _
_ ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hX
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hY
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- then the conclusion follows from the assumption `hent` and basic inequality manipulations
exact ⟨by linarith, by linarith⟩
variable [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ' : Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
lemma app_ent_PFR (α : ℝ) (hent: 20 * d[X;μ # Y;μ'] < α * (H[X; μ] + H[Y; μ'])) (hX : Measurable X)
(hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ']
< α * (H[ X; μ] + H[Y; μ']) :=
@app_ent_PFR' _ _ _ _ _ _ _ _ (MeasureSpace.mk μ) (MeasureSpace.mk μ') _ _ _ _ α hent hX hY
set_option maxHeartbeats 300000 in
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables and $\alpha < 1$ then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq (1 + α) / (2 * (1 - α)) * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 20/\alpha * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection'
(α : ℝ) (hX : Measurable X) (hY : Measurable Y) (αpos : 0 < α) (αone : α < 1) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (H[X ; μ] + H[Y ; μ']) ∧
α * (H[(QuotientAddGroup.mk' H) ∘ X ; μ] + H[(QuotientAddGroup.mk' H) ∘ Y ; μ']) ≤
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] := by
let S := { H : AddSubgroup G | (∃ (c : ℝ), 0 ≤ c ∧
log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (1 - c) * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
c * (H[X; μ] + H[Y;μ'])) ∧
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] <
α * (H[ (QuotientAddGroup.mk' H) ∘ X; μ ] + H[ (QuotientAddGroup.mk' H) ∘ Y; μ']) }
have : 0 ≤ H[X ; μ] + H[Y ; μ'] := by linarith [entropy_nonneg X μ, entropy_nonneg Y μ']
have : 0 < 1 - α := sub_pos.mpr αone
by_cases hE : (⊥ : AddSubgroup G) ∈ S
· classical
obtain ⟨H, ⟨⟨c, hc, hlog, hup⟩, hent⟩, hMaxl⟩ :=
S.toFinite.exists_maximal_wrt id S (Set.nonempty_of_mem hE)
set ψ : G →+ G ⧸ H := QuotientAddGroup.mk' H
have surj : Function.Surjective ψ := QuotientAddGroup.mk'_surjective H
set G' := G ⧸ H
have : ElementaryAddCommGroup G' 2 := ElementaryAddCommGroup.quotient_group (by decide)
(by simp [AddSubgroup.zero_mem])
obtain ⟨H', hlog', hup'⟩ := app_ent_PFR _ _ _ _ α hent ((measurable_discrete _).comp hX)
((measurable_discrete _).comp hY)
have H_ne_bot: H' ≠ ⊥ := by
by_contra!
rcases this with rfl
have inj : Function.Injective (QuotientAddGroup.mk' (⊥ : AddSubgroup G')) :=
(QuotientAddGroup.quotientBot : (G' ⧸ ⊥) ≃+ G').symm.injective
rw [entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ inj,
entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ inj] at hup'
nlinarith [entropy_nonneg (ψ ∘ X) μ, entropy_nonneg (ψ ∘ Y) μ']
let H'' := H'.comap ψ
use H''
rw [← (AddSubgroup.map_comap_eq_self_of_surjective surj _ : H''.map ψ = H')] at hup' hlog'
set H' := H''.map ψ
have Hlt : H < H'' := by
have : H = (⊥ : AddSubgroup G').comap ψ := by
simp only [ψ, AddMonoidHom.comap_bot, QuotientAddGroup.ker_mk']
rw [this, AddSubgroup.comap_lt_comap_of_surjective surj]
exact Ne.bot_lt H_ne_bot
let φ : G' ⧸ H' ≃+ G ⧸ H'' := QuotientAddGroup.quotientQuotientEquivQuotient H H'' Hlt.le
set ψ' : G' →+ G' ⧸ H' := QuotientAddGroup.mk' H'
set ψ'' : G →+ G ⧸ H'' := QuotientAddGroup.mk' H''
have diag : ψ' ∘ ψ = φ.symm ∘ ψ'' := rfl
rw [← Function.comp.assoc, ← Function.comp.assoc, diag, Function.comp.assoc,
Function.comp.assoc] at hup'
have cond : log (Nat.card H'') ≤
(1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := by
have cardprod : Nat.card H'' = Nat.card H' * Nat.card H := by
have hcard₀ := Nat.card_congr <| (AddSubgroup.addSubgroupOfEquivOfLe Hlt.le).toEquiv
have hcard₁ := Nat.card_congr <|
(QuotientAddGroup.quotientKerEquivRange (ψ.restrict H'')).toEquiv
have hcard₂ := AddSubgroup.card_eq_card_quotient_mul_card_addSubgroup (H.addSubgroupOf H'')
rw [ψ.ker_restrict H'', QuotientAddGroup.ker_mk', ψ.restrict_range H''] at hcard₁
simpa only [← Nat.card_eq_fintype_card, hcard₀, hcard₁] using hcard₂
calc
log (Nat.card H'')
_ = log ((Nat.card H' : ℝ) * (Nat.card H : ℝ)) := by rw [cardprod]; norm_cast
_ = log (Nat.card H') + log (Nat.card H) := by
rw [Real.log_mul (Nat.cast_ne_zero.2 (@Nat.card_pos H').ne')
(Nat.cast_ne_zero.2 (@Nat.card_pos H).ne')]
_ ≤ (1 + α) / 2 * (H[⇑ψ ∘ X ; μ] + H[⇑ψ ∘ Y ; μ']) + log (Nat.card H) := by gcongr
_ ≤ (1 + α) / 2 * (c * (H[X; μ] + H[Y;μ'])) +
(1 + α) / (2 * (1 - α)) * (1 - c) * (H[X ; μ] + H[Y ; μ']) := by gcongr
_ = (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X ; μ] + H[Y ; μ']) := by
field_simp; ring
have HS : H'' ∉ S := λ Hs => Hlt.ne (hMaxl H'' Hs Hlt.le)
simp only [S, Set.mem_setOf_eq, not_and, not_lt] at HS
refine ⟨?_, HS ⟨α * c, by positivity, cond, ?_⟩⟩
· calc
log (Nat.card H'')
_ ≤ (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := cond
_ ≤ (1 + α) / (2 * (1 - α)) * 1 * (H[X; μ] + H[Y;μ']) := by gcongr; simp; positivity
_ = (1 + α) / (2 * (1 - α)) * (H[X; μ] + H[Y;μ']) := by simp only [mul_one]
· calc
H[ ψ'' ∘ X; μ ] + H[ ψ'' ∘ Y; μ' ]
_ = H[ φ.symm ∘ ψ'' ∘ X; μ ] + H[ φ.symm ∘ ψ'' ∘ Y; μ' ] := by
simp_rw [← entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ φ.symm.injective,
← entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ φ.symm.injective]
_ ≤ α * (H[ ψ ∘ X; μ ] + H[ ψ ∘ Y; μ' ]) := hup'.le
_ ≤ α * (c * (H[X ; μ] + H[Y ; μ'])) := by gcongr
_ = (α * c) * (H[X ; μ] + H[Y ; μ']) := by ring
· use ⊥
constructor
· simp only [AddSubgroup.mem_bot, Nat.card_eq_fintype_card, Fintype.card_ofSubsingleton,
Nat.cast_one, log_one]
positivity
· simp only [S, Set.mem_setOf_eq, not_and, not_lt] at hE
exact hE ⟨1, by norm_num, by
norm_num; exact add_le_add (entropy_comp_le μ hX _) (entropy_comp_le μ' hY _)⟩
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq 2 * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 34 * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
34 * d[(QuotientAddGroup.mk' H) ∘ X;μ # (QuotientAddGroup.mk' H) ∘ Y;μ'] := by
rcases PFR_projection' X Y μ μ' ((3 : ℝ) / 5) hX hY (by norm_num) (by norm_num) with ⟨H, h, h'⟩
refine ⟨H, ?_, ?_⟩
· convert h
norm_num
· have : 0 ≤ d[⇑(QuotientAddGroup.mk' H) ∘ X ; μ # ⇑(QuotientAddGroup.mk' H) ∘ Y ; μ'] :=
rdist_nonneg ((measurable_discrete _).comp hX) ((measurable_discrete _).comp hY)
linarith
end F2_projection
open MeasureTheory ProbabilityTheory Real Set
open scoped BigOperators
lemma four_logs {a b c d : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) (hd : 0 < d) :
log ((a*b)/(c*d)) = log a + log b - log c - log d := by
rw [log_div, log_mul, log_mul, sub_sub] <;> positivity
lemma sum_prob_preimage {G H : Type*} {X : Finset H} {A : Set G} [Finite A] {φ : A → X}
{A_ : H → Set G} (hA : A.Nonempty) (hφ : ∀ x : X, A_ x = Subtype.val '' (φ ⁻¹' {x})) :
∑ x in X, (Nat.card (A_ x) : ℝ) / (Nat.card A) = 1 := by
rw [← Finset.sum_div]
apply (div_eq_one_iff_eq <| Nat.cast_ne_zero.mpr <| Nat.pos_iff_ne_zero.mp (@Nat.card_pos _ hA.to_subtype _)).mpr
classical
haveI := Fintype.ofFinite A
rewrite [Nat.card_eq_fintype_card, ← Finset.card_univ, Finset.card_eq_sum_card_fiberwise
<| fun a _ ↦ Finset.mem_univ (φ a), ← Finset.sum_coe_sort]
norm_cast
congr; ext
rewrite [← Set.Finite.toFinset_setOf, (Set.toFinite _).card_toFinset, ← Nat.card_eq_fintype_card,
hφ, Nat.card_image_of_injective Subtype.val_injective]; rfl
/-- Let $\phi : G\to H$ be a homomorphism and $A,B\subseteq G$ be finite subsets. If $x,y\in H$ then let $A_x=A\cap \phi^{-1}(x)$ and $B_y=B\cap \phi^{-1}(y)$. There exist $x,y\in H$ such that $A_x,B_y$ are both non-empty and
\[d[\phi(U_A);\phi(U_B)]\log \frac{\lvert A\rvert\lvert B\rvert}{\lvert A_x\rvert\lvert B_y\rvert}\leq (\mathbb{H}(\phi(U_A))+\mathbb{H}(\phi(U_B)))(d(U_A,U_B)-d(U_{A_x},U_{B_y}).\] -/
lemma single_fibres {G H Ω Ω': Type u}
[AddCommGroup G] [Countable G] [MeasurableSpace G] [MeasurableSingletonClass G]
[AddCommGroup H] [Countable H] [MeasurableSpace H] [MeasurableSingletonClass H]
[MeasureSpace Ω] [MeasureSpace Ω']
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
(φ : G →+ H)
{A B : Set G} [Finite A] [Finite B] {UA : Ω → G} {UB: Ω' → G} (hA : A.Nonempty) (hB : B.Nonempty)
(hUA': Measurable UA) (hUB': Measurable UB) (hUA: IsUniform A UA) (hUB: IsUniform B UB)
(hUA_mem : ∀ ω, UA ω ∈ A) (hUB_mem : ∀ ω, UB ω ∈ B) :
∃ (x y : H) (Ax By: Set G),
Ax = A ∩ φ.toFun ⁻¹' {x} ∧ By = B ∩ φ.toFun ⁻¹' {y} ∧ Ax.Nonempty ∧ By.Nonempty ∧
d[φ.toFun ∘ UA # φ.toFun ∘ UB]
* log ((Nat.card A) * (Nat.card B) / ((Nat.card Ax) * (Nat.card By))) ≤
(H[φ.toFun ∘ UA] + H[φ.toFun ∘ UB]) * (d[UA # UB] - dᵤ[Ax # By]) := by
have : Nonempty A := hA.to_subtype
have : Nonempty B := hB.to_subtype
haveI : FiniteRange UA := finiteRange_of_finset UA A.toFinite.toFinset (by simpa)
haveI : FiniteRange UB := finiteRange_of_finset UB B.toFinite.toFinset (by simpa)
have hUA_coe : IsUniform A.toFinite.toFinset.toSet UA := by rwa [Set.Finite.coe_toFinset]
have hUB_coe : IsUniform B.toFinite.toFinset.toSet UB := by rwa [Set.Finite.coe_toFinset]
let A_ (x : H) : Set G := A ∩ φ.toFun ⁻¹' {x}
let B_ (y : H) : Set G := B ∩ φ.toFun ⁻¹' {y}
let X : Finset H := FiniteRange.toFinset (φ.toFun ∘ UA)
let Y : Finset H := FiniteRange.toFinset (φ.toFun ∘ UB)
haveI h_Ax (x : X) : Nonempty (A_ x.val) := by
obtain ⟨ω, hω⟩ := (FiniteRange.mem_iff _ _).mp x.property
use UA ω; exact Set.mem_inter (hUA_mem ω) (by exact hω)
haveI h_By (y : Y) : Nonempty (B_ y.val) := by
obtain ⟨ω, hω⟩ := (FiniteRange.mem_iff _ _).mp y.property
use UB ω; exact Set.mem_inter (hUB_mem ω) (by exact hω)
have h_AX (a : A) : φ.toFun a.val ∈ X := by
obtain ⟨ω, hω⟩ := hUA_coe.nonempty_preimage_of_mem hUA' (A.toFinite.mem_toFinset.mpr a.property)
exact (FiniteRange.mem_iff _ (φ.toFun a.val)).mpr ⟨ω, congr_arg _ hω⟩
have h_BY (b : B) : φ.toFun b.val ∈ Y := by
obtain ⟨ω, hω⟩ := hUB_coe.nonempty_preimage_of_mem hUB' (B.toFinite.mem_toFinset.mpr b.property)
exact (FiniteRange.mem_iff _ (φ.toFun b.val)).mpr ⟨ω, congr_arg _ hω⟩
let φ_AX (a : A) : X := by use φ.toFun a.val; exact h_AX a
let φ_BY (b : B) : Y := by use φ.toFun b.val; exact h_BY b
have h_φ_AX (x : X) : A_ x.val = φ_AX ⁻¹' {x} := by ext; simp [A_, φ_AX]; simp [Subtype.ext_iff]
have h_φ_BY (y : Y) : B_ y.val = φ_BY ⁻¹' {y} := by ext; simp [B_, φ_BY]; simp [Subtype.ext_iff]
let p (x : H) (y : H) : ℝ :=
(Nat.card (A_ x).Elem) * (Nat.card (B_ y).Elem) / ((Nat.card A.Elem) * (Nat.card B.Elem))
have :
∑ x in X, ∑ y in Y, (p x y) * dᵤ[A_ x # B_ y] ≤ d[UA # UB] - d[φ.toFun ∘ UA # φ.toFun ∘ UB] :=
calc
_ = d[UA | φ.toFun ∘ UA # UB | φ.toFun ∘ UB] := by
rewrite [condRuzsaDist_eq_sum hUA' ((measurable_discrete _).comp hUA')
hUB' ((measurable_discrete _).comp hUB')]
refine Finset.sum_congr rfl <| fun x hx ↦ Finset.sum_congr rfl <| fun y hy ↦ ?_
haveI : Nonempty (A_ x) := h_Ax ⟨x, hx⟩
haveI : Nonempty (B_ y) := h_By ⟨y, hy⟩
let μx := (ℙ : Measure Ω)[|(φ.toFun ∘ UA) ⁻¹' {x}]
let μy := (ℙ : Measure Ω')[|(φ.toFun ∘ UB) ⁻¹' {y}]
have h_μ_p : IsProbabilityMeasure μx ∧ IsProbabilityMeasure μy := by
constructor <;> apply ProbabilityTheory.cond_isProbabilityMeasure <;> rw [Set.preimage_comp]
refine @IsUniform.measure_preimage_ne_zero _ _ _ _ _ _ _ _ _ _ hUA_coe hUA' _ ?_
swap; refine @IsUniform.measure_preimage_ne_zero _ _ _ _ _ _ _ _ _ _ hUB_coe hUB' _ ?_
all_goals rwa [Set.inter_comm, Set.Finite.coe_toFinset]
have h_μ_unif : IsUniform (A_ x) UA μx ∧ IsUniform (B_ y) UB μy := by
have : _ ∧ _ := ⟨hUA.restrict hUA' (φ.toFun ⁻¹' {x}), hUB.restrict hUB' (φ.toFun ⁻¹' {y})⟩
rwa [Set.inter_comm _ A, Set.inter_comm _ B] at this
rewrite [rdist_set_eq_rdist h_μ_p.1 h_μ_p.2 h_μ_unif.1 h_μ_unif.2 hUA' hUB']
show _ = (Measure.real _ (UA ⁻¹' (_ ⁻¹' _))) * (Measure.real _ (UB ⁻¹' (_ ⁻¹' _))) * _
rewrite [hUA_coe.measureReal_preimage hUA', hUB_coe.measureReal_preimage hUB']
simp_rw [p, A_, B_, IsProbabilityMeasure.measureReal_univ, one_mul]
rewrite [mul_div_mul_comm, Set.inter_comm A, Set.inter_comm B]
simp only [Set.Finite.coe_toFinset, Set.Finite.mem_toFinset, Finset.mem_val]; rfl
_ ≤ d[UA # UB] - d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
rewrite [ZeroHom.toFun_eq_coe, AddMonoidHom.toZeroHom_coe]
linarith only [rdist_le_sum_fibre φ hUA' hUB' (μ := ℙ) (μ' := ℙ)]
let M := H[φ.toFun ∘ UA] + H[φ.toFun ∘ UB]
have hM : M = ∑ x in X, ∑ y in Y, Real.negMulLog (p x y) := by
have h_compl {x y} (h_notin : (x, y) ∉ X ×ˢ Y) : Real.negMulLog (p x y) = 0 := by
unfold_let p; beta_reduce
rewrite [Finset.mem_product, not_and_or] at h_notin
suffices A_ x = ∅ ∨ B_ y = ∅ by obtain h | h := this <;> rw [h] <;> simp
refine h_notin.imp ?_ ?_
· rw [← not_nonempty_iff_eq_empty]
rintro h ⟨a, ha, rfl⟩
exact h (h_AX ⟨a, ha⟩)
· rw [← not_nonempty_iff_eq_empty]
rintro h ⟨a, ha, rfl⟩
exact h (h_BY ⟨a, ha⟩)
unfold_let M
unfold entropy
haveI := isProbabilityMeasure_map (μ := ℙ) ((measurable_discrete φ).comp hUA').aemeasurable
haveI := isProbabilityMeasure_map (μ := ℙ) ((measurable_discrete φ).comp hUB').aemeasurable
rewrite [← Finset.sum_product', ← tsum_eq_sum fun _ ↦ h_compl, ← measureEntropy_prod]
apply tsum_congr; intro; congr
rewrite [← Set.singleton_prod_singleton, Measure.smul_apply, Measure.prod_prod,
Measure.map_apply ((measurable_discrete _).comp hUA') (MeasurableSet.singleton _),
Measure.map_apply ((measurable_discrete _).comp hUB') (MeasurableSet.singleton _),
Set.preimage_comp, hUA_coe.measure_preimage hUA',
Set.preimage_comp, hUB_coe.measure_preimage hUB']
simp [p, A_, B_, mul_div_mul_comm, Set.inter_comm, ENNReal.toReal_div]
have h_sum : ∑ x in X, ∑ y in Y,
(p x y) * (M * dᵤ[A_ x # B_ y] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p x y)) ≤
M * d[UA # UB] :=
calc
_ = ∑ x in X, ∑ y in Y, (p x y) * M * dᵤ[A_ x # B_ y] + M * d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
simp_rw [hM, Finset.sum_mul, ← Finset.sum_add_distrib]
refine Finset.sum_congr rfl <| fun _ _ ↦ Finset.sum_congr rfl <| fun _ _ ↦ ?_
simp only [negMulLog, left_distrib, mul_assoc, Finset.sum_mul]
exact congrArg (HAdd.hAdd _) (by group)
_ = M * ∑ x in X, ∑ y in Y, (p x y) * dᵤ[A_ x # B_ y] + M * d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
simp_rw [Finset.mul_sum]
congr; ext; congr; ext; group
_ ≤ M * d[UA # UB] := by
rewrite [← left_distrib]
apply mul_le_mul_of_nonneg_left
· linarith
· unfold_let M
linarith only [entropy_nonneg (φ.toFun ∘ UA) ℙ, entropy_nonneg (φ.toFun ∘ UB) ℙ]
have : ∃ x : X, ∃ y : Y,
M * dᵤ[A_ x.val # B_ y.val] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p x.val y.val) ≤
M * d[UA # UB] := by
let f (xy : H × H) := (p xy.1 xy.2) * (M * d[UA # UB])
let g (xy : H × H) := (p xy.1 xy.2) *
(M * dᵤ[A_ xy.1 # B_ xy.2] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p xy.1 xy.2))
by_contra hc; push_neg at hc
replace hc : ∀ xy ∈ X ×ˢ Y, f xy < g xy := by
refine fun xy h ↦ mul_lt_mul_of_pos_left ?_ ?_
· exact hc ⟨xy.1, (Finset.mem_product.mp h).1⟩ ⟨xy.2, (Finset.mem_product.mp h).2⟩
· haveI : Nonempty _ := h_Ax ⟨xy.1, (Finset.mem_product.mp h).1⟩
haveI : Nonempty _ := h_By ⟨xy.2, (Finset.mem_product.mp h).2⟩
simp only [p, div_pos, mul_pos, Nat.cast_pos, Nat.card_pos]
have h_nonempty : Finset.Nonempty (X ×ˢ Y) := by
use ⟨φ.toFun <| UA <| Classical.choice <| ProbabilityMeasure.nonempty ⟨ℙ, inferInstance⟩,
φ.toFun <| UB <| Classical.choice <| ProbabilityMeasure.nonempty ⟨ℙ, inferInstance⟩⟩
exact Finset.mem_product.mpr ⟨FiniteRange.mem _ _, FiniteRange.mem _ _⟩
replace hc := Finset.sum_lt_sum_of_nonempty h_nonempty hc
have h_p_one : ∑ x in X ×ˢ Y, p x.1 x.2 = 1 := by
simp_rw [Finset.sum_product, p, mul_div_mul_comm, ← Finset.mul_sum,
← sum_prob_preimage hA h_φ_AX, sum_prob_preimage hB h_φ_BY, mul_one]
rewrite [← Finset.sum_mul, h_p_one, one_mul, Finset.sum_product] at hc
exact not_le_of_gt hc h_sum
obtain ⟨x, y, hxy⟩ := this
refine ⟨x, y, A_ x.val, B_ y.val, rfl, rfl, @nonempty_of_nonempty_subtype _ _ (h_Ax x), @nonempty_of_nonempty_subtype _ _ (h_By y), ?_⟩
rewrite [← inv_div, Real.log_inv]
show _ * -log (p x.val y.val) ≤ M * _
linarith only [hxy]
section dim
open Classical
variable {G : Type*} [AddCommGroup G]
/- If G ≅ ℤᵈ then there is a subgroup H of G such that A lies in a coset of H. This is helpful to
give the equivalent definition of `dimension`. Here this is stated in greated generality since the
proof carries over automatically-/
lemma exists_coset_cover (A : Set G) :
∃ (d : ℕ), ∃ (S : Submodule ℤ G) (v : G),
FiniteDimensional.finrank ℤ S = d ∧ ∀ a ∈ A, a - v ∈ S := by
existsi FiniteDimensional.finrank ℤ (⊤ : Submodule ℤ G), ⊤, 0
refine ⟨rfl, fun a _ ↦ trivial⟩
/-- The dimension of the affine span over `ℤ` of a subset of an additive group. -/
noncomputable def dimension (A : Set G) : ℕ := Nat.find (exists_coset_cover A)
lemma dimension_le_of_coset_cover (A : Set G) (S : Submodule ℤ G) (v : G)
(hA : ∀ a ∈ A, a - v ∈ S) : dimension A ≤ FiniteDimensional.finrank ℤ S := by
apply Nat.find_le
existsi S , v
exact ⟨rfl, hA⟩
lemma dimension_le_rank [Module.Finite ℤ G] (A : Set G) :
dimension A ≤ FiniteDimensional.finrank ℤ G := by
obtain ⟨S, v, hs, _⟩ := Nat.find_spec (exists_coset_cover A)
rw [dimension, ←hs]
apply Submodule.finrank_le S
end dim
variable {G : Type u} [AddCommGroup G] [Module.Free ℤ G] [Module.Finite ℤ G] [Countable G] [MeasurableSpace G] [MeasurableSingletonClass G]
open Real MeasureTheory ProbabilityTheory Pointwise Set
/-- Move to Mathlib? `Finsupp.mapRange` of a surjective function is surjective. -/
lemma Finsupp.mapRange_surjective {α : Type u_1} {M : Type u_5} {N : Type u_7} [Zero M] [Zero N] (f : M → N) (hf : f 0 = 0)
(hs : Function.Surjective f) : Function.Surjective (Finsupp.mapRange (α := α) f hf) := by
classical
let g (n : N) : M := if n = 0 then 0 else Function.surjInv hs n
have : Function.RightInverse g f := by
intro n
by_cases h : n = 0
. simp [g, h, hf]
· simp [g, h, Function.surjInv_eq hs n]
have hg : g 0 = 0 := by simp [g]
have hfg : (f ∘ g) 0 = 0 := by simp [hf, hg]
intro F
use Finsupp.mapRange g hg F
rw [← Finsupp.mapRange_comp (h := hfg)]
convert Finsupp.mapRange_id F
convert Function.RightInverse.id this
/-- A free Z-module is torsion-free. Move to Mathlib? -/
lemma torsion_free : AddMonoid.IsTorsionFree G := by
rintro x hx hn
rw [isOfFinAddOrder_iff_nsmul_eq_zero] at hn
rcases hn with ⟨ n, hn, hn' ⟩
apply_fun Module.Free.repr ℤ G at hn'
simp_rw [map_nsmul, map_zero, smul_eq_zero, AddEquivClass.map_eq_zero_iff, hx, or_false] at hn'
linarith
/-- If G is a rank n free Z-module, then G/2G is a finite elementary 2-group of cardinality 2^n. Code is slow, needs to be golfed -/
lemma weak_PFR_quotient_prelim :
let H := G ⧸ (AddMonoidHom.range (zsmulAddGroupHom 2))
ElementaryAddCommGroup H 2 ∧ Finite H ∧ Nat.card H = 2^(FiniteDimensional.finrank ℤ G) := by
set ψ : G →+ G := zsmulAddGroupHom 2
set G₂ := AddMonoidHom.range ψ
set H := G ⧸ G₂
set φ : G →+ H := QuotientAddGroup.mk' G₂
have hH_elem : ElementaryAddCommGroup H 2 := by
apply ElementaryAddCommGroup.quotient_group (by decide)
intro x; rw [AddMonoidHom.mem_range]
use x
rw [zsmulAddGroupHom_apply]
norm_cast
let B := Module.Free.ChooseBasisIndex ℤ G
let bG : Basis B ℤ G := Module.Free.chooseBasis ℤ G
have hB_fin : Fintype B := by infer_instance
have hB_card : Nat.card B = FiniteDimensional.finrank ℤ G := by
rw [FiniteDimensional.finrank_eq_card_basis bG, Nat.card_eq_fintype_card]
have hH_module : Module (ZMod 2) H := by infer_instance
let mod : (B →₀ ℤ) →+ (B →₀ ZMod 2) := Finsupp.mapRange.addMonoidHom (Int.castAddHom (ZMod 2))
let f : G →+ (B →₀ ℤ) := bG.repr
have hker : G₂ ≤ AddMonoidHom.ker (AddMonoidHom.comp mod f) := by
intro x hx
simp only [AddMonoidHom.mem_range, G₂, ψ, zsmulAddGroupHom_apply] at hx
simp_rw [AddMonoidHom.mem_ker, AddMonoidHom.coe_comp, Function.comp_apply, mod,
Finsupp.mapRange.addMonoidHom_apply, Int.coe_castAddHom]
rcases hx with ⟨y, rfl⟩
ext b
simp_rw [map_zsmul, Finsupp.mapRange_apply, Finsupp.coe_smul, Pi.smul_apply, smul_eq_mul,
Int.cast_mul, Int.cast_ofNat, Finsupp.coe_zero, Pi.zero_apply, mul_eq_zero]
left
exact ZMod.nat_cast_self 2
let g : H →+ (B →₀ ZMod 2) := QuotientAddGroup.lift G₂ (AddMonoidHom.comp mod f) hker
have hsur : Function.Surjective g := by
have h1 : Function.Surjective mod := Finsupp.mapRange_surjective (Int.castAddHom (ZMod 2)) (map_zero _) ZMod.int_cast_surjective
have h2 := h1.comp bG.repr.surjective
have h3 : mod ∘ bG.repr = g ∘ (QuotientAddGroup.mk' G₂) := by
ext x b
simp_rw [mod, Function.comp_apply, Finsupp.mapRange.addMonoidHom_apply, Int.coe_castAddHom,
Finsupp.mapRange_apply, QuotientAddGroup.coe_mk', g]
rw [QuotientAddGroup.lift_mk]
simp [mod, f]
rw [h3] at h2
apply Function.Surjective.of_comp h2
have hinj : Function.Injective g := by
rw [injective_iff_map_eq_zero]
intro x hx
rcases QuotientAddGroup.mk'_surjective G₂ x with ⟨y, rfl⟩
simp only [QuotientAddGroup.mk'_apply, g] at hx
rw [QuotientAddGroup.lift_mk] at hx
simp_rw [AddMonoidHom.coe_comp, Function.comp_apply, mod, Finsupp.mapRange.addMonoidHom_apply,
Int.coe_castAddHom, DFunLike.ext_iff,Finsupp.mapRange_apply, Finsupp.coe_zero, Pi.zero_apply,
ZMod.int_cast_zmod_eq_zero_iff_dvd] at hx
replace hx := fun x ↦ Int.mul_ediv_cancel' (hx x)
let z (b : B) := ((Module.Free.chooseBasis ℤ G).repr y) b / 2
let z' := (Finsupp.equivFunOnFinite).symm z
change ∀ b : B, 2 * z' b = (f y) b at hx
let x' := bG.repr.symm z'
rw [QuotientAddGroup.mk'_apply, QuotientAddGroup.eq_zero_iff, AddMonoidHom.mem_range]
simp_rw [ψ, zsmulAddGroupHom_apply]
use x'
change 2 • (bG.repr.symm.toLinearMap.toAddMonoidHom z') = y
rw [← AddMonoidHom.map_zsmul bG.repr.symm.toLinearMap.toAddMonoidHom z' (2 : ℤ)]
rw [← LinearEquiv.symm_apply_apply bG.repr y]
change bG.repr.symm (2 • z') = bG.repr.symm (f y)
congr
ext b
rw [Finsupp.smul_apply, ← hx b, smul_eq_mul]
rcases Function.bijective_iff_has_inverse.mp ⟨ hinj, hsur ⟩ with ⟨ g', hg' ⟩
have bH : Basis B (ZMod 2) H := by
constructor
exact {
toFun := g
invFun := g'
left_inv := hg'.1
right_inv := hg'.2
map_add' := AddMonoidHom.map_add _
map_smul' := by
intro r x
rcases ZMod.int_cast_surjective r with ⟨ n, rfl ⟩
change g ((n : ZMod 2) • x) = (n : ZMod 2) • g x
rw [intCast_smul, intCast_smul]
exact AddMonoidHom.map_zsmul g x n
}
have hH_fin : Fintype H := Module.fintypeOfFintype bH
have hH_card : Nat.card H = 2^(FiniteDimensional.finrank ℤ G) := by
rw [Nat.card_eq_fintype_card, Module.card_fintype bH, ← Nat.card_eq_fintype_card (α := B), hB_card]
congr
exact ⟨ hH_elem, Finite.of_fintype H, hH_card ⟩
open QuotientAddGroup
/-- A version of the third isomorphism theorem: if G₂ ≤ G and H' is a subgroup of G⧸G₂, then there is a canonical isomorphism between H⧸H' and G⧸N, where N is the preimage of H' in G. A bit clunky; may be a better way to do this -/
lemma third_iso {G : Type u} [AddCommGroup G] {G₂ : AddSubgroup G} (H' : AddSubgroup (G ⧸ G₂)) :
let H := G ⧸ G₂
let φ : G →+ H := mk' G₂
let N := AddSubgroup.comap φ H'
∃ e : H ⧸ H' ≃+ G ⧸ N, ∀ x : G, e (mk' H' (φ x))= mk' N x := by
set H := G ⧸ G₂
let φ : G →+ H := mk' G₂
let N := AddSubgroup.comap φ H'
have h1 : G₂ ≤ N := by
intro x hx
rw [← eq_zero_iff] at hx
have : φ x = 0 := hx
simp [N, this, AddSubgroup.zero_mem H']
set H'' := AddSubgroup.map (mk' G₂) N
have h2 : H' = H'' := by
change H' = AddSubgroup.map (mk' G₂) N
rw [AddSubgroup.map_comap_eq, AddMonoidHom.range_top_of_surjective _ (mk'_surjective G₂)]
simp
let e1 : H ⧸ H'' ≃+ G ⧸ N := quotientQuotientEquivQuotient _ _ h1
let e2 := quotientAddEquivOfEq h2
set e := e2.trans e1
use e
intro x
convert (quotientQuotientEquivQuotientAux_mk_mk _ _ h1 x) using 1
lemma single {Ω : Type u} [MeasurableSpace Ω] [DiscreteMeasurableSpace Ω] (μ : Measure Ω)
[IsProbabilityMeasure μ] {A : Set Ω} {z : Ω} (hA : μ.real A = 1) (hz : μ.real {z} > 0) :
z ∈ A := by
contrapose! hz
have : Disjoint {z} A := by simp [hz]
replace this := measureReal_union (μ := μ) this (measurableSet_discrete _)
simp [hA] at this
have h := measureReal_mono (μ := μ) (show insert z A ⊆ Set.univ by simp)
simp [this] at h
assumption
/-- Given two non-empty finite subsets A, B of a rank n free Z-module G, there exists a subgroup N and points x, y in G/N such that the fibers Ax, By of A, B over x, y respectively are non-empty, one has the inequality
$$ \log \frac{|A| |B|}{|A_x| |B_y|} ≤ 34 (d[U_A; U_B] - d[U_{A_x}; U_{B_y}])$$
and one has the dimension bound
$$ n \log 2 ≤ \log |G/N| + 40 d[U_A; U_B].$$
-/
lemma weak_PFR_asymm_prelim (A B : Set G) [Finite A] [Finite B] (hnA : A.Nonempty) (hnB : B.Nonempty):
∃ (N : AddSubgroup G) (x y : G ⧸ N) (Ax By : Set G), Ax.Nonempty ∧ By.Nonempty ∧
Set.Finite Ax ∧ Set.Finite By ∧ Ax = {z:G | z ∈ A ∧ QuotientAddGroup.mk' N z = x } ∧
By = {z:G | z ∈ B ∧ QuotientAddGroup.mk' N z = y } ∧
(log 2) * FiniteDimensional.finrank ℤ G ≤ log (Nat.card (G ⧸ N)) +
40 * dᵤ[ A # B ] ∧ log (Nat.card A) + log (Nat.card B) - log (Nat.card Ax) - log (Nat.card By)
≤ 34 * (dᵤ[ A # B ] - dᵤ[ Ax # By ]) := by
have : Nonempty A := hnA.to_subtype
have : Nonempty B := hnB.to_subtype
obtain ⟨ h_elem, h_finite, h_card ⟩ := weak_PFR_quotient_prelim (G := G)
set ψ : G →+ G := zsmulAddGroupHom 2
set G₂ := AddMonoidHom.range ψ
set H := G ⧸ G₂
let φ : G →+ H := QuotientAddGroup.mk' G₂
let _mH : MeasurableSpace H := ⊤
have h_fintype : Fintype H := Fintype.ofFinite H
have h_torsionfree := torsion_free (G := G)
obtain ⟨ Ω, mΩ, UA, hμ, hUA_mes, hUA_unif, hUA_mem, hUA_fin ⟩ := exists_isUniform_measureSpace' A
obtain ⟨ Ω', mΩ', UB, hμ', hUB_mes, hUB_unif, hUB_mem, hUB_fin ⟩ :=
exists_isUniform_measureSpace' B
rcases (PFR_projection (φ.toFun ∘ UA) (φ.toFun ∘ UB) ℙ ℙ (by measurability) (by measurability)) with ⟨H', ⟨ hH1, hH2 ⟩ ⟩
let N := AddSubgroup.comap φ H'
set φ' := QuotientAddGroup.mk' N
have _cGN : Countable (G ⧸ N) := Function.Surjective.countable (QuotientAddGroup.mk'_surjective N)
have _msGN : MeasurableSingletonClass (G ⧸ N) := by
constructor
intro x
exact MeasurableSpace.map_def.mpr (measurableSet_discrete _)
rcases third_iso H' with ⟨ e : H ⧸ H' ≃+ G ⧸ N, he ⟩
rcases single_fibres φ' hnA hnB hUA_mes hUB_mes hUA_unif hUB_unif hUA_mem hUB_mem with
⟨x, y, Ax, By, hAx, hBy, hnAx, hnBy, hcard_ineq⟩
have : Nonempty Ax := hnAx.to_subtype
have : Nonempty By := hnBy.to_subtype
have Axf : Finite Ax := by rw [hAx]; infer_instance
have Byf : Finite By := by rw [hBy]; infer_instance
have h1 := torsion_dist_shrinking UA UB ℙ ℙ hUA_mes hUB_mes h_torsionfree φ
have h2 := torsion_dist_shrinking UB UA ℙ ℙ hUB_mes hUA_mes h_torsionfree φ
rw [rdist_symm] at h2
rw [<- rdist_set_eq_rdist hμ hμ' hUA_unif hUB_unif hUA_mes hUB_mes] at h1 h2
-- using explicit .toFun casts as this saves a lot of heartbeats
change H[φ.toFun ∘ UA] ≤ 10 * dᵤ[A # B] at h1
change H[φ.toFun ∘ UB] ≤ 10 * dᵤ[A # B] at h2
replace hH1 : log (Nat.card H') ≤ 40 * dᵤ[A # B] := by
apply hH1.trans
linarith
replace h_card : log 2 * FiniteDimensional.finrank ℤ G ≤ log (Nat.card (G ⧸ N)) + 40 * dᵤ[A # B] := by
rw [mul_comm, ← log_rpow (by norm_num)]
norm_cast
classical
rwa [← h_card, ← Nat.card_congr e.toEquiv, Nat.card_eq_fintype_card, Nat.card_eq_fintype_card, ← AddSubgroup.index_mul_card H', AddSubgroup.index_eq_card, Nat.cast_mul, log_mul, add_le_add_iff_left, ← Nat.card_eq_fintype_card]
all_goals norm_cast; exact Fintype.card_ne_zero
use N, x, y, Ax, By
refine ⟨ hnAx, hnBy, Ax.toFinite, By.toFinite, hAx, hBy, h_card, ?_ ⟩
replace hH2 : H[φ'.toFun ∘ UA] + H[φ'.toFun ∘ UB] ≤ 34 * d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] := by
set X := ((mk' H').toFun ∘ φ.toFun) ∘ UA
set Y := ((mk' H').toFun ∘ φ.toFun) ∘ UB
have hX : Measurable X := Measurable.comp (measurable_discrete _) hUA_mes
have hY : Measurable Y := Measurable.comp (measurable_discrete _) hUB_mes
change H[X] + H[Y] ≤ 34 * d[X # Y] at hH2
have ha : φ'.toFun ∘ UA = e.toFun ∘ X := by ext x; exact (he (UA x)).symm
have hb : φ'.toFun ∘ UB = e.toFun ∘ Y := by ext x; exact (he (UB x)).symm
have he_inj : Function.Injective e.toFun := AddEquiv.injective e
rw [ha, hb, entropy_comp_of_injective _ hX _ he_inj, entropy_comp_of_injective _ hY _ he_inj]
have : d[e.toFun ∘ X # e.toFun ∘ Y] = d[X # Y] := rdist_of_inj hX hY e.toAddMonoidHom he_inj
rwa [this]
set X : Ω → G ⧸ N := φ'.toFun ∘ UA
set Y : Ω' → G ⧸ N := φ'.toFun ∘ UB
have hX : Measurable X := Measurable.comp (measurable_discrete _) hUA_mes
have hY : Measurable Y := Measurable.comp (measurable_discrete _) hUB_mes
rcases le_iff_lt_or_eq.mp (rdist_nonneg (μ := ℙ) (μ' := ℙ) hX hY) with h | h
swap
. rw [← h] at hH2
have hH2A : H[X] ≥ 0 := entropy_nonneg _ _
have hH2B : H[Y] ≥ 0 := entropy_nonneg _ _
have hH2A' : H[X] ≤ 0 := by linarith only [hH2, hH2A, hH2B]
have hH2B' : H[Y] ≤ 0 := by linarith only [hH2, hH2A, hH2B]
rcases const_of_nonpos_entropy (μ := ℙ) hX hH2A' with ⟨ x', hx ⟩
rcases const_of_nonpos_entropy (μ := ℙ) hY hH2B' with ⟨ y', hy ⟩
have hAAx {z : G} (hz : z ∈ A) : φ'.toFun z = x' := by
change (ℙ).real (UA⁻¹' (φ'⁻¹' {x'})) = 1 at hx
rw [← MeasureTheory.map_measureReal_apply hUA_mes (measurableSet_discrete _)] at hx
set Af := A.toFinite.toFinset
have hUAf : IsUniform Af UA := by
convert hUA_unif; simp only [Af, Set.Finite.coe_toFinset]
have hnAf : 0 < Nat.card Af := by simp only [Af, Set.Finite.mem_toFinset, Nat.card_pos]
have hzf : z ∈ Af := by simp [Af, Set.Finite.mem_toFinset, hz]
have : (Measure.map UA ℙ).real {z} > 0 := by
rw [IsUniform.measureReal_preimage_of_mem' hUAf hUA_mes hzf]
positivity
have _ : IsProbabilityMeasure ((ℙ).map UA) := by
exact MeasureTheory.isProbabilityMeasure_map (Measurable.aemeasurable hUA_mes)
replace this := single ((ℙ).map UA) hx this
rwa [Set.mem_preimage, Set.mem_singleton_iff] at this
have hxx : Ax = A := by
have h : hnAx.some ∈ Ax := hnAx.some_mem
simp [hAx] at h ⊢
have := hAAx h.1
simp [h.2] at this
intro z hz
simp [this]
convert hAAx hz
have hBBy {z : G} (hz : z ∈ B) : φ'.toFun z = y' := by
change (ℙ).real (UB⁻¹' (φ'⁻¹' {y'})) = 1 at hy
rw [← MeasureTheory.map_measureReal_apply hUB_mes (measurableSet_discrete _)] at hy
set Bf := B.toFinite.toFinset
have hUBf : IsUniform Bf UB := by convert hUB_unif; simp only [Bf, Set.Finite.coe_toFinset]
have hnBf : 0 < Nat.card Bf := by simp only [Bf, Set.Finite.mem_toFinset, Nat.card_pos]
have hzf : z ∈ Bf := by simp [Bf, Set.Finite.mem_toFinset, hz]
have : (Measure.map UB ℙ).real {z} > 0 := by
rw [IsUniform.measureReal_preimage_of_mem' hUBf hUB_mes hzf]
positivity
have _ : IsProbabilityMeasure ((ℙ).map UB) := by
exact MeasureTheory.isProbabilityMeasure_map (Measurable.aemeasurable hUB_mes)
replace this := single ((ℙ).map UB) hy this
rwa [Set.mem_preimage, Set.mem_singleton_iff] at this
have hyy : By = B := by
have h : hnBy.some ∈ By := hnBy.some_mem
simp [hBy] at h ⊢
have := hBBy h.1
simp [h.2] at this
intro z hz
simp [this]
convert hBBy hz
simp [hxx, hyy]
have := calc d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] * (log (Nat.card A) + log (Nat.card B) - log (Nat.card Ax) - log (Nat.card By))
_ = d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] * log ((Nat.card A) * (Nat.card B) / ((Nat.card Ax) * (Nat.card By))) := by
congr
convert (four_logs ?_ ?_ ?_ ?_).symm
all_goals norm_cast; exact Nat.card_pos
_ ≤ (H[φ'.toFun ∘ UA] + H[φ'.toFun ∘ UB]) * (d[UA # UB] - dᵤ[Ax # By]) := hcard_ineq
_ ≤ (34 * d[φ'.toFun ∘ UA # φ'.toFun ∘ UB]) * (d[UA # UB] - dᵤ[Ax # By]) := by
apply mul_le_mul_of_nonneg_right hH2
have := rdist_le_avg_ent (Measurable.comp (measurable_discrete φ'.toFun) hUA_mes) (Measurable.comp (measurable_discrete φ'.toFun) hUB_mes)
replace this : 0 < H[φ'.toFun ∘ UA] + H[φ'.toFun ∘ UB] := by linarith
rw [← mul_le_mul_left this]
apply le_trans _ hcard_ineq
rw [mul_zero]
change 0 ≤ d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] * log ((Nat.card A) * (Nat.card B) / ((Nat.card Ax) * (Nat.card By)))
rw [← mul_zero d[φ'.toFun ∘ UA # φ'.toFun ∘ UB], mul_le_mul_left h]
apply Real.log_nonneg
rw [one_le_div]
gcongr
. apply Nat.card_mono
. exact Set.toFinite A
rw [hAx]; exact Set.inter_subset_left _ _
apply Nat.card_mono
. exact Set.toFinite B
rw [hBy]; exact Set.inter_subset_left _ _
norm_cast
exact mul_pos Nat.card_pos Nat.card_pos
_ = d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] * (34 * (d[UA # UB] - dᵤ[Ax # By])) := by ring
_ = d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] * (34 * (dᵤ[A # B] - dᵤ[Ax # By])) := by
rw [<- rdist_set_eq_rdist hμ hμ' hUA_unif hUB_unif hUA_mes hUB_mes]
exact (mul_le_mul_left h).mp this
/-- Separating out the conclusion of `weak_PFR_asymm` for convenience of induction arguments.-/
def WeakPFRAsymmConclusion (A B : Set G) : Prop :=
∃ A' B' : Set G, A' ⊆ A ∧ B' ⊆ B ∧ A'.Nonempty ∧ B'.Nonempty ∧
log (((Nat.card A) * (Nat.card B)) / ((Nat.card A') * (Nat.card B'))) ≤ 34 * dᵤ[A # B] ∧
max (dimension A') (dimension B') ≤ (40 / log 2) * dᵤ[A # B]
/-- The property of two sets A,B of a group G not being contained in cosets of the same proper subgroup -/
def not_in_coset {G: Type u} [AddCommGroup G] (A B : Set G) : Prop := AddSubgroup.closure ((A-A) ∪ (B-B)) = ⊤
/-- In fact one has equality here, but this is tricker to prove and not needed for the argument. -/
lemma dimension_of_shift {G: Type u} [AddCommGroup G]
{H: AddSubgroup G} (A : Set H) (x : G) :
dimension ((fun a:H ↦ (a:G) + x) '' A) ≤ dimension A := by
classical
rcases Nat.find_spec (exists_coset_cover A) with ⟨ S, v, hrank, hshift ⟩
change FiniteDimensional.finrank ℤ S = dimension A at hrank
rw [← hrank]
convert dimension_le_of_coset_cover _ (Submodule.map H.subtype.toIntLinearMap S) (x+v) ?_
. apply LinearEquiv.finrank_eq
exact Submodule.equivMapOfInjective _ (by simpa using Subtype.val_injective) _
intro a ha
rw [Set.mem_image] at ha
rcases ha with ⟨ b, ⟨ hb, hb'⟩ ⟩
rw [Submodule.mem_map]
use b - v, hshift b hb
simp [← hb']
abel
lemma conclusion_transfers {A B : Set G}
(G': AddSubgroup G) (A' B' : Set G')
(hA : IsShift A A') (hB : IsShift B B') [Finite A'] [Finite B'] (hA' : A'.Nonempty) (hB' : B'.Nonempty)
(h : WeakPFRAsymmConclusion A' B') : WeakPFRAsymmConclusion A B := by
have : Nonempty A' := hA'.to_subtype
have : Nonempty B' := hB'.to_subtype
rcases h with ⟨A'', B'', hA'', hB'', hA''_non, hB''_non, hcard_ineq, hdim_ineq⟩
rcases hA with ⟨ x, hA ⟩
set f : G' → G := fun a ↦ (a : G) + x
have hf : Function.Injective f := by
intro y z hyz
simp [f] at hyz
exact hyz
have hA' : A = f '' A' := by
simp_rw [hA, ← Set.image_vadd, Set.image_image, vadd_eq_add, f, add_comm]; rfl
rcases hB with ⟨ y, hB ⟩
set g : G' → G := fun a ↦ (a : G) + y
have hg : Function.Injective g := by
intro y z hyz
simp [g] at hyz
exact hyz
have hB' : B = g '' B' := by
simp_rw [hB, ← Set.image_vadd, Set.image_image, vadd_eq_add, g, add_comm]; rfl
use f '' A'', g '' B''
have : dᵤ[A # B] = dᵤ[A' # B'] := by
rw [<-rdist_set_of_inj _ _ (φ := G'.subtype) Subtype.val_injective, <-rdist_set_add_const (G'.subtype '' A') (G'.subtype '' B') x y]
congr
. rw [hA]
ext y
simp [Set.mem_vadd_set]
constructor
. rintro ⟨ z, ⟨ ⟨ w, hw ⟩, rfl ⟩ ⟩
have : x + z + -x ∈ G' := by simp [w]
use this
simp
convert hw
rintro ⟨ h, ha ⟩
use y + -x
constructor
. use h
abel
rw [hB]
ext x
simp [Set.mem_vadd_set]
constructor
. rintro ⟨ z, ⟨ ⟨ w, hw ⟩, rfl ⟩ ⟩
have : y + z + -y ∈ G' := by simp [w]
use this
simp
convert hw
rintro ⟨ h, ha ⟩
use x + -y
constructor
. use h
abel
refine ⟨ ?_, ?_, ?_, ?_, ?_, ?_ ⟩
. simp [hA', hf, hA'']
. simp [hB', hg, hB'']
. simp [hA''_non]
. simp [hB''_non]
. convert hcard_ineq using 2
. congr 3
. rw [hA', Nat.card_image_of_injective hf]
. rw [hB', Nat.card_image_of_injective hg]
. rw [Nat.card_image_of_injective hf]
rw [Nat.card_image_of_injective hg]
convert LE.le.trans _ hdim_ineq using 2
norm_cast
apply max_le_max
. exact dimension_of_shift A'' x
· exact dimension_of_shift B'' y
/-- If $A,B\subseteq \mathbb{Z}^d$ are finite non-empty sets then there exist non-empty $A'\subseteq A$ and $B'\subseteq B$ such that
\[\log\frac{\lvert A\rvert\lvert B\rvert}{\lvert A'\rvert\lvert B'\rvert}\leq 34 d[U_A;U_B]\]
such that $\max(\dim A',\dim B')\leq \frac{40}{\log 2} d[U_A;U_B]$. -/
lemma weak_PFR_asymm (A B : Set G) [Finite A] [Finite B] (hA : A.Nonempty) (hB : B.Nonempty) : WeakPFRAsymmConclusion A B := by
let P : ℕ → Prop := fun M ↦ (∀ (G : Type u) (hG_comm : AddCommGroup G) (_hG_free : Module.Free ℤ G) (_hG_fin : Module.Finite ℤ G) (_hG_count : Countable G) (hG_mes : MeasurableSpace G) (_hG_sing: MeasurableSingletonClass G) (A B: Set G) (_hA_fin: Finite A) (_hB_fin: Finite B) (_hA_non: A.Nonempty) (_hB_non: B.Nonempty) (_hM : (Nat.card A) + (Nat.card B) ≤ M), WeakPFRAsymmConclusion A B)
suffices ∀ M, (∀ M', M' < M → P M') → P M by
set M := (Nat.card A) + (Nat.card B)
have hM : (Nat.card A) + (Nat.card B) ≤ M := Nat.le_refl _
convert (Nat.strong_induction_on (p := P) M this) G ‹_› ‹_› ‹_› ‹_› _ ‹_› A B ‹_› ‹_› ‹_› ‹_› hM
intro M h_induct
-- wlog we can assume A, B are not in cosets of a smaller subgroup
suffices ∀ (G : Type u) (hG_comm : AddCommGroup G) (_hG_free : Module.Free ℤ G)
(_hG_fin : Module.Finite ℤ G) (_hG_count : Countable G) (hG_mes : MeasurableSpace G)
(_hG_sing : MeasurableSingletonClass G) (A B : Set G) (_hA_fin : Finite A) (_hB_fin : Finite B) (_hA_non : A.Nonempty) (_hB_non : B.Nonempty) (_hM : Nat.card A + Nat.card B ≤ M)
(_hnot : NotInCoset A B), WeakPFRAsymmConclusion A B by
intro G hG_comm hG_free hG_fin hG_count hG_mes hG_sing A B hA_fin hB_fin hA_non hB_non hM
obtain ⟨ G', A', B', hAA', hBB', hnot' ⟩ := wlog_notInCoset hA_non hB_non
have hG'_fin : Module.Finite ℤ G' :=
Module.Finite.iff_fg (N := AddSubgroup.toIntSubmodule G').2 (IsNoetherian.noetherian _)
have hG'_free : Module.Free ℤ G' := by
rcases Submodule.nonempty_basis_of_pid (Module.Free.chooseBasis ℤ G) (AddSubgroup.toIntSubmodule G') with ⟨ n, ⟨ b ⟩ ⟩
exact Module.Free.of_basis b
have hAA'_card: Nat.card A = Nat.card A' := (Nat.card_image_of_injective Subtype.val_injective _) ▸ hAA'.card_congr
have hBB'_card: Nat.card B = Nat.card B' := (Nat.card_image_of_injective Subtype.val_injective _) ▸ hBB'.card_congr
have hA_non' : Nonempty A := Set.nonempty_coe_sort.mpr hA_non
have hB_non' : Nonempty B := Set.nonempty_coe_sort.mpr hB_non
rw [hAA'_card, hBB'_card] at hM
have hA'_nonfin : A'.Nonempty ∧ Finite A' := by
have := Nat.card_pos (α := A)
rw [hAA'_card, Nat.card_pos_iff] at this
exact ⟨@nonempty_of_nonempty_subtype _ _ this.1, this.2⟩
have hB'_nonfin : B'.Nonempty ∧ Finite B' := by
have := Nat.card_pos (α := B)
rw [hBB'_card, Nat.card_pos_iff] at this
exact ⟨@nonempty_of_nonempty_subtype _ _ this.1, this.2⟩
obtain ⟨ hA'_non, hA'_fin ⟩ := hA'_nonfin
obtain ⟨ hB'_non, hB'_fin ⟩ := hB'_nonfin
replace this := this G' _ hG'_free hG'_fin (by infer_instance) (by infer_instance) (by infer_instance) A' B' hA'_fin hB'_fin hA'_non hB'_non hM hnot'
exact conclusion_transfers G' A' B' hAA' hBB' hA'_non hB'_non this
intro G hG_comm hG_free hG_fin hG_count hG_mes hG_sing A B hA_fin hB_fin hA_non hB_non hM hnot
rcases weak_PFR_asymm_prelim A B hA_non hB_non with ⟨ N, x, y, Ax, By, hAx_non, hBy_non, hAx_fin, hBy_fin, hAx, hBy, hdim, hcard⟩
have hAxA : Ax ⊆ A := by rw [hAx]; simp
have hByB : By ⊆ B := by rw [hBy]; simp
have hA_pos : (0 : ℝ) < Nat.card A := Nat.cast_pos.mpr (@Nat.card_pos _ hA_non.to_subtype _)
have hB_pos : (0 : ℝ) < Nat.card B := Nat.cast_pos.mpr (@Nat.card_pos _ hB_non.to_subtype _)
rcases lt_or_ge (Nat.card Ax + Nat.card By) (Nat.card A + Nat.card B) with h | h
. replace h := h_induct (Nat.card Ax + Nat.card By) (h.trans_le hM) G hG_comm hG_free hG_fin hG_count hG_mes hG_sing Ax By (Set.finite_coe_iff.mpr hAx_fin) (Set.finite_coe_iff.mpr hBy_fin) hAx_non hBy_non (Eq.le rfl)
rcases h with ⟨ A', B', hA', hB', hA'_non, hB'_non, hcard_ineq, hdim_ineq ⟩
use A', B'
have hAx_fin' := Set.finite_coe_iff.mpr hAx_fin
have hBy_fin' := Set.finite_coe_iff.mpr hBy_fin
have hA'_fin' := Set.finite_coe_iff.mpr (Set.Finite.subset hAx_fin hA')
have hB'_fin' := Set.finite_coe_iff.mpr (Set.Finite.subset hBy_fin hB')
have hAx_non' := Set.nonempty_coe_sort.mpr hAx_non
have hBy_non' := Set.nonempty_coe_sort.mpr hBy_non
have hA'_non' := Set.nonempty_coe_sort.mpr hA'_non
have hB'_non' := Set.nonempty_coe_sort.mpr hB'_non
have hAx_pos : (0 : ℝ) < Nat.card Ax := Nat.cast_pos.mpr Nat.card_pos
have hBy_pos : (0 : ℝ) < Nat.card By := Nat.cast_pos.mpr Nat.card_pos
have hA'_pos : (0 : ℝ) < Nat.card A' := Nat.cast_pos.mpr Nat.card_pos
have hB'_pos : (0 : ℝ) < Nat.card B' := Nat.cast_pos.mpr Nat.card_pos
have hAxA_le : (Nat.card Ax : ℝ) ≤ (Nat.card A : ℝ) := Nat.cast_le.mpr (Nat.card_mono A.toFinite hAxA)
have hByB_le : (Nat.card By : ℝ) ≤ (Nat.card B : ℝ) := Nat.cast_le.mpr (Nat.card_mono B.toFinite hByB)
refine ⟨ hA'.trans hAxA, hB'.trans hByB, hA'_non, hB'_non, ?_, ?_ ⟩
. rw [four_logs hA_pos hB_pos hA'_pos hB'_pos]
rw [four_logs hAx_pos hBy_pos hA'_pos hB'_pos] at hcard_ineq
linarith only [hcard, hcard_ineq]
apply hdim_ineq.trans
gcongr
linarith only [Real.log_le_log hAx_pos hAxA_le, Real.log_le_log hBy_pos hByB_le, hcard]
use A, B
refine ⟨ Eq.subset rfl, Eq.subset rfl, hA_non, hB_non, ?_, ?_ ⟩
. have := hA_non.to_subtype
have := hB_non.to_subtype
apply LE.le.trans _ <| mul_nonneg (by norm_num) <| rdist_set_nonneg A B
rw [div_self (by positivity)]
simp
have hAx_eq : Ax = A := by
apply Set.Finite.eq_of_subset_of_card_le A.toFinite hAxA
linarith only [h, Nat.card_mono B.toFinite hByB]
have hBy_eq : By = B := by
apply Set.Finite.eq_of_subset_of_card_le B.toFinite hByB
linarith only [h, Nat.card_mono A.toFinite hAxA]
have hN : N = ⊤ := by
have : (A-A) ∪ (B-B) ⊆ N := by
rw [← hAx_eq, ← hBy_eq, hAx, hBy]
intro z hz
simp [Set.mem_sub] at hz
convert (QuotientAddGroup.eq_zero_iff z).mp ?_
. infer_instance
rcases hz with ⟨ a, ⟨ -, ha⟩, a', ⟨-, ha'⟩, haa' ⟩ | ⟨ b, ⟨ -, hb⟩, b', ⟨ -,hb'⟩, hbb' ⟩
. rw [← haa']; simp [ha, ha']
rw [← hbb']; simp [hb, hb']
rw [← AddSubgroup.closure_le, hnot] at this
exact top_le_iff.mp this
have : Nat.card (G ⧸ N) = 1 := by
rw [Nat.card_eq_one_iff_unique]
constructor
. rw [hN]
exact QuotientAddGroup.subsingleton_quotient_top
infer_instance
simp [this] at hdim
rw [← le_div_iff' (by positivity)] at hdim
convert LE.le.trans ?_ hdim using 1
. field_simp
simp
exact ⟨ dimension_le_rank A, dimension_le_rank B ⟩
/-- If $A\subseteq \mathbb{Z}^d$ is a finite non-empty set with $d[U_A;U_A]\leq \log K$ then there exists a non-empty $A'\subseteq A$ such that
$\lvert A'\rvert\geq K^{-17}\lvert A\rvert$
and $\dim A'\leq \frac{40}{\log 2} \log K$. -/
| lemma weak_PFR {A : Set G} [Finite A] {K : ℝ} (hA : A.Nonempty) (hK: 0 < K) (hdist: dᵤ[A # A] ≤ log K):
∃ A' : Set G, A' ⊆ A ∧ (Nat.card A') ≥ K^(-17 : ℝ) * (Nat.card A)
∧ (dimension A') ≤ (40 / log 2) * log K | weak_PFR | 25309ad 20231211 | c0c547a 20240116 | pfr/PFR/WeakPFR.lean | {
"lineInFile": 1177,
"tokenPositionInFile": 61189,
"theoremPositionInFile": 30
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n rcases weak_PFR_asymm A A hA hA with ⟨A', A'', hA', hA'', hA'nonempty, hA''nonempty, hcard, hdim⟩\n\n have : ∃ B : Set G, B ⊆ A ∧ (Nat.card B) ≥ (Nat.card A') ∧ (Nat.card B) ≥ (Nat.card A'') ∧ (dimension B) ≤\nmax (dimension A') (dimension A'') := by\n rcases lt_or_ge (Nat.card A') (Nat.card A'') with h | h\n . use A''\n exact ⟨hA'', by linarith, by linarith, le_max_right _ _⟩\n use A'\n exact ⟨hA', by linarith, by linarith, le_max_left _ _⟩\n\n rcases this with ⟨B, hB, hBcard, hBcard', hBdim⟩\n use B\n have hApos : Nat.card A > 0 := by\n rw [gt_iff_lt, Nat.card_pos_iff]\n exact ⟨hA.to_subtype, inferInstance⟩\n have hA'pos : Nat.card A' > 0 := by\n rw [gt_iff_lt, Nat.card_pos_iff]\n refine ⟨ hA'nonempty.to_subtype, Finite.Set.subset _ hA' ⟩\n have hA''pos : Nat.card A'' > 0 := by\n rw [gt_iff_lt, Nat.card_pos_iff]\n refine ⟨ hA''nonempty.to_subtype, Finite.Set.subset _ hA'' ⟩\n have hBpos : Nat.card B > 0 := by linarith\n\n refine ⟨hB, ?_, ?_⟩\n . have := calc 2 * log ((Nat.card A) / (Nat.card B))\n _ = log ( ((Nat.card A) * (Nat.card A)) / ((Nat.card B) * (Nat.card B)) ) := by\n convert (log_pow (((Nat.card A) : ℝ)/(Nat.card B)) 2).symm\n field_simp\n rw [← pow_two, ← pow_two]\n _ ≤ log ( ((Nat.card A) * (Nat.card A)) / ((Nat.card A') * (Nat.card A'')) ) := by\n apply log_le_log\n . positivity\n gcongr\n _ ≤ 34 * dᵤ[A # A] := hcard\n _ ≤ 34 * log K := mul_le_mul_of_nonneg_left hdist (by linarith)\n _ = 2 * (17 * log K) := by ring\n _ = 2 * log (K^17) := by\n congr\n convert (log_pow K 17).symm\n rw [mul_le_mul_left (by norm_num), log_le_log_iff (by positivity) (by positivity), div_le_iff (by positivity), <- mul_inv_le_iff (by positivity), <-ge_iff_le, mul_comm] at this\n convert this using 2\n convert zpow_neg K 17 using 1\n norm_cast\n calc (dimension B : ℝ)\n _ ≤ (((max (dimension A') (dimension A'')) : ℕ) : ℝ) := by norm_cast\n _ ≤ (40 / log 2) * dᵤ[A # A] := hdim\n _ ≤ (40 / log 2) * log K := mul_le_mul_of_nonneg_left hdist (by positivity)",
"proofType": "tactic",
"proofLengthLines": 48,
"proofLengthTokens": 2089
} | pfr |
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Quotient
import Mathlib.GroupTheory.Torsion
import Mathlib.GroupTheory.Torsion
import Mathlib.LinearAlgebra.FreeModule.PID
import PFR.Mathlib.Data.Set.Pointwise.SMul
import PFR.EntropyPFR
import PFR.ImprovedPFR
import PFR.ForMathlib.Entropy.RuzsaSetDist
import PFR.Mathlib.GroupTheory.Torsion
/-!
# Weak PFR over the integers
Here we use the entropic form of PFR to deduce a weak form of PFR over the integers.
## Main statement
* `weak_PFR_int`: Let $A\subseteq \mathbb{Z}^d$ and $\lvert A+A\rvert\leq K\lvert A\rvert$.
There exists $A'\subseteq A$ such that $\lvert A'\rvert \geq K^{-17}\lvert A\rvert$ and
$\dim A' \leq (40/\log 2)\log K$.
-/
section AddCommGroup
variable {G : Type*} [AddCommGroup G] {A B : Set G}
open Set
open scoped Pointwise
def IsShift (A B : Set G) : Prop := ∃ x : G, A = x +ᵥ B
lemma IsShift.sub_self_congr : IsShift A B → A - A = B - B := by
rintro ⟨x, rfl⟩; simp [vadd_sub_vadd_comm, singleton_zero]
lemma IsShift.card_congr : IsShift A B → Nat.card A = Nat.card B := by rintro ⟨x, rfl⟩; simp
/-- The property of two sets A, B of a group G not being contained in cosets of the same proper
subgroup -/
def NotInCoset (A B : Set G) : Prop := AddSubgroup.closure ((A - A) ∪ (B - B)) = ⊤
/-- Without loss of generality, one can move (up to translation and embedding) any pair A, B of non-empty sets into a subgroup where they are not in a coset. -/
lemma wlog_notInCoset (hA : A.Nonempty) (hB : B.Nonempty) :
∃ (G' : AddSubgroup G) (A' B' : Set G'), IsShift A A' ∧ IsShift B B' ∧ NotInCoset A' B' := by
obtain ⟨x, hx⟩ := hA
obtain ⟨y, hy⟩ := hB
set G' := AddSubgroup.closure ((A - A) ∪ (B - B))
set A' : Set G' := (↑) ⁻¹' ((-x) +ᵥ A)
set B' : Set G' := (↑) ⁻¹' ((-y) +ᵥ B)
have hxA : -x +ᵥ A ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hx).trans $ (subset_union_left ..).trans
AddSubgroup.subset_closure
have hyB : -y +ᵥ B ⊆ range ((↑) : G' → G) := by
simp only [← singleton_add', ← neg_singleton, neg_add_eq_sub, SetLike.coe_sort_coe,
Subtype.range_coe_subtype, SetLike.mem_coe]
exact (sub_subset_sub_left $ singleton_subset_iff.2 hy).trans $ (subset_union_right ..).trans
AddSubgroup.subset_closure
have hA : IsShift A A' := ⟨x, by rw [Set.image_preimage_eq_of_subset hxA, vadd_neg_vadd]⟩
have hB : IsShift B B' := ⟨y, by rw [Set.image_preimage_eq_of_subset hyB, vadd_neg_vadd]⟩
refine ⟨G', A', B', hA, hB, ?_⟩
unfold NotInCoset
convert AddSubgroup.closure_preimage_eq_top ((A - A) ∪ (B - B))
simp_rw [preimage_union, hA.sub_self_congr, hB.sub_self_congr]
rw [preimage_sub, preimage_sub]
simp [A', B', preimage_image_preimage]
all_goals apply_rules [Subtype.coe_injective, (image_preimage_subset ..).trans, hxA, hyB]
end AddCommGroup
section Torsion
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [MeasurableSpace G] [MeasurableSingletonClass G]
[Countable G] {Ω Ω' : Type u} [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ': Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
/-- If $G$ is torsion-free and $X,Y$ are $G$-valued random variables then $d[X;2Y]\leq 5d[X;Y]$. -/
lemma torsion_free_doubling [FiniteRange X] [FiniteRange Y]
(hX : Measurable X) (hY : Measurable Y) (hG : AddMonoid.IsTorsionFree G) :
d[X ; μ # (Y + Y) ; μ'] ≤ 5 * d[X; μ # Y ; μ'] := by
obtain ⟨A, mA, μA, X', Y'₁, Y'₂, hμA, h_indep, hX'_meas, hY'₁_meas, hY'₂_meas, hX'_ident,
hY'₁_ident, hY'₂_ident, _, _, _⟩ := independent_copies3_nondep_finiteRange hX hY hY μ μ' μ'
have h_meas (i : Fin 3) : Measurable (![X', Y'₁, Y'₂] i) := by fin_cases i <;> assumption
haveI : NoZeroSMulDivisors ℕ G := hG.noZeroNsmulDivisors
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] = H[⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨x, y₁, y₂⟩ ↦ (x, y₁ - y₂, x - 2 • y₁)
show H[f ∘ ⟨X', ⟨Y'₁, Y'₂⟩⟩ ; μA] = _
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hX'_meas <| Measurable.prod hY'₁_meas hY'₂_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun X' (prod Y'₁ Y'₂) μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 1 2 0 (by decide) (by decide)
rw [this.entropy_pair_eq_add hX'_meas (by exact Measurable.prod hY'₁_meas hY'₂_meas),
IndepFun.entropy_pair_eq_add hY'₁_meas hY'₂_meas (h_indep.indepFun (show 1 ≠ 2 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, two_mul]
have : H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[X ; μ] + H[Y ; μ'] := calc
H[⟨X', X' - 2 • Y'₁⟩ ; μA] = H[⟨X', Y'₁⟩ ; μA] := by
let f : G × G → G × G := fun ⟨x, y₁⟩ ↦ (x, x - 2 • y₁)
show H[f ∘ ⟨X', Y'₁⟩ ; μA] = _
apply entropy_comp_of_injective μA (by exact Measurable.prod hX'_meas hY'₁_meas) f
exact fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all [smul_right_inj]
_ = H[X ; μ] + H[Y ; μ'] := by
rw [IndepFun.entropy_pair_eq_add hX'_meas hY'₁_meas (h_indep.indepFun (show 0 ≠ 1 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq]
let f : G × G → G × G := fun ⟨x, y⟩ ↦ (x, y - x)
have hf : f.Injective := fun ⟨_, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _⟩ := h; simp_all
have : H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] := calc
H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] = H[f ∘ ⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
show _ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂ - (Y'₁ - Y'₂)⟩ ; μA]
rw [sub_sub_sub_cancel_right, ← sub_add_eq_sub_sub, two_nsmul]
_ = H[⟨Y'₁ - Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
refine entropy_comp_of_injective μA (Measurable.prod ?_ ?_) f hf
· exact Measurable.sub hY'₁_meas hY'₂_meas
· exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
_ ≤ H[Y'₁ - Y'₂ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] :=
entropy_pair_le_add (hY'₁_meas.sub' hY'₂_meas) (hX'_meas.sub' hY'₁_meas |>.sub' hY'₂_meas) μA
have : H[⟨X', ⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩⟩ ; μA] + H[X' - 2 • Y'₁ ; μA] ≤
H[⟨X', X' - 2 • Y'₁⟩ ; μA] + H[⟨Y'₁ - Y'₂, X' - 2 • Y'₁⟩ ; μA] := by
haveI : FiniteRange (Y'₁ - Y'₂) := FiniteRange.sub Y'₁ Y'₂
haveI : FiniteRange (2 • Y'₁) := by show FiniteRange ((fun x ↦ 2 • x) ∘ Y'₁); infer_instance
apply entropy_triple_add_entropy_le μA hX'_meas (Measurable.sub hY'₁_meas hY'₂_meas)
exact Measurable.sub' hX'_meas <| Measurable.const_smul hY'₁_meas 2
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[X ; μ] + 2 * H[Y ; μ'] := calc
H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] := by
let f : G × G × G → G × G × G := fun ⟨y₁, y₂, x⟩ ↦ (y₁, y₂, x - y₁ - y₂)
show H[f ∘ ⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA] = H[⟨Y'₁, ⟨Y'₂, X'⟩⟩ ; μA]
refine entropy_comp_of_injective μA ?_ f ?_
· exact Measurable.prod hY'₁_meas <| Measurable.prod hY'₂_meas hX'_meas
· exact fun ⟨_, _, _⟩ _ h ↦ by simp [f] at h; obtain ⟨_, _, _⟩ := h; simp_all
_ = H[X ; μ] + 2 * H[Y ; μ'] := by
have : IndepFun Y'₁ (prod Y'₂ X') μA := Indep.symm <|
h_indep.indepFun_prod_mk h_meas 2 0 1 (by decide) (by decide)
rw [this.entropy_pair_eq_add hY'₁_meas (by exact Measurable.prod hY'₂_meas hX'_meas),
IndepFun.entropy_pair_eq_add hY'₂_meas hX'_meas (h_indep.indepFun (show 2 ≠ 0 by decide)),
hX'_ident.entropy_eq, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq]
group
have : H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₂ ; μA] := calc
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₁, X' - Y'₂⟩ ; μA] := by rw [sub_right_comm] ; rfl
_ = H[⟨Y'₁, X' - Y'₂⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₁_meas <| Measurable.sub hX'_meas hY'₂_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₂ ; μA] := by
haveI : FiniteRange (X' - Y'₂) := FiniteRange.sub X' Y'₂
convert IndepFun.entropy_pair_eq_add hY'₁_meas (hX'_meas.sub hY'₂_meas)
<| h_indep.indepFun_sub_right h_meas 1 0 2 (by decide) (by decide)
exact hY'₁_ident.entropy_eq.symm
have : H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[Y ; μ'] + H[X' - Y'₁ ; μA] := calc
H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] = H[f ∘ ⟨Y'₂, X' - Y'₁⟩ ; μA] := rfl
_ = H[⟨Y'₂, X' - Y'₁⟩ ; μA] := entropy_comp_of_injective μA
(by exact Measurable.prod hY'₂_meas <| Measurable.sub hX'_meas hY'₁_meas) f hf
_ = H[Y ; μ'] + H[X' - Y'₁ ; μA] := by
haveI : FiniteRange (X' - Y'₁) := FiniteRange.sub X' Y'₁
convert IndepFun.entropy_pair_eq_add hY'₂_meas (hX'_meas.sub hY'₁_meas)
<| h_indep.indepFun_sub_right h_meas 2 0 1 (by decide) (by decide)
exact hY'₂_ident.entropy_eq.symm
have : H[⟨Y'₁, ⟨Y'₂, X' - Y'₁ - Y'₂⟩⟩ ; μA] + H[X' - Y'₁ - Y'₂ ; μA] ≤
H[⟨Y'₁, X' - Y'₁ - Y'₂⟩ ; μA] + H[⟨Y'₂, X' - Y'₁ - Y'₂⟩ ; μA] := by
apply entropy_triple_add_entropy_le μA hY'₁_meas hY'₂_meas
exact Measurable.sub (Measurable.sub hX'_meas hY'₁_meas) hY'₂_meas
have : H[X' - Y'₁ - Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := calc
H[X' - Y'₁ - Y'₂ ; μA] ≤ H[X' - Y'₁ ; μA] + H[X' - Y'₂ ; μA] - H[X ; μ] := by linarith
_ = 2 * d[X ; μ # Y ; μ'] + H[Y ; μ'] := by
nth_rw 1 [two_mul, ← hX'_ident.rdist_eq hY'₁_ident, ← hX'_ident.rdist_eq hY'₂_ident]
have h1 : d[X' ; μA # Y'₁ ; μA] = H[X' - Y'₁ ; μA] - H[X' ; μA] / 2 - H[Y'₁ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 1 by decide)).rdist_eq hX'_meas hY'₁_meas
have h2 : d[X' ; μA # Y'₂ ; μA] = H[X' - Y'₂ ; μA] - H[X' ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 0 ≠ 2 by decide)).rdist_eq hX'_meas hY'₂_meas
rw [h1, h2, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, hX'_ident.entropy_eq]
group
have : d[X ; μ # 2 • Y ; μ'] ≤
d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := calc
d[X ; μ # 2 • Y ; μ'] = H[X' - 2 • Y'₁ ; μA] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by
have h2Y_ident : IdentDistrib (2 • Y'₁) (2 • Y) (μ := μA) (ν := μ') := by
convert hY'₁_ident.comp <| measurable_discrete <| fun g ↦ 2 • g
have h2Y_indep : IndepFun X' (2 • Y'₁) (μ := μA) := by
convert (h_indep.indepFun (show 0 ≠ 1 by decide)).comp measurable_id
(measurable_const_smul 2)
rw [← hX'_ident.rdist_eq h2Y_ident,
h2Y_indep.rdist_eq hX'_meas <| Measurable.const_smul hY'₁_meas 2,
hX'_ident.entropy_eq, h2Y_ident.entropy_eq]
_ ≤ H[Y'₁ - Y'₂ ; μA] + 2 * d[X ; μ # Y ; μ'] - H[X ; μ] / 2 - H[2 • Y ; μ'] / 2 := by linarith
_ = d[Y'₁ ; μA # Y'₂ ; μA] + (H[Y ; μ'] - H[X ; μ]) / 2 + 2 * d[X ; μ # Y ; μ'] := by
have H2Y : H[2 • Y ; μ'] = H[Y ; μ'] := by
let f (g : G) := 2 • g
exact entropy_comp_of_injective μ' hY f (fun _ _ ↦ by simp [f, smul_right_inj])
have : d[Y'₁ ; μA # Y'₂ ; μA] = H[Y'₁ - Y'₂ ; μA] - H[Y'₁ ; μA] / 2 - H[Y'₂ ; μA] / 2 :=
(h_indep.indepFun (show 1 ≠ 2 by decide)).rdist_eq hY'₁_meas hY'₂_meas
rw [this, hY'₁_ident.entropy_eq, hY'₂_ident.entropy_eq, H2Y]
group
have : d[Y'₁ ; μA # Y'₂ ; μA] ≤ 2 * d[X ; μ # Y ; μ'] := by
rw [two_mul]
convert rdist_triangle hY'₁_meas hX'_meas hY'₂_meas (μ := μA) (μ' := μA) (μ'' := μA)
· exact rdist_symm.trans (hY'₁_ident.rdist_eq hX'_ident).symm
· exact (hX'_ident.rdist_eq hY'₂_ident).symm
rw [← two_nsmul]
linarith [abs_le.mp <| diff_ent_le_rdist hX hY (μ := μ) (μ' := μ')]
/-- If $G$ is a torsion-free group and $X,Y$ are $G$-valued random variables and
$\phi : G\to \mathbb{F}_2^d$ is a homomorphism then
\[\mathbb{H}(\phi(X))\leq 10d[X;Y].\] -/
lemma torsion_dist_shrinking {H : Type u} [FiniteRange X] [FiniteRange Y] (hX : Measurable X)
(hY : Measurable Y) [AddCommGroup H] [ElementaryAddCommGroup H 2]
[MeasurableSpace H] [MeasurableSingletonClass H] [Countable H]
(hG : AddMonoid.IsTorsionFree G) (φ : G →+ H) :
H[φ ∘ X ; μ] ≤ 10 * d[X; μ # Y ; μ'] := by
have :=
calc d[φ ∘ X ; μ # φ ∘ (Y + Y); μ'] ≤ d[X; μ # (Y + Y) ; μ'] := rdist_of_hom_le φ hX (Measurable.add hY hY)
_ ≤ 5 * d[X; μ # Y ; μ'] := torsion_free_doubling X Y μ μ' hX hY hG
have eq_zero : φ ∘ (Y + Y) = fun _ ↦ 0 := by ext x ; simp only [Function.comp_apply, Pi.add_apply,
map_add, ElementaryAddCommGroup.add_self]
rwa [eq_zero, rdist_zero_eq_half_ent, div_le_iff zero_lt_two, mul_assoc, mul_comm _ 2, ←mul_assoc,
show (5*2 : ℝ) = 10 by norm_num] at this
end Torsion
instance {G : Type u} [AddCommGroup G] [Fintype G] [MeasurableSpace G] [MeasurableSingletonClass G] (H : AddSubgroup G)
: MeasurableSingletonClass (G ⧸ H) :=
⟨λ _ ↦ by { rw [measurableSet_quotient]; simp [measurableSet_discrete] }⟩
section F2_projection
open Real ProbabilityTheory MeasureTheory
variable {G : Type u} [AddCommGroup G] [ElementaryAddCommGroup G 2] [Fintype G] [MeasurableSpace G]
[MeasurableSingletonClass G] {Ω Ω' : Type*}
/-- Let $G=\mathbb{F}_2^n$ and $X,Y$ be $G$-valued random variables such that
\[\mathbb{H}(X)+\mathbb{H}(Y)> (20/\alpha) d[X;Y],\]
for some $\alpha > 0$.
There is a non-trivial subgroup $H\leq G$ such that
\[\log \lvert H\rvert <(1+\alpha)/2 (\mathbb{H}(X)+\mathbb{H}(Y))\] and
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))< \alpha (\mathbb{H}(X)+\mathbb{H}(Y))\]
where $\psi:G\to G/H$ is the natural projection homomorphism.
-/
lemma app_ent_PFR' [MeasureSpace Ω] [MeasureSpace Ω'] (X : Ω → G) (Y : Ω' → G)
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
{α : ℝ} (hent : 20 * d[X # Y] < α * (H[X] + H[Y])) (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X] + H[Y]) ∧
H[(QuotientAddGroup.mk' H) ∘ X] + H[(QuotientAddGroup.mk' H) ∘ Y] < α * (H[X] + H[Y]) := by
let p : refPackage Ω Ω' G := {
X₀₁ := X
X₀₂ := Y
hmeas1 := hX
hmeas2 := hY
η := 1/8
hη := by norm_num
hη' := by norm_num }
obtain ⟨H, Ω'', hΩ'', U, _, hUmeas, hUunif, ineq⟩ := entropic_PFR_conjecture_improv p rfl
let ψ := (QuotientAddGroup.mk' H)
use H
haveI : Finite H := Subtype.finite
-- Note that H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y]
have ent_le : H[ψ ∘ X] + H[ψ ∘ Y] ≤ 20 * d[X # Y] := calc
H[ψ ∘ X] + H[ψ ∘ Y] ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· exact ent_of_proj_le hX hUmeas hUunif
· exact ent_of_proj_le hY hUmeas hUunif
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- Note that (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y]
have log_sub_le : (log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) ≤ 20 * d[X # Y] := calc
(log (Nat.card H) - H[X]) + (log (Nat.card H) - H[Y]) =
(H[U] - H[X]) + (H[U] - H[Y]) := by
rw [IsUniform.entropy_eq' hUunif hUmeas, SetLike.coe_sort_coe]
_ ≤ |(H[U] - H[X])| + |(H[U] - H[Y])| := by gcongr <;> exact le_abs_self _
_ ≤ 2 * d[X # U] + 2 * d[Y # U] := by
gcongr
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hX
· rw [rdist_symm]; exact diff_ent_le_rdist hUmeas hY
_ = 2 * (d[X # U] + d[Y # U]) := by ring
_ ≤ 2 * (10 * d[X # Y]) := by gcongr
_ = 20 * d[X # Y] := by ring
-- then the conclusion follows from the assumption `hent` and basic inequality manipulations
exact ⟨by linarith, by linarith⟩
variable [MeasurableSpace Ω] [MeasurableSpace Ω'] (X : Ω → G) (Y : Ω' → G)
(μ : Measure Ω := by volume_tac) (μ' : Measure Ω' := by volume_tac)
[IsProbabilityMeasure μ] [IsProbabilityMeasure μ']
lemma app_ent_PFR (α : ℝ) (hent: 20 * d[X;μ # Y;μ'] < α * (H[X; μ] + H[Y; μ'])) (hX : Measurable X)
(hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) < (1 + α) / 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ']
< α * (H[ X; μ] + H[Y; μ']) :=
@app_ent_PFR' _ _ _ _ _ _ _ _ (MeasureSpace.mk μ) (MeasureSpace.mk μ') _ _ _ _ α hent hX hY
set_option maxHeartbeats 300000 in
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables and $\alpha < 1$ then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq (1 + α) / (2 * (1 - α)) * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 20/\alpha * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection'
(α : ℝ) (hX : Measurable X) (hY : Measurable Y) (αpos : 0 < α) (αone : α < 1) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (H[X ; μ] + H[Y ; μ']) ∧
α * (H[(QuotientAddGroup.mk' H) ∘ X ; μ] + H[(QuotientAddGroup.mk' H) ∘ Y ; μ']) ≤
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] := by
let S := { H : AddSubgroup G | (∃ (c : ℝ), 0 ≤ c ∧
log (Nat.card H) ≤ (1 + α) / (2 * (1 - α)) * (1 - c) * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
c * (H[X; μ] + H[Y;μ'])) ∧
20 * d[(QuotientAddGroup.mk' H) ∘ X ; μ # (QuotientAddGroup.mk' H) ∘ Y ; μ'] <
α * (H[ (QuotientAddGroup.mk' H) ∘ X; μ ] + H[ (QuotientAddGroup.mk' H) ∘ Y; μ']) }
have : 0 ≤ H[X ; μ] + H[Y ; μ'] := by linarith [entropy_nonneg X μ, entropy_nonneg Y μ']
have : 0 < 1 - α := sub_pos.mpr αone
by_cases hE : (⊥ : AddSubgroup G) ∈ S
· classical
obtain ⟨H, ⟨⟨c, hc, hlog, hup⟩, hent⟩, hMaxl⟩ :=
S.toFinite.exists_maximal_wrt id S (Set.nonempty_of_mem hE)
set ψ : G →+ G ⧸ H := QuotientAddGroup.mk' H
have surj : Function.Surjective ψ := QuotientAddGroup.mk'_surjective H
set G' := G ⧸ H
have : ElementaryAddCommGroup G' 2 := ElementaryAddCommGroup.quotient_group (by decide)
(by simp [AddSubgroup.zero_mem])
obtain ⟨H', hlog', hup'⟩ := app_ent_PFR _ _ _ _ α hent ((measurable_discrete _).comp hX)
((measurable_discrete _).comp hY)
have H_ne_bot: H' ≠ ⊥ := by
by_contra!
rcases this with rfl
have inj : Function.Injective (QuotientAddGroup.mk' (⊥ : AddSubgroup G')) :=
(QuotientAddGroup.quotientBot : (G' ⧸ ⊥) ≃+ G').symm.injective
rw [entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ inj,
entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ inj] at hup'
nlinarith [entropy_nonneg (ψ ∘ X) μ, entropy_nonneg (ψ ∘ Y) μ']
let H'' := H'.comap ψ
use H''
rw [← (AddSubgroup.map_comap_eq_self_of_surjective surj _ : H''.map ψ = H')] at hup' hlog'
set H' := H''.map ψ
have Hlt : H < H'' := by
have : H = (⊥ : AddSubgroup G').comap ψ := by
simp only [ψ, AddMonoidHom.comap_bot, QuotientAddGroup.ker_mk']
rw [this, AddSubgroup.comap_lt_comap_of_surjective surj]
exact Ne.bot_lt H_ne_bot
let φ : G' ⧸ H' ≃+ G ⧸ H'' := QuotientAddGroup.quotientQuotientEquivQuotient H H'' Hlt.le
set ψ' : G' →+ G' ⧸ H' := QuotientAddGroup.mk' H'
set ψ'' : G →+ G ⧸ H'' := QuotientAddGroup.mk' H''
have diag : ψ' ∘ ψ = φ.symm ∘ ψ'' := rfl
rw [← Function.comp.assoc, ← Function.comp.assoc, diag, Function.comp.assoc,
Function.comp.assoc] at hup'
have cond : log (Nat.card H'') ≤
(1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := by
have cardprod : Nat.card H'' = Nat.card H' * Nat.card H := by
have hcard₀ := Nat.card_congr <| (AddSubgroup.addSubgroupOfEquivOfLe Hlt.le).toEquiv
have hcard₁ := Nat.card_congr <|
(QuotientAddGroup.quotientKerEquivRange (ψ.restrict H'')).toEquiv
have hcard₂ := AddSubgroup.card_eq_card_quotient_mul_card_addSubgroup (H.addSubgroupOf H'')
rw [ψ.ker_restrict H'', QuotientAddGroup.ker_mk', ψ.restrict_range H''] at hcard₁
simpa only [← Nat.card_eq_fintype_card, hcard₀, hcard₁] using hcard₂
calc
log (Nat.card H'')
_ = log ((Nat.card H' : ℝ) * (Nat.card H : ℝ)) := by rw [cardprod]; norm_cast
_ = log (Nat.card H') + log (Nat.card H) := by
rw [Real.log_mul (Nat.cast_ne_zero.2 (@Nat.card_pos H').ne')
(Nat.cast_ne_zero.2 (@Nat.card_pos H).ne')]
_ ≤ (1 + α) / 2 * (H[⇑ψ ∘ X ; μ] + H[⇑ψ ∘ Y ; μ']) + log (Nat.card H) := by gcongr
_ ≤ (1 + α) / 2 * (c * (H[X; μ] + H[Y;μ'])) +
(1 + α) / (2 * (1 - α)) * (1 - c) * (H[X ; μ] + H[Y ; μ']) := by gcongr
_ = (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X ; μ] + H[Y ; μ']) := by
field_simp; ring
have HS : H'' ∉ S := λ Hs => Hlt.ne (hMaxl H'' Hs Hlt.le)
simp only [S, Set.mem_setOf_eq, not_and, not_lt] at HS
refine ⟨?_, HS ⟨α * c, by positivity, cond, ?_⟩⟩
· calc
log (Nat.card H'')
_ ≤ (1 + α) / (2 * (1 - α)) * (1 - α * c) * (H[X; μ] + H[Y;μ']) := cond
_ ≤ (1 + α) / (2 * (1 - α)) * 1 * (H[X; μ] + H[Y;μ']) := by gcongr; simp; positivity
_ = (1 + α) / (2 * (1 - α)) * (H[X; μ] + H[Y;μ']) := by simp only [mul_one]
· calc
H[ ψ'' ∘ X; μ ] + H[ ψ'' ∘ Y; μ' ]
_ = H[ φ.symm ∘ ψ'' ∘ X; μ ] + H[ φ.symm ∘ ψ'' ∘ Y; μ' ] := by
simp_rw [← entropy_comp_of_injective _ ((measurable_discrete _).comp hX) _ φ.symm.injective,
← entropy_comp_of_injective _ ((measurable_discrete _).comp hY) _ φ.symm.injective]
_ ≤ α * (H[ ψ ∘ X; μ ] + H[ ψ ∘ Y; μ' ]) := hup'.le
_ ≤ α * (c * (H[X ; μ] + H[Y ; μ'])) := by gcongr
_ = (α * c) * (H[X ; μ] + H[Y ; μ']) := by ring
· use ⊥
constructor
· simp only [AddSubgroup.mem_bot, Nat.card_eq_fintype_card, Fintype.card_ofSubsingleton,
Nat.cast_one, log_one]
positivity
· simp only [S, Set.mem_setOf_eq, not_and, not_lt] at hE
exact hE ⟨1, by norm_num, by
norm_num; exact add_le_add (entropy_comp_le μ hX _) (entropy_comp_le μ' hY _)⟩
/-- If $G=\mathbb{F}_2^d$ and $X,Y$ are $G$-valued random variables then there is
a subgroup $H\leq \mathbb{F}_2^d$ such that
\[\log \lvert H\rvert \leq 2 * (\mathbb{H}(X)+\mathbb{H}(Y))\]
and if $\psi:G \to G/H$ is the natural projection then
\[\mathbb{H}(\psi(X))+\mathbb{H}(\psi(Y))\leq 34 * d[\psi(X);\psi(Y)].\] -/
lemma PFR_projection (hX : Measurable X) (hY : Measurable Y) :
∃ H : AddSubgroup G, log (Nat.card H) ≤ 2 * (H[X; μ] + H[Y;μ']) ∧
H[(QuotientAddGroup.mk' H) ∘ X; μ] + H[(QuotientAddGroup.mk' H) ∘ Y; μ'] ≤
34 * d[(QuotientAddGroup.mk' H) ∘ X;μ # (QuotientAddGroup.mk' H) ∘ Y;μ'] := by
rcases PFR_projection' X Y μ μ' ((3 : ℝ) / 5) hX hY (by norm_num) (by norm_num) with ⟨H, h, h'⟩
refine ⟨H, ?_, ?_⟩
· convert h
norm_num
· have : 0 ≤ d[⇑(QuotientAddGroup.mk' H) ∘ X ; μ # ⇑(QuotientAddGroup.mk' H) ∘ Y ; μ'] :=
rdist_nonneg ((measurable_discrete _).comp hX) ((measurable_discrete _).comp hY)
linarith
end F2_projection
open MeasureTheory ProbabilityTheory Real Set
open scoped BigOperators
lemma four_logs {a b c d : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) (hd : 0 < d) :
log ((a*b)/(c*d)) = log a + log b - log c - log d := by
rw [log_div, log_mul, log_mul, sub_sub] <;> positivity
lemma sum_prob_preimage {G H : Type*} {X : Finset H} {A : Set G} [Finite A] {φ : A → X}
{A_ : H → Set G} (hA : A.Nonempty) (hφ : ∀ x : X, A_ x = Subtype.val '' (φ ⁻¹' {x})) :
∑ x in X, (Nat.card (A_ x) : ℝ) / (Nat.card A) = 1 := by
rw [← Finset.sum_div]
apply (div_eq_one_iff_eq <| Nat.cast_ne_zero.mpr <| Nat.pos_iff_ne_zero.mp (@Nat.card_pos _ hA.to_subtype _)).mpr
classical
haveI := Fintype.ofFinite A
rewrite [Nat.card_eq_fintype_card, ← Finset.card_univ, Finset.card_eq_sum_card_fiberwise
<| fun a _ ↦ Finset.mem_univ (φ a), ← Finset.sum_coe_sort]
norm_cast
congr; ext
rewrite [← Set.Finite.toFinset_setOf, (Set.toFinite _).card_toFinset, ← Nat.card_eq_fintype_card,
hφ, Nat.card_image_of_injective Subtype.val_injective]; rfl
/-- Let $\phi : G\to H$ be a homomorphism and $A,B\subseteq G$ be finite subsets. If $x,y\in H$ then let $A_x=A\cap \phi^{-1}(x)$ and $B_y=B\cap \phi^{-1}(y)$. There exist $x,y\in H$ such that $A_x,B_y$ are both non-empty and
\[d[\phi(U_A);\phi(U_B)]\log \frac{\lvert A\rvert\lvert B\rvert}{\lvert A_x\rvert\lvert B_y\rvert}\leq (\mathbb{H}(\phi(U_A))+\mathbb{H}(\phi(U_B)))(d(U_A,U_B)-d(U_{A_x},U_{B_y}).\] -/
lemma single_fibres {G H Ω Ω': Type u}
[AddCommGroup G] [Countable G] [MeasurableSpace G] [MeasurableSingletonClass G]
[AddCommGroup H] [Countable H] [MeasurableSpace H] [MeasurableSingletonClass H]
[MeasureSpace Ω] [MeasureSpace Ω']
[IsProbabilityMeasure (ℙ : Measure Ω)] [IsProbabilityMeasure (ℙ : Measure Ω')]
(φ : G →+ H)
{A B : Set G} [Finite A] [Finite B] {UA : Ω → G} {UB: Ω' → G} (hA : A.Nonempty) (hB : B.Nonempty)
(hUA': Measurable UA) (hUB': Measurable UB) (hUA: IsUniform A UA) (hUB: IsUniform B UB)
(hUA_mem : ∀ ω, UA ω ∈ A) (hUB_mem : ∀ ω, UB ω ∈ B) :
∃ (x y : H) (Ax By: Set G),
Ax = A ∩ φ.toFun ⁻¹' {x} ∧ By = B ∩ φ.toFun ⁻¹' {y} ∧ Ax.Nonempty ∧ By.Nonempty ∧
d[φ.toFun ∘ UA # φ.toFun ∘ UB]
* log ((Nat.card A) * (Nat.card B) / ((Nat.card Ax) * (Nat.card By))) ≤
(H[φ.toFun ∘ UA] + H[φ.toFun ∘ UB]) * (d[UA # UB] - dᵤ[Ax # By]) := by
have : Nonempty A := hA.to_subtype
have : Nonempty B := hB.to_subtype
haveI : FiniteRange UA := finiteRange_of_finset UA A.toFinite.toFinset (by simpa)
haveI : FiniteRange UB := finiteRange_of_finset UB B.toFinite.toFinset (by simpa)
have hUA_coe : IsUniform A.toFinite.toFinset.toSet UA := by rwa [Set.Finite.coe_toFinset]
have hUB_coe : IsUniform B.toFinite.toFinset.toSet UB := by rwa [Set.Finite.coe_toFinset]
let A_ (x : H) : Set G := A ∩ φ.toFun ⁻¹' {x}
let B_ (y : H) : Set G := B ∩ φ.toFun ⁻¹' {y}
let X : Finset H := FiniteRange.toFinset (φ.toFun ∘ UA)
let Y : Finset H := FiniteRange.toFinset (φ.toFun ∘ UB)
haveI h_Ax (x : X) : Nonempty (A_ x.val) := by
obtain ⟨ω, hω⟩ := (FiniteRange.mem_iff _ _).mp x.property
use UA ω; exact Set.mem_inter (hUA_mem ω) (by exact hω)
haveI h_By (y : Y) : Nonempty (B_ y.val) := by
obtain ⟨ω, hω⟩ := (FiniteRange.mem_iff _ _).mp y.property
use UB ω; exact Set.mem_inter (hUB_mem ω) (by exact hω)
have h_AX (a : A) : φ.toFun a.val ∈ X := by
obtain ⟨ω, hω⟩ := hUA_coe.nonempty_preimage_of_mem hUA' (A.toFinite.mem_toFinset.mpr a.property)
exact (FiniteRange.mem_iff _ (φ.toFun a.val)).mpr ⟨ω, congr_arg _ hω⟩
have h_BY (b : B) : φ.toFun b.val ∈ Y := by
obtain ⟨ω, hω⟩ := hUB_coe.nonempty_preimage_of_mem hUB' (B.toFinite.mem_toFinset.mpr b.property)
exact (FiniteRange.mem_iff _ (φ.toFun b.val)).mpr ⟨ω, congr_arg _ hω⟩
let φ_AX (a : A) : X := by use φ.toFun a.val; exact h_AX a
let φ_BY (b : B) : Y := by use φ.toFun b.val; exact h_BY b
have h_φ_AX (x : X) : A_ x.val = φ_AX ⁻¹' {x} := by ext; simp [A_, φ_AX]; simp [Subtype.ext_iff]
have h_φ_BY (y : Y) : B_ y.val = φ_BY ⁻¹' {y} := by ext; simp [B_, φ_BY]; simp [Subtype.ext_iff]
let p (x : H) (y : H) : ℝ :=
(Nat.card (A_ x).Elem) * (Nat.card (B_ y).Elem) / ((Nat.card A.Elem) * (Nat.card B.Elem))
have :
∑ x in X, ∑ y in Y, (p x y) * dᵤ[A_ x # B_ y] ≤ d[UA # UB] - d[φ.toFun ∘ UA # φ.toFun ∘ UB] :=
calc
_ = d[UA | φ.toFun ∘ UA # UB | φ.toFun ∘ UB] := by
rewrite [condRuzsaDist_eq_sum hUA' ((measurable_discrete _).comp hUA')
hUB' ((measurable_discrete _).comp hUB')]
refine Finset.sum_congr rfl <| fun x hx ↦ Finset.sum_congr rfl <| fun y hy ↦ ?_
haveI : Nonempty (A_ x) := h_Ax ⟨x, hx⟩
haveI : Nonempty (B_ y) := h_By ⟨y, hy⟩
let μx := (ℙ : Measure Ω)[|(φ.toFun ∘ UA) ⁻¹' {x}]
let μy := (ℙ : Measure Ω')[|(φ.toFun ∘ UB) ⁻¹' {y}]
have h_μ_p : IsProbabilityMeasure μx ∧ IsProbabilityMeasure μy := by
constructor <;> apply ProbabilityTheory.cond_isProbabilityMeasure <;> rw [Set.preimage_comp]
refine @IsUniform.measure_preimage_ne_zero _ _ _ _ _ _ _ _ _ _ hUA_coe hUA' _ ?_
swap; refine @IsUniform.measure_preimage_ne_zero _ _ _ _ _ _ _ _ _ _ hUB_coe hUB' _ ?_
all_goals rwa [Set.inter_comm, Set.Finite.coe_toFinset]
have h_μ_unif : IsUniform (A_ x) UA μx ∧ IsUniform (B_ y) UB μy := by
have : _ ∧ _ := ⟨hUA.restrict hUA' (φ.toFun ⁻¹' {x}), hUB.restrict hUB' (φ.toFun ⁻¹' {y})⟩
rwa [Set.inter_comm _ A, Set.inter_comm _ B] at this
rewrite [rdist_set_eq_rdist h_μ_p.1 h_μ_p.2 h_μ_unif.1 h_μ_unif.2 hUA' hUB']
show _ = (Measure.real _ (UA ⁻¹' (_ ⁻¹' _))) * (Measure.real _ (UB ⁻¹' (_ ⁻¹' _))) * _
rewrite [hUA_coe.measureReal_preimage hUA', hUB_coe.measureReal_preimage hUB']
simp_rw [p, A_, B_, IsProbabilityMeasure.measureReal_univ, one_mul]
rewrite [mul_div_mul_comm, Set.inter_comm A, Set.inter_comm B]
simp only [Set.Finite.coe_toFinset, Set.Finite.mem_toFinset, Finset.mem_val]; rfl
_ ≤ d[UA # UB] - d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
rewrite [ZeroHom.toFun_eq_coe, AddMonoidHom.toZeroHom_coe]
linarith only [rdist_le_sum_fibre φ hUA' hUB' (μ := ℙ) (μ' := ℙ)]
let M := H[φ.toFun ∘ UA] + H[φ.toFun ∘ UB]
have hM : M = ∑ x in X, ∑ y in Y, Real.negMulLog (p x y) := by
have h_compl {x y} (h_notin : (x, y) ∉ X ×ˢ Y) : Real.negMulLog (p x y) = 0 := by
unfold_let p; beta_reduce
rewrite [Finset.mem_product, not_and_or] at h_notin
suffices A_ x = ∅ ∨ B_ y = ∅ by obtain h | h := this <;> rw [h] <;> simp
refine h_notin.imp ?_ ?_
· rw [← not_nonempty_iff_eq_empty]
rintro h ⟨a, ha, rfl⟩
exact h (h_AX ⟨a, ha⟩)
· rw [← not_nonempty_iff_eq_empty]
rintro h ⟨a, ha, rfl⟩
exact h (h_BY ⟨a, ha⟩)
unfold_let M
unfold entropy
haveI := isProbabilityMeasure_map (μ := ℙ) ((measurable_discrete φ).comp hUA').aemeasurable
haveI := isProbabilityMeasure_map (μ := ℙ) ((measurable_discrete φ).comp hUB').aemeasurable
rewrite [← Finset.sum_product', ← tsum_eq_sum fun _ ↦ h_compl, ← measureEntropy_prod]
apply tsum_congr; intro; congr
rewrite [← Set.singleton_prod_singleton, Measure.smul_apply, Measure.prod_prod,
Measure.map_apply ((measurable_discrete _).comp hUA') (MeasurableSet.singleton _),
Measure.map_apply ((measurable_discrete _).comp hUB') (MeasurableSet.singleton _),
Set.preimage_comp, hUA_coe.measure_preimage hUA',
Set.preimage_comp, hUB_coe.measure_preimage hUB']
simp [p, A_, B_, mul_div_mul_comm, Set.inter_comm, ENNReal.toReal_div]
have h_sum : ∑ x in X, ∑ y in Y,
(p x y) * (M * dᵤ[A_ x # B_ y] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p x y)) ≤
M * d[UA # UB] :=
calc
_ = ∑ x in X, ∑ y in Y, (p x y) * M * dᵤ[A_ x # B_ y] + M * d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
simp_rw [hM, Finset.sum_mul, ← Finset.sum_add_distrib]
refine Finset.sum_congr rfl <| fun _ _ ↦ Finset.sum_congr rfl <| fun _ _ ↦ ?_
simp only [negMulLog, left_distrib, mul_assoc, Finset.sum_mul]
exact congrArg (HAdd.hAdd _) (by group)
_ = M * ∑ x in X, ∑ y in Y, (p x y) * dᵤ[A_ x # B_ y] + M * d[φ.toFun ∘ UA # φ.toFun ∘ UB] := by
simp_rw [Finset.mul_sum]
congr; ext; congr; ext; group
_ ≤ M * d[UA # UB] := by
rewrite [← left_distrib]
apply mul_le_mul_of_nonneg_left
· linarith
· unfold_let M
linarith only [entropy_nonneg (φ.toFun ∘ UA) ℙ, entropy_nonneg (φ.toFun ∘ UB) ℙ]
have : ∃ x : X, ∃ y : Y,
M * dᵤ[A_ x.val # B_ y.val] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p x.val y.val) ≤
M * d[UA # UB] := by
let f (xy : H × H) := (p xy.1 xy.2) * (M * d[UA # UB])
let g (xy : H × H) := (p xy.1 xy.2) *
(M * dᵤ[A_ xy.1 # B_ xy.2] + d[φ.toFun ∘ UA # φ.toFun ∘ UB] * -Real.log (p xy.1 xy.2))
by_contra hc; push_neg at hc
replace hc : ∀ xy ∈ X ×ˢ Y, f xy < g xy := by
refine fun xy h ↦ mul_lt_mul_of_pos_left ?_ ?_
· exact hc ⟨xy.1, (Finset.mem_product.mp h).1⟩ ⟨xy.2, (Finset.mem_product.mp h).2⟩
· haveI : Nonempty _ := h_Ax ⟨xy.1, (Finset.mem_product.mp h).1⟩
haveI : Nonempty _ := h_By ⟨xy.2, (Finset.mem_product.mp h).2⟩
simp only [p, div_pos, mul_pos, Nat.cast_pos, Nat.card_pos]
have h_nonempty : Finset.Nonempty (X ×ˢ Y) := by
use ⟨φ.toFun <| UA <| Classical.choice <| ProbabilityMeasure.nonempty ⟨ℙ, inferInstance⟩,
φ.toFun <| UB <| Classical.choice <| ProbabilityMeasure.nonempty ⟨ℙ, inferInstance⟩⟩
exact Finset.mem_product.mpr ⟨FiniteRange.mem _ _, FiniteRange.mem _ _⟩
replace hc := Finset.sum_lt_sum_of_nonempty h_nonempty hc
have h_p_one : ∑ x in X ×ˢ Y, p x.1 x.2 = 1 := by
simp_rw [Finset.sum_product, p, mul_div_mul_comm, ← Finset.mul_sum,
← sum_prob_preimage hA h_φ_AX, sum_prob_preimage hB h_φ_BY, mul_one]
rewrite [← Finset.sum_mul, h_p_one, one_mul, Finset.sum_product] at hc
exact not_le_of_gt hc h_sum
obtain ⟨x, y, hxy⟩ := this
refine ⟨x, y, A_ x.val, B_ y.val, rfl, rfl, @nonempty_of_nonempty_subtype _ _ (h_Ax x), @nonempty_of_nonempty_subtype _ _ (h_By y), ?_⟩
rewrite [← inv_div, Real.log_inv]
show _ * -log (p x.val y.val) ≤ M * _
linarith only [hxy]
section dim
open Classical
variable {G : Type*} [AddCommGroup G]
/- If G ≅ ℤᵈ then there is a subgroup H of G such that A lies in a coset of H. This is helpful to
give the equivalent definition of `dimension`. Here this is stated in greated generality since the
proof carries over automatically-/
lemma exists_coset_cover (A : Set G) :
∃ (d : ℕ), ∃ (S : Submodule ℤ G) (v : G),
FiniteDimensional.finrank ℤ S = d ∧ ∀ a ∈ A, a - v ∈ S := by
existsi FiniteDimensional.finrank ℤ (⊤ : Submodule ℤ G), ⊤, 0
refine ⟨rfl, fun a _ ↦ trivial⟩
/-- The dimension of the affine span over `ℤ` of a subset of an additive group. -/
noncomputable def dimension (A : Set G) : ℕ := Nat.find (exists_coset_cover A)
lemma dimension_le_of_coset_cover (A : Set G) (S : Submodule ℤ G) (v : G)
(hA : ∀ a ∈ A, a - v ∈ S) : dimension A ≤ FiniteDimensional.finrank ℤ S := by
apply Nat.find_le
existsi S , v
exact ⟨rfl, hA⟩
lemma dimension_le_rank [Module.Finite ℤ G] (A : Set G) :
dimension A ≤ FiniteDimensional.finrank ℤ G := by
obtain ⟨S, v, hs, _⟩ := Nat.find_spec (exists_coset_cover A)
rw [dimension, ←hs]
apply Submodule.finrank_le S
end dim
variable {G : Type u} [AddCommGroup G] [Module.Free ℤ G] [Module.Finite ℤ G] [Countable G] [MeasurableSpace G] [MeasurableSingletonClass G]
open Real MeasureTheory ProbabilityTheory Pointwise Set
/-- Move to Mathlib? `Finsupp.mapRange` of a surjective function is surjective. -/
lemma Finsupp.mapRange_surjective {α : Type u_1} {M : Type u_5} {N : Type u_7} [Zero M] [Zero N] (f : M → N) (hf : f 0 = 0)
(hs : Function.Surjective f) : Function.Surjective (Finsupp.mapRange (α := α) f hf) := by
classical
let g (n : N) : M := if n = 0 then 0 else Function.surjInv hs n
have : Function.RightInverse g f := by
intro n
by_cases h : n = 0
. simp [g, h, hf]
· simp [g, h, Function.surjInv_eq hs n]
have hg : g 0 = 0 := by simp [g]
have hfg : (f ∘ g) 0 = 0 := by simp [hf, hg]
intro F
use Finsupp.mapRange g hg F
rw [← Finsupp.mapRange_comp (h := hfg)]
convert Finsupp.mapRange_id F
convert Function.RightInverse.id this
/-- A free Z-module is torsion-free. Move to Mathlib? -/
lemma torsion_free : AddMonoid.IsTorsionFree G := by
rintro x hx hn
rw [isOfFinAddOrder_iff_nsmul_eq_zero] at hn
rcases hn with ⟨ n, hn, hn' ⟩
apply_fun Module.Free.repr ℤ G at hn'
simp_rw [map_nsmul, map_zero, smul_eq_zero, AddEquivClass.map_eq_zero_iff, hx, or_false] at hn'
linarith
/-- If G is a rank n free Z-module, then G/2G is a finite elementary 2-group of cardinality 2^n. Code is slow, needs to be golfed -/
lemma weak_PFR_quotient_prelim :
let H := G ⧸ (AddMonoidHom.range (zsmulAddGroupHom 2))
ElementaryAddCommGroup H 2 ∧ Finite H ∧ Nat.card H = 2^(FiniteDimensional.finrank ℤ G) := by
set ψ : G →+ G := zsmulAddGroupHom 2
set G₂ := AddMonoidHom.range ψ
set H := G ⧸ G₂
set φ : G →+ H := QuotientAddGroup.mk' G₂
have hH_elem : ElementaryAddCommGroup H 2 := by
apply ElementaryAddCommGroup.quotient_group (by decide)
intro x; rw [AddMonoidHom.mem_range]
use x
rw [zsmulAddGroupHom_apply]
norm_cast
let B := Module.Free.ChooseBasisIndex ℤ G
let bG : Basis B ℤ G := Module.Free.chooseBasis ℤ G
have hB_fin : Fintype B := by infer_instance
have hB_card : Nat.card B = FiniteDimensional.finrank ℤ G := by
rw [FiniteDimensional.finrank_eq_card_basis bG, Nat.card_eq_fintype_card]
have hH_module : Module (ZMod 2) H := by infer_instance
let mod : (B →₀ ℤ) →+ (B →₀ ZMod 2) := Finsupp.mapRange.addMonoidHom (Int.castAddHom (ZMod 2))
let f : G →+ (B →₀ ℤ) := bG.repr
have hker : G₂ ≤ AddMonoidHom.ker (AddMonoidHom.comp mod f) := by
intro x hx
simp only [AddMonoidHom.mem_range, G₂, ψ, zsmulAddGroupHom_apply] at hx
simp_rw [AddMonoidHom.mem_ker, AddMonoidHom.coe_comp, Function.comp_apply, mod,
Finsupp.mapRange.addMonoidHom_apply, Int.coe_castAddHom]
rcases hx with ⟨y, rfl⟩
ext b
simp_rw [map_zsmul, Finsupp.mapRange_apply, Finsupp.coe_smul, Pi.smul_apply, smul_eq_mul,
Int.cast_mul, Int.cast_ofNat, Finsupp.coe_zero, Pi.zero_apply, mul_eq_zero]
left
exact ZMod.nat_cast_self 2
let g : H →+ (B →₀ ZMod 2) := QuotientAddGroup.lift G₂ (AddMonoidHom.comp mod f) hker
have hsur : Function.Surjective g := by
have h1 : Function.Surjective mod := Finsupp.mapRange_surjective (Int.castAddHom (ZMod 2)) (map_zero _) ZMod.int_cast_surjective
have h2 := h1.comp bG.repr.surjective
have h3 : mod ∘ bG.repr = g ∘ (QuotientAddGroup.mk' G₂) := by
ext x b
simp_rw [mod, Function.comp_apply, Finsupp.mapRange.addMonoidHom_apply, Int.coe_castAddHom,
Finsupp.mapRange_apply, QuotientAddGroup.coe_mk', g]
rw [QuotientAddGroup.lift_mk]
simp [mod, f]
rw [h3] at h2
apply Function.Surjective.of_comp h2
have hinj : Function.Injective g := by
rw [injective_iff_map_eq_zero]
intro x hx
rcases QuotientAddGroup.mk'_surjective G₂ x with ⟨y, rfl⟩
simp only [QuotientAddGroup.mk'_apply, g] at hx
rw [QuotientAddGroup.lift_mk] at hx
simp_rw [AddMonoidHom.coe_comp, Function.comp_apply, mod, Finsupp.mapRange.addMonoidHom_apply,
Int.coe_castAddHom, DFunLike.ext_iff,Finsupp.mapRange_apply, Finsupp.coe_zero, Pi.zero_apply,
ZMod.int_cast_zmod_eq_zero_iff_dvd] at hx
replace hx := fun x ↦ Int.mul_ediv_cancel' (hx x)
let z (b : B) := ((Module.Free.chooseBasis ℤ G).repr y) b / 2
let z' := (Finsupp.equivFunOnFinite).symm z
change ∀ b : B, 2 * z' b = (f y) b at hx
let x' := bG.repr.symm z'
rw [QuotientAddGroup.mk'_apply, QuotientAddGroup.eq_zero_iff, AddMonoidHom.mem_range]
simp_rw [ψ, zsmulAddGroupHom_apply]
use x'
change 2 • (bG.repr.symm.toLinearMap.toAddMonoidHom z') = y
rw [← AddMonoidHom.map_zsmul bG.repr.symm.toLinearMap.toAddMonoidHom z' (2 : ℤ)]
rw [← LinearEquiv.symm_apply_apply bG.repr y]
change bG.repr.symm (2 • z') = bG.repr.symm (f y)
congr
ext b
rw [Finsupp.smul_apply, ← hx b, smul_eq_mul]
rcases Function.bijective_iff_has_inverse.mp ⟨ hinj, hsur ⟩ with ⟨ g', hg' ⟩
have bH : Basis B (ZMod 2) H := by
constructor
exact {
toFun := g
invFun := g'
left_inv := hg'.1
right_inv := hg'.2
map_add' := AddMonoidHom.map_add _
map_smul' := by
intro r x
rcases ZMod.int_cast_surjective r with ⟨ n, rfl ⟩
change g ((n : ZMod 2) • x) = (n : ZMod 2) • g x
rw [intCast_smul, intCast_smul]
exact AddMonoidHom.map_zsmul g x n
}
have hH_fin : Fintype H := Module.fintypeOfFintype bH
have hH_card : Nat.card H = 2^(FiniteDimensional.finrank ℤ G) := by
rw [Nat.card_eq_fintype_card, Module.card_fintype bH, ← Nat.card_eq_fintype_card (α := B), hB_card]
congr
exact ⟨ hH_elem, Finite.of_fintype H, hH_card ⟩
open QuotientAddGroup
/-- A version of the third isomorphism theorem: if G₂ ≤ G and H' is a subgroup of G⧸G₂, then there is a canonical isomorphism between H⧸H' and G⧸N, where N is the preimage of H' in G. A bit clunky; may be a better way to do this -/
lemma third_iso {G : Type u} [AddCommGroup G] {G₂ : AddSubgroup G} (H' : AddSubgroup (G ⧸ G₂)) :
let H := G ⧸ G₂
let φ : G →+ H := mk' G₂
let N := AddSubgroup.comap φ H'
∃ e : H ⧸ H' ≃+ G ⧸ N, ∀ x : G, e (mk' H' (φ x))= mk' N x := by
set H := G ⧸ G₂
let φ : G →+ H := mk' G₂
let N := AddSubgroup.comap φ H'
have h1 : G₂ ≤ N := by
intro x hx
rw [← eq_zero_iff] at hx
have : φ x = 0 := hx
simp [N, this, AddSubgroup.zero_mem H']
set H'' := AddSubgroup.map (mk' G₂) N
have h2 : H' = H'' := by
change H' = AddSubgroup.map (mk' G₂) N
rw [AddSubgroup.map_comap_eq, AddMonoidHom.range_top_of_surjective _ (mk'_surjective G₂)]
simp
let e1 : H ⧸ H'' ≃+ G ⧸ N := quotientQuotientEquivQuotient _ _ h1
let e2 := quotientAddEquivOfEq h2
set e := e2.trans e1
use e
intro x
convert (quotientQuotientEquivQuotientAux_mk_mk _ _ h1 x) using 1
lemma single {Ω : Type u} [MeasurableSpace Ω] [DiscreteMeasurableSpace Ω] (μ : Measure Ω)
[IsProbabilityMeasure μ] {A : Set Ω} {z : Ω} (hA : μ.real A = 1) (hz : μ.real {z} > 0) :
z ∈ A := by
contrapose! hz
have : Disjoint {z} A := by simp [hz]
replace this := measureReal_union (μ := μ) this (measurableSet_discrete _)
simp [hA] at this
have h := measureReal_mono (μ := μ) (show insert z A ⊆ Set.univ by simp)
simp [this] at h
assumption
/-- Given two non-empty finite subsets A, B of a rank n free Z-module G, there exists a subgroup N and points x, y in G/N such that the fibers Ax, By of A, B over x, y respectively are non-empty, one has the inequality
$$ \log \frac{|A| |B|}{|A_x| |B_y|} ≤ 34 (d[U_A; U_B] - d[U_{A_x}; U_{B_y}])$$
and one has the dimension bound
$$ n \log 2 ≤ \log |G/N| + 40 d[U_A; U_B].$$
-/
lemma weak_PFR_asymm_prelim (A B : Set G) [Finite A] [Finite B] (hnA : A.Nonempty) (hnB : B.Nonempty):
∃ (N : AddSubgroup G) (x y : G ⧸ N) (Ax By : Set G), Ax.Nonempty ∧ By.Nonempty ∧
Set.Finite Ax ∧ Set.Finite By ∧ Ax = {z:G | z ∈ A ∧ QuotientAddGroup.mk' N z = x } ∧
By = {z:G | z ∈ B ∧ QuotientAddGroup.mk' N z = y } ∧
(log 2) * FiniteDimensional.finrank ℤ G ≤ log (Nat.card (G ⧸ N)) +
40 * dᵤ[ A # B ] ∧ log (Nat.card A) + log (Nat.card B) - log (Nat.card Ax) - log (Nat.card By)
≤ 34 * (dᵤ[ A # B ] - dᵤ[ Ax # By ]) := by
have : Nonempty A := hnA.to_subtype
have : Nonempty B := hnB.to_subtype
obtain ⟨ h_elem, h_finite, h_card ⟩ := weak_PFR_quotient_prelim (G := G)
set ψ : G →+ G := zsmulAddGroupHom 2
set G₂ := AddMonoidHom.range ψ
set H := G ⧸ G₂
let φ : G →+ H := QuotientAddGroup.mk' G₂
let _mH : MeasurableSpace H := ⊤
have h_fintype : Fintype H := Fintype.ofFinite H
have h_torsionfree := torsion_free (G := G)
obtain ⟨ Ω, mΩ, UA, hμ, hUA_mes, hUA_unif, hUA_mem, hUA_fin ⟩ := exists_isUniform_measureSpace' A
obtain ⟨ Ω', mΩ', UB, hμ', hUB_mes, hUB_unif, hUB_mem, hUB_fin ⟩ :=
exists_isUniform_measureSpace' B
rcases (PFR_projection (φ.toFun ∘ UA) (φ.toFun ∘ UB) ℙ ℙ (by measurability) (by measurability)) with ⟨H', ⟨ hH1, hH2 ⟩ ⟩
let N := AddSubgroup.comap φ H'
set φ' := QuotientAddGroup.mk' N
have _cGN : Countable (G ⧸ N) := Function.Surjective.countable (QuotientAddGroup.mk'_surjective N)
have _msGN : MeasurableSingletonClass (G ⧸ N) := by
constructor
intro x
exact MeasurableSpace.map_def.mpr (measurableSet_discrete _)
rcases third_iso H' with ⟨ e : H ⧸ H' ≃+ G ⧸ N, he ⟩
rcases single_fibres φ' hnA hnB hUA_mes hUB_mes hUA_unif hUB_unif hUA_mem hUB_mem with
⟨x, y, Ax, By, hAx, hBy, hnAx, hnBy, hcard_ineq⟩
have : Nonempty Ax := hnAx.to_subtype
have : Nonempty By := hnBy.to_subtype
have Axf : Finite Ax := by rw [hAx]; infer_instance
have Byf : Finite By := by rw [hBy]; infer_instance
have h1 := torsion_dist_shrinking UA UB ℙ ℙ hUA_mes hUB_mes h_torsionfree φ
have h2 := torsion_dist_shrinking UB UA ℙ ℙ hUB_mes hUA_mes h_torsionfree φ
rw [rdist_symm] at h2
rw [<- rdist_set_eq_rdist hμ hμ' hUA_unif hUB_unif hUA_mes hUB_mes] at h1 h2
-- using explicit .toFun casts as this saves a lot of heartbeats
change H[φ.toFun ∘ UA] ≤ 10 * dᵤ[A # B] at h1
change H[φ.toFun ∘ UB] ≤ 10 * dᵤ[A # B] at h2
replace hH1 : log (Nat.card H') ≤ 40 * dᵤ[A # B] := by
apply hH1.trans
linarith
replace h_card : log 2 * FiniteDimensional.finrank ℤ G ≤ log (Nat.card (G ⧸ N)) + 40 * dᵤ[A # B] := by
rw [mul_comm, ← log_rpow (by norm_num)]
norm_cast
classical
rwa [← h_card, ← Nat.card_congr e.toEquiv, Nat.card_eq_fintype_card, Nat.card_eq_fintype_card, ← AddSubgroup.index_mul_card H', AddSubgroup.index_eq_card, Nat.cast_mul, log_mul, add_le_add_iff_left, ← Nat.card_eq_fintype_card]
all_goals norm_cast; exact Fintype.card_ne_zero
use N, x, y, Ax, By
refine ⟨ hnAx, hnBy, Ax.toFinite, By.toFinite, hAx, hBy, h_card, ?_ ⟩
replace hH2 : H[φ'.toFun ∘ UA] + H[φ'.toFun ∘ UB] ≤ 34 * d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] := by
set X := ((mk' H').toFun ∘ φ.toFun) ∘ UA
set Y := ((mk' H').toFun ∘ φ.toFun) ∘ UB
have hX : Measurable X := Measurable.comp (measurable_discrete _) hUA_mes
have hY : Measurable Y := Measurable.comp (measurable_discrete _) hUB_mes
change H[X] + H[Y] ≤ 34 * d[X # Y] at hH2
have ha : φ'.toFun ∘ UA = e.toFun ∘ X := by ext x; exact (he (UA x)).symm
have hb : φ'.toFun ∘ UB = e.toFun ∘ Y := by ext x; exact (he (UB x)).symm
have he_inj : Function.Injective e.toFun := AddEquiv.injective e
rw [ha, hb, entropy_comp_of_injective _ hX _ he_inj, entropy_comp_of_injective _ hY _ he_inj]
have : d[e.toFun ∘ X # e.toFun ∘ Y] = d[X # Y] := rdist_of_inj hX hY e.toAddMonoidHom he_inj
rwa [this]
set X : Ω → G ⧸ N := φ'.toFun ∘ UA
set Y : Ω' → G ⧸ N := φ'.toFun ∘ UB
have hX : Measurable X := Measurable.comp (measurable_discrete _) hUA_mes
have hY : Measurable Y := Measurable.comp (measurable_discrete _) hUB_mes
rcases le_iff_lt_or_eq.mp (rdist_nonneg (μ := ℙ) (μ' := ℙ) hX hY) with h | h
swap
. rw [← h] at hH2
have hH2A : H[X] ≥ 0 := entropy_nonneg _ _
have hH2B : H[Y] ≥ 0 := entropy_nonneg _ _
have hH2A' : H[X] ≤ 0 := by linarith only [hH2, hH2A, hH2B]
have hH2B' : H[Y] ≤ 0 := by linarith only [hH2, hH2A, hH2B]
rcases const_of_nonpos_entropy (μ := ℙ) hX hH2A' with ⟨ x', hx ⟩
rcases const_of_nonpos_entropy (μ := ℙ) hY hH2B' with ⟨ y', hy ⟩
have hAAx {z : G} (hz : z ∈ A) : φ'.toFun z = x' := by
change (ℙ).real (UA⁻¹' (φ'⁻¹' {x'})) = 1 at hx
rw [← MeasureTheory.map_measureReal_apply hUA_mes (measurableSet_discrete _)] at hx
set Af := A.toFinite.toFinset
have hUAf : IsUniform Af UA := by
convert hUA_unif; simp only [Af, Set.Finite.coe_toFinset]
have hnAf : 0 < Nat.card Af := by simp only [Af, Set.Finite.mem_toFinset, Nat.card_pos]
have hzf : z ∈ Af := by simp [Af, Set.Finite.mem_toFinset, hz]
have : (Measure.map UA ℙ).real {z} > 0 := by
rw [IsUniform.measureReal_preimage_of_mem' hUAf hUA_mes hzf]
positivity
have _ : IsProbabilityMeasure ((ℙ).map UA) := by
exact MeasureTheory.isProbabilityMeasure_map (Measurable.aemeasurable hUA_mes)
replace this := single ((ℙ).map UA) hx this
rwa [Set.mem_preimage, Set.mem_singleton_iff] at this
have hxx : Ax = A := by
have h : hnAx.some ∈ Ax := hnAx.some_mem
simp [hAx] at h ⊢
have := hAAx h.1
simp [h.2] at this
intro z hz
simp [this]
convert hAAx hz
have hBBy {z : G} (hz : z ∈ B) : φ'.toFun z = y' := by
change (ℙ).real (UB⁻¹' (φ'⁻¹' {y'})) = 1 at hy
rw [← MeasureTheory.map_measureReal_apply hUB_mes (measurableSet_discrete _)] at hy
set Bf := B.toFinite.toFinset
have hUBf : IsUniform Bf UB := by convert hUB_unif; simp only [Bf, Set.Finite.coe_toFinset]
have hnBf : 0 < Nat.card Bf := by simp only [Bf, Set.Finite.mem_toFinset, Nat.card_pos]
have hzf : z ∈ Bf := by simp [Bf, Set.Finite.mem_toFinset, hz]
have : (Measure.map UB ℙ).real {z} > 0 := by
rw [IsUniform.measureReal_preimage_of_mem' hUBf hUB_mes hzf]
positivity
have _ : IsProbabilityMeasure ((ℙ).map UB) := by
exact MeasureTheory.isProbabilityMeasure_map (Measurable.aemeasurable hUB_mes)
replace this := single ((ℙ).map UB) hy this
rwa [Set.mem_preimage, Set.mem_singleton_iff] at this
have hyy : By = B := by
have h : hnBy.some ∈ By := hnBy.some_mem
simp [hBy] at h ⊢
have := hBBy h.1
simp [h.2] at this
intro z hz
simp [this]
convert hBBy hz
simp [hxx, hyy]
have := calc d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] * (log (Nat.card A) + log (Nat.card B) - log (Nat.card Ax) - log (Nat.card By))
_ = d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] * log ((Nat.card A) * (Nat.card B) / ((Nat.card Ax) * (Nat.card By))) := by
congr
convert (four_logs ?_ ?_ ?_ ?_).symm
all_goals norm_cast; exact Nat.card_pos
_ ≤ (H[φ'.toFun ∘ UA] + H[φ'.toFun ∘ UB]) * (d[UA # UB] - dᵤ[Ax # By]) := hcard_ineq
_ ≤ (34 * d[φ'.toFun ∘ UA # φ'.toFun ∘ UB]) * (d[UA # UB] - dᵤ[Ax # By]) := by
apply mul_le_mul_of_nonneg_right hH2
have := rdist_le_avg_ent (Measurable.comp (measurable_discrete φ'.toFun) hUA_mes) (Measurable.comp (measurable_discrete φ'.toFun) hUB_mes)
replace this : 0 < H[φ'.toFun ∘ UA] + H[φ'.toFun ∘ UB] := by linarith
rw [← mul_le_mul_left this]
apply le_trans _ hcard_ineq
rw [mul_zero]
change 0 ≤ d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] * log ((Nat.card A) * (Nat.card B) / ((Nat.card Ax) * (Nat.card By)))
rw [← mul_zero d[φ'.toFun ∘ UA # φ'.toFun ∘ UB], mul_le_mul_left h]
apply Real.log_nonneg
rw [one_le_div]
gcongr
. apply Nat.card_mono
. exact Set.toFinite A
rw [hAx]; exact Set.inter_subset_left _ _
apply Nat.card_mono
. exact Set.toFinite B
rw [hBy]; exact Set.inter_subset_left _ _
norm_cast
exact mul_pos Nat.card_pos Nat.card_pos
_ = d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] * (34 * (d[UA # UB] - dᵤ[Ax # By])) := by ring
_ = d[φ'.toFun ∘ UA # φ'.toFun ∘ UB] * (34 * (dᵤ[A # B] - dᵤ[Ax # By])) := by
rw [<- rdist_set_eq_rdist hμ hμ' hUA_unif hUB_unif hUA_mes hUB_mes]
exact (mul_le_mul_left h).mp this
/-- Separating out the conclusion of `weak_PFR_asymm` for convenience of induction arguments.-/
def WeakPFRAsymmConclusion (A B : Set G) : Prop :=
∃ A' B' : Set G, A' ⊆ A ∧ B' ⊆ B ∧ A'.Nonempty ∧ B'.Nonempty ∧
log (((Nat.card A) * (Nat.card B)) / ((Nat.card A') * (Nat.card B'))) ≤ 34 * dᵤ[A # B] ∧
max (dimension A') (dimension B') ≤ (40 / log 2) * dᵤ[A # B]
/-- The property of two sets A,B of a group G not being contained in cosets of the same proper subgroup -/
def not_in_coset {G: Type u} [AddCommGroup G] (A B : Set G) : Prop := AddSubgroup.closure ((A-A) ∪ (B-B)) = ⊤
/-- In fact one has equality here, but this is tricker to prove and not needed for the argument. -/
lemma dimension_of_shift {G: Type u} [AddCommGroup G]
{H: AddSubgroup G} (A : Set H) (x : G) :
dimension ((fun a:H ↦ (a:G) + x) '' A) ≤ dimension A := by
classical
rcases Nat.find_spec (exists_coset_cover A) with ⟨ S, v, hrank, hshift ⟩
change FiniteDimensional.finrank ℤ S = dimension A at hrank
rw [← hrank]
convert dimension_le_of_coset_cover _ (Submodule.map H.subtype.toIntLinearMap S) (x+v) ?_
. apply LinearEquiv.finrank_eq
exact Submodule.equivMapOfInjective _ (by simpa using Subtype.val_injective) _
intro a ha
rw [Set.mem_image] at ha
rcases ha with ⟨ b, ⟨ hb, hb'⟩ ⟩
rw [Submodule.mem_map]
use b - v, hshift b hb
simp [← hb']
abel
lemma conclusion_transfers {A B : Set G}
(G': AddSubgroup G) (A' B' : Set G')
(hA : IsShift A A') (hB : IsShift B B') [Finite A'] [Finite B'] (hA' : A'.Nonempty) (hB' : B'.Nonempty)
(h : WeakPFRAsymmConclusion A' B') : WeakPFRAsymmConclusion A B := by
have : Nonempty A' := hA'.to_subtype
have : Nonempty B' := hB'.to_subtype
rcases h with ⟨A'', B'', hA'', hB'', hA''_non, hB''_non, hcard_ineq, hdim_ineq⟩
rcases hA with ⟨ x, hA ⟩
set f : G' → G := fun a ↦ (a : G) + x
have hf : Function.Injective f := by
intro y z hyz
simp [f] at hyz
exact hyz
have hA' : A = f '' A' := by
simp_rw [hA, ← Set.image_vadd, Set.image_image, vadd_eq_add, f, add_comm]; rfl
rcases hB with ⟨ y, hB ⟩
set g : G' → G := fun a ↦ (a : G) + y
have hg : Function.Injective g := by
intro y z hyz
simp [g] at hyz
exact hyz
have hB' : B = g '' B' := by
simp_rw [hB, ← Set.image_vadd, Set.image_image, vadd_eq_add, g, add_comm]; rfl
use f '' A'', g '' B''
have : dᵤ[A # B] = dᵤ[A' # B'] := by
rw [<-rdist_set_of_inj _ _ (φ := G'.subtype) Subtype.val_injective, <-rdist_set_add_const (G'.subtype '' A') (G'.subtype '' B') x y]
congr
. rw [hA]
ext y
simp [Set.mem_vadd_set]
constructor
. rintro ⟨ z, ⟨ ⟨ w, hw ⟩, rfl ⟩ ⟩
have : x + z + -x ∈ G' := by simp [w]
use this
simp
convert hw
rintro ⟨ h, ha ⟩
use y + -x
constructor
. use h
abel
rw [hB]
ext x
simp [Set.mem_vadd_set]
constructor
. rintro ⟨ z, ⟨ ⟨ w, hw ⟩, rfl ⟩ ⟩
have : y + z + -y ∈ G' := by simp [w]
use this
simp
convert hw
rintro ⟨ h, ha ⟩
use x + -y
constructor
. use h
abel
refine ⟨ ?_, ?_, ?_, ?_, ?_, ?_ ⟩
. simp [hA', hf, hA'']
. simp [hB', hg, hB'']
. simp [hA''_non]
. simp [hB''_non]
. convert hcard_ineq using 2
. congr 3
. rw [hA', Nat.card_image_of_injective hf]
. rw [hB', Nat.card_image_of_injective hg]
. rw [Nat.card_image_of_injective hf]
rw [Nat.card_image_of_injective hg]
convert LE.le.trans _ hdim_ineq using 2
norm_cast
apply max_le_max
. exact dimension_of_shift A'' x
· exact dimension_of_shift B'' y
/-- If $A,B\subseteq \mathbb{Z}^d$ are finite non-empty sets then there exist non-empty $A'\subseteq A$ and $B'\subseteq B$ such that
\[\log\frac{\lvert A\rvert\lvert B\rvert}{\lvert A'\rvert\lvert B'\rvert}\leq 34 d[U_A;U_B]\]
such that $\max(\dim A',\dim B')\leq \frac{40}{\log 2} d[U_A;U_B]$. -/
lemma weak_PFR_asymm (A B : Set G) [Finite A] [Finite B] (hA : A.Nonempty) (hB : B.Nonempty) : WeakPFRAsymmConclusion A B := by
let P : ℕ → Prop := fun M ↦ (∀ (G : Type u) (hG_comm : AddCommGroup G) (_hG_free : Module.Free ℤ G) (_hG_fin : Module.Finite ℤ G) (_hG_count : Countable G) (hG_mes : MeasurableSpace G) (_hG_sing: MeasurableSingletonClass G) (A B: Set G) (_hA_fin: Finite A) (_hB_fin: Finite B) (_hA_non: A.Nonempty) (_hB_non: B.Nonempty) (_hM : (Nat.card A) + (Nat.card B) ≤ M), WeakPFRAsymmConclusion A B)
suffices ∀ M, (∀ M', M' < M → P M') → P M by
set M := (Nat.card A) + (Nat.card B)
have hM : (Nat.card A) + (Nat.card B) ≤ M := Nat.le_refl _
convert (Nat.strong_induction_on (p := P) M this) G ‹_› ‹_› ‹_› ‹_› _ ‹_› A B ‹_› ‹_› ‹_› ‹_› hM
intro M h_induct
-- wlog we can assume A, B are not in cosets of a smaller subgroup
suffices ∀ (G : Type u) (hG_comm : AddCommGroup G) (_hG_free : Module.Free ℤ G)
(_hG_fin : Module.Finite ℤ G) (_hG_count : Countable G) (hG_mes : MeasurableSpace G)
(_hG_sing : MeasurableSingletonClass G) (A B : Set G) (_hA_fin : Finite A) (_hB_fin : Finite B) (_hA_non : A.Nonempty) (_hB_non : B.Nonempty) (_hM : Nat.card A + Nat.card B ≤ M)
(_hnot : NotInCoset A B), WeakPFRAsymmConclusion A B by
intro G hG_comm hG_free hG_fin hG_count hG_mes hG_sing A B hA_fin hB_fin hA_non hB_non hM
obtain ⟨ G', A', B', hAA', hBB', hnot' ⟩ := wlog_notInCoset hA_non hB_non
have hG'_fin : Module.Finite ℤ G' :=
Module.Finite.iff_fg (N := AddSubgroup.toIntSubmodule G').2 (IsNoetherian.noetherian _)
have hG'_free : Module.Free ℤ G' := by
rcases Submodule.nonempty_basis_of_pid (Module.Free.chooseBasis ℤ G) (AddSubgroup.toIntSubmodule G') with ⟨ n, ⟨ b ⟩ ⟩
exact Module.Free.of_basis b
have hAA'_card: Nat.card A = Nat.card A' := (Nat.card_image_of_injective Subtype.val_injective _) ▸ hAA'.card_congr
have hBB'_card: Nat.card B = Nat.card B' := (Nat.card_image_of_injective Subtype.val_injective _) ▸ hBB'.card_congr
have hA_non' : Nonempty A := Set.nonempty_coe_sort.mpr hA_non
have hB_non' : Nonempty B := Set.nonempty_coe_sort.mpr hB_non
rw [hAA'_card, hBB'_card] at hM
have hA'_nonfin : A'.Nonempty ∧ Finite A' := by
have := Nat.card_pos (α := A)
rw [hAA'_card, Nat.card_pos_iff] at this
exact ⟨@nonempty_of_nonempty_subtype _ _ this.1, this.2⟩
have hB'_nonfin : B'.Nonempty ∧ Finite B' := by
have := Nat.card_pos (α := B)
rw [hBB'_card, Nat.card_pos_iff] at this
exact ⟨@nonempty_of_nonempty_subtype _ _ this.1, this.2⟩
obtain ⟨ hA'_non, hA'_fin ⟩ := hA'_nonfin
obtain ⟨ hB'_non, hB'_fin ⟩ := hB'_nonfin
replace this := this G' _ hG'_free hG'_fin (by infer_instance) (by infer_instance) (by infer_instance) A' B' hA'_fin hB'_fin hA'_non hB'_non hM hnot'
exact conclusion_transfers G' A' B' hAA' hBB' hA'_non hB'_non this
intro G hG_comm hG_free hG_fin hG_count hG_mes hG_sing A B hA_fin hB_fin hA_non hB_non hM hnot
rcases weak_PFR_asymm_prelim A B hA_non hB_non with ⟨ N, x, y, Ax, By, hAx_non, hBy_non, hAx_fin, hBy_fin, hAx, hBy, hdim, hcard⟩
have hAxA : Ax ⊆ A := by rw [hAx]; simp
have hByB : By ⊆ B := by rw [hBy]; simp
have hA_pos : (0 : ℝ) < Nat.card A := Nat.cast_pos.mpr (@Nat.card_pos _ hA_non.to_subtype _)
have hB_pos : (0 : ℝ) < Nat.card B := Nat.cast_pos.mpr (@Nat.card_pos _ hB_non.to_subtype _)
rcases lt_or_ge (Nat.card Ax + Nat.card By) (Nat.card A + Nat.card B) with h | h
. replace h := h_induct (Nat.card Ax + Nat.card By) (h.trans_le hM) G hG_comm hG_free hG_fin hG_count hG_mes hG_sing Ax By (Set.finite_coe_iff.mpr hAx_fin) (Set.finite_coe_iff.mpr hBy_fin) hAx_non hBy_non (Eq.le rfl)
rcases h with ⟨ A', B', hA', hB', hA'_non, hB'_non, hcard_ineq, hdim_ineq ⟩
use A', B'
have hAx_fin' := Set.finite_coe_iff.mpr hAx_fin
have hBy_fin' := Set.finite_coe_iff.mpr hBy_fin
have hA'_fin' := Set.finite_coe_iff.mpr (Set.Finite.subset hAx_fin hA')
have hB'_fin' := Set.finite_coe_iff.mpr (Set.Finite.subset hBy_fin hB')
have hAx_non' := Set.nonempty_coe_sort.mpr hAx_non
have hBy_non' := Set.nonempty_coe_sort.mpr hBy_non
have hA'_non' := Set.nonempty_coe_sort.mpr hA'_non
have hB'_non' := Set.nonempty_coe_sort.mpr hB'_non
have hAx_pos : (0 : ℝ) < Nat.card Ax := Nat.cast_pos.mpr Nat.card_pos
have hBy_pos : (0 : ℝ) < Nat.card By := Nat.cast_pos.mpr Nat.card_pos
have hA'_pos : (0 : ℝ) < Nat.card A' := Nat.cast_pos.mpr Nat.card_pos
have hB'_pos : (0 : ℝ) < Nat.card B' := Nat.cast_pos.mpr Nat.card_pos
have hAxA_le : (Nat.card Ax : ℝ) ≤ (Nat.card A : ℝ) := Nat.cast_le.mpr (Nat.card_mono A.toFinite hAxA)
have hByB_le : (Nat.card By : ℝ) ≤ (Nat.card B : ℝ) := Nat.cast_le.mpr (Nat.card_mono B.toFinite hByB)
refine ⟨ hA'.trans hAxA, hB'.trans hByB, hA'_non, hB'_non, ?_, ?_ ⟩
. rw [four_logs hA_pos hB_pos hA'_pos hB'_pos]
rw [four_logs hAx_pos hBy_pos hA'_pos hB'_pos] at hcard_ineq
linarith only [hcard, hcard_ineq]
apply hdim_ineq.trans
gcongr
linarith only [Real.log_le_log hAx_pos hAxA_le, Real.log_le_log hBy_pos hByB_le, hcard]
use A, B
refine ⟨ Eq.subset rfl, Eq.subset rfl, hA_non, hB_non, ?_, ?_ ⟩
. have := hA_non.to_subtype
have := hB_non.to_subtype
apply LE.le.trans _ <| mul_nonneg (by norm_num) <| rdist_set_nonneg A B
rw [div_self (by positivity)]
simp
have hAx_eq : Ax = A := by
apply Set.Finite.eq_of_subset_of_card_le A.toFinite hAxA
linarith only [h, Nat.card_mono B.toFinite hByB]
have hBy_eq : By = B := by
apply Set.Finite.eq_of_subset_of_card_le B.toFinite hByB
linarith only [h, Nat.card_mono A.toFinite hAxA]
have hN : N = ⊤ := by
have : (A-A) ∪ (B-B) ⊆ N := by
rw [← hAx_eq, ← hBy_eq, hAx, hBy]
intro z hz
simp [Set.mem_sub] at hz
convert (QuotientAddGroup.eq_zero_iff z).mp ?_
. infer_instance
rcases hz with ⟨ a, ⟨ -, ha⟩, a', ⟨-, ha'⟩, haa' ⟩ | ⟨ b, ⟨ -, hb⟩, b', ⟨ -,hb'⟩, hbb' ⟩
. rw [← haa']; simp [ha, ha']
rw [← hbb']; simp [hb, hb']
rw [← AddSubgroup.closure_le, hnot] at this
exact top_le_iff.mp this
have : Nat.card (G ⧸ N) = 1 := by
rw [Nat.card_eq_one_iff_unique]
constructor
. rw [hN]
exact QuotientAddGroup.subsingleton_quotient_top
infer_instance
simp [this] at hdim
rw [← le_div_iff' (by positivity)] at hdim
convert LE.le.trans ?_ hdim using 1
. field_simp
simp
exact ⟨ dimension_le_rank A, dimension_le_rank B ⟩
/-- If $A\subseteq \mathbb{Z}^d$ is a finite non-empty set with $d[U_A;U_A]\leq \log K$ then there exists a non-empty $A'\subseteq A$ such that
$\lvert A'\rvert\geq K^{-17}\lvert A\rvert$
and $\dim A'\leq \frac{40}{\log 2} \log K$. -/
lemma weak_PFR {A : Set G} [Finite A] {K : ℝ} (hA : A.Nonempty) (hK: 0 < K) (hdist: dᵤ[A # A] ≤ log K):
∃ A' : Set G, A' ⊆ A ∧ (Nat.card A') ≥ K^(-17 : ℝ) * (Nat.card A)
∧ (dimension A') ≤ (40 / log 2) * log K := by
rcases weak_PFR_asymm A A hA hA with ⟨A', A'', hA', hA'', hA'nonempty, hA''nonempty, hcard, hdim⟩
have : ∃ B : Set G, B ⊆ A ∧ (Nat.card B) ≥ (Nat.card A') ∧ (Nat.card B) ≥ (Nat.card A'') ∧ (dimension B) ≤
max (dimension A') (dimension A'') := by
rcases lt_or_ge (Nat.card A') (Nat.card A'') with h | h
. use A''
exact ⟨hA'', by linarith, by linarith, le_max_right _ _⟩
use A'
exact ⟨hA', by linarith, by linarith, le_max_left _ _⟩
rcases this with ⟨B, hB, hBcard, hBcard', hBdim⟩
use B
have hApos : Nat.card A > 0 := by
rw [gt_iff_lt, Nat.card_pos_iff]
exact ⟨hA.to_subtype, inferInstance⟩
have hA'pos : Nat.card A' > 0 := by
rw [gt_iff_lt, Nat.card_pos_iff]
refine ⟨ hA'nonempty.to_subtype, Finite.Set.subset _ hA' ⟩
have hA''pos : Nat.card A'' > 0 := by
rw [gt_iff_lt, Nat.card_pos_iff]
refine ⟨ hA''nonempty.to_subtype, Finite.Set.subset _ hA'' ⟩
have hBpos : Nat.card B > 0 := by linarith
refine ⟨hB, ?_, ?_⟩
. have := calc 2 * log ((Nat.card A) / (Nat.card B))
_ = log ( ((Nat.card A) * (Nat.card A)) / ((Nat.card B) * (Nat.card B)) ) := by
convert (log_pow (((Nat.card A) : ℝ)/(Nat.card B)) 2).symm
field_simp
rw [← pow_two, ← pow_two]
_ ≤ log ( ((Nat.card A) * (Nat.card A)) / ((Nat.card A') * (Nat.card A'')) ) := by
apply log_le_log
. positivity
gcongr
_ ≤ 34 * dᵤ[A # A] := hcard
_ ≤ 34 * log K := mul_le_mul_of_nonneg_left hdist (by linarith)
_ = 2 * (17 * log K) := by ring
_ = 2 * log (K^17) := by
congr
convert (log_pow K 17).symm
rw [mul_le_mul_left (by norm_num), log_le_log_iff (by positivity) (by positivity), div_le_iff (by positivity), <- mul_inv_le_iff (by positivity), <-ge_iff_le, mul_comm] at this
convert this using 2
convert zpow_neg K 17 using 1
norm_cast
calc (dimension B : ℝ)
_ ≤ (((max (dimension A') (dimension A'')) : ℕ) : ℝ) := by norm_cast
_ ≤ (40 / log 2) * dᵤ[A # A] := hdim
_ ≤ (40 / log 2) * log K := mul_le_mul_of_nonneg_left hdist (by positivity)
/-- Let $A\subseteq \mathbb{Z}^d$ and $\lvert A-A\rvert\leq K\lvert A\rvert$.
There exists $A'\subseteq A$ such that $\lvert A'\rvert \geq K^{-17}\lvert A\rvert$
and $\dim A' \leq \frac{40}{\log 2} \log K$.-/
| theorem weak_PFR_int {A : Set G} [Finite A] (hnA : A.Nonempty) {K : ℝ} (hK : 0 < K)
(hA: Nat.card (A-A) ≤ K * Nat.card A) :
∃ A' : Set G, A' ⊆ A ∧ Nat.card A' ≥ K ^ (-17 : ℝ) * (Nat.card A) ∧
dimension A' ≤ (40 / log 2) * log K | weak_PFR_int | 25309ad 20231211 | c0c547a 20240116 | pfr/PFR/WeakPFR.lean | {
"lineInFile": 1231,
"tokenPositionInFile": 63710,
"theoremPositionInFile": 31
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n apply weak_PFR hnA hK ((rdist_set_le A A hnA hnA).trans _)\n suffices log (Nat.card (A-A)) ≤ log K + log (Nat.card A) by linarith\n rw [← log_mul (by positivity) _]\n . apply log_le_log _ hA\n norm_cast\n have : Nonempty (A-A) := by\n exact Set.Nonempty.coe_sort (Set.Nonempty.sub hnA hnA)\n apply Nat.card_pos\n norm_cast\n apply ne_of_gt (@Nat.card_pos _ hnA.to_subtype _)",
"proofType": "tactic",
"proofLengthLines": 11,
"proofLengthTokens": 389
} | pfr |
import PFR.Fibring
import PFR.TauFunctional
/-!
# First estimate
The first estimate on tau-minimizers.
Assumptions:
* $X_1, X_2$ are tau-minimizers
* $X_1, X_2, \tilde X_1, \tilde X_2$ are independent random variables, with $X_1,\tilde X_1$ copies of $X_1$ and $X_2,\tilde X_2$ copies of $X_2$.
* $k := d[X_1;X_2]$
* $I_1 := I [X_1+X_2 : \tilde X_1 + X_2 | X_1+X_2+\tilde X_1+\tilde X_2]$
## Main results
* `first_estimate` : $I_1 ≤ 2 η k$
* `ent_ofsum_le` : $H[X_1+X_2+\tilde X_1+\tilde X_2] \le \tfrac{1}{2} H[X_1]+\tfrac{1}{2} H[X_2] + (2 + \eta) k - I_1.$
-/
open MeasureTheory ProbabilityTheory
variable {G : Type*} [addgroup: AddCommGroup G] [Fintype G] [hG : MeasurableSpace G]
[MeasurableSingletonClass G] [elem: ElementaryAddCommGroup G 2] [MeasurableAdd₂ G]
variable {Ω₀₁ Ω₀₂ : Type*} [MeasureSpace Ω₀₁] [MeasureSpace Ω₀₂]
[IsProbabilityMeasure (ℙ : Measure Ω₀₁)] [IsProbabilityMeasure (ℙ : Measure Ω₀₂)]
variable (p : refPackage Ω₀₁ Ω₀₂ G)
variable {Ω : Type*} [MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)]
variable (X₁ X₂ X₁' X₂' : Ω → G)
(hX₁ : Measurable X₁) (hX₂ : Measurable X₂) (hX₁' : Measurable X₁') (hX₂' : Measurable X₂')
variable (h₁ : IdentDistrib X₁ X₁') (h₂ : IdentDistrib X₂ X₂')
variable (h_indep : iIndepFun (fun _i => hG) ![X₁, X₂, X₂', X₁'])
variable (h_min: tau_minimizes p X₁ X₂)
/-- `k := d[X₁ # X₂]`, the Ruzsa distance `rdist` between X₁ and X₂. -/
local notation3 "k" => d[X₁ # X₂]
/-- `I₁ := I[X₁ + X₂ : X₁' + X₂ | X₁ + X₂ + X₁' + X₂']`, the conditional mutual information
of `X₁ + X₂` and `X₁' + X₂` given the quadruple sum `X₁ + X₂ + X₁' + X₂'`. -/
local notation3 "I₁" => I[X₁ + X₂ : X₁' + X₂ | X₁ + X₂ + X₁' + X₂']
/-- The sum of
$$ d[X_1+\tilde X_2;X_2+\tilde X_1] + d[X_1|X_1+\tilde X_2; X_2|X_2+\tilde X_1] $$
and
$$ I[X_1+ X_2 : \tilde X_1 + X_2 \,|\, X_1 + X_2 + \tilde X_1 + \tilde X_2] $$
is equal to $2k$. -/
| lemma rdist_add_rdist_add_condMutual_eq : d[X₁ + X₂' # X₂ + X₁'] + d[X₁ | X₁ + X₂' # X₂ | X₂ + X₁']
+ I[X₁ + X₂ : X₁' + X₂ | X₁ + X₂ + X₁' + X₂'] = 2 * k | rdist_add_rdist_add_condMutual_eq | 59160fb 20231116 | 8035e66 20231125 | pfr/PFR/FirstEstimate.lean | {
"lineInFile": 55,
"tokenPositionInFile": 1892,
"theoremPositionInFile": 2
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n have h0 : ![X₁, X₂, X₂', X₁'] 0 = X₁ := rfl\n have h1 : ![X₁, X₂, X₂', X₁'] 1 = X₂ := rfl\n have h2 : ![X₁, X₂, X₂', X₁'] 2 = X₂' := rfl\n have h3 : ![X₁, X₂, X₂', X₁'] 3 = X₁' := rfl\n have h := sum_of_rdist_eq_char_2 ![X₁, X₂, X₂', X₁'] h_indep\n (fun i => by fin_cases i <;> assumption)\n rw [h0, h1, h2, h3] at h\n have heq : d[X₂' # X₁'] = k := by\n rw [rdist_symm]\n apply ProbabilityTheory.IdentDistrib.rdist_eq h₁.symm h₂.symm\n rw [heq] at h\n convert h.symm using 1\n · congr 2 <;> abel\n · ring",
"proofType": "tactic",
"proofLengthLines": 15,
"proofLengthTokens": 516
} | pfr |
import PFR.Fibring
import PFR.TauFunctional
/-!
# First estimate
The first estimate on tau-minimizers.
Assumptions:
* $X_1, X_2$ are tau-minimizers
* $X_1, X_2, \tilde X_1, \tilde X_2$ are independent random variables, with $X_1,\tilde X_1$ copies of $X_1$ and $X_2,\tilde X_2$ copies of $X_2$.
* $k := d[X_1;X_2]$
* $I_1 := I [X_1+X_2 : \tilde X_1 + X_2 | X_1+X_2+\tilde X_1+\tilde X_2]$
## Main results
* `first_estimate` : $I_1 ≤ 2 η k$
* `ent_ofsum_le` : $H[X_1+X_2+\tilde X_1+\tilde X_2] \le \tfrac{1}{2} H[X_1]+\tfrac{1}{2} H[X_2] + (2 + \eta) k - I_1.$
-/
open MeasureTheory ProbabilityTheory
variable {G : Type*} [addgroup: AddCommGroup G] [Fintype G] [hG : MeasurableSpace G]
[MeasurableSingletonClass G] [elem: ElementaryAddCommGroup G 2] [MeasurableAdd₂ G]
variable {Ω₀₁ Ω₀₂ : Type*} [MeasureSpace Ω₀₁] [MeasureSpace Ω₀₂]
[IsProbabilityMeasure (ℙ : Measure Ω₀₁)] [IsProbabilityMeasure (ℙ : Measure Ω₀₂)]
variable (p : refPackage Ω₀₁ Ω₀₂ G)
variable {Ω : Type*} [MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)]
variable (X₁ X₂ X₁' X₂' : Ω → G)
(hX₁ : Measurable X₁) (hX₂ : Measurable X₂) (hX₁' : Measurable X₁') (hX₂' : Measurable X₂')
variable (h₁ : IdentDistrib X₁ X₁') (h₂ : IdentDistrib X₂ X₂')
variable (h_indep : iIndepFun (fun _i => hG) ![X₁, X₂, X₂', X₁'])
variable (h_min: tau_minimizes p X₁ X₂)
/-- `k := d[X₁ # X₂]`, the Ruzsa distance `rdist` between X₁ and X₂. -/
local notation3 "k" => d[X₁ # X₂]
/-- `I₁ := I[X₁ + X₂ : X₁' + X₂ | X₁ + X₂ + X₁' + X₂']`, the conditional mutual information
of `X₁ + X₂` and `X₁' + X₂` given the quadruple sum `X₁ + X₂ + X₁' + X₂'`. -/
local notation3 "I₁" => I[X₁ + X₂ : X₁' + X₂ | X₁ + X₂ + X₁' + X₂']
/-- The sum of
$$ d[X_1+\tilde X_2;X_2+\tilde X_1] + d[X_1|X_1+\tilde X_2; X_2|X_2+\tilde X_1] $$
and
$$ I[X_1+ X_2 : \tilde X_1 + X_2 \,|\, X_1 + X_2 + \tilde X_1 + \tilde X_2] $$
is equal to $2k$. -/
lemma rdist_add_rdist_add_condMutual_eq : d[X₁ + X₂' # X₂ + X₁'] + d[X₁ | X₁ + X₂' # X₂ | X₂ + X₁']
+ I[X₁ + X₂ : X₁' + X₂ | X₁ + X₂ + X₁' + X₂'] = 2 * k := by
have h0 : ![X₁, X₂, X₂', X₁'] 0 = X₁ := rfl
have h1 : ![X₁, X₂, X₂', X₁'] 1 = X₂ := rfl
have h2 : ![X₁, X₂, X₂', X₁'] 2 = X₂' := rfl
have h3 : ![X₁, X₂, X₂', X₁'] 3 = X₁' := rfl
have h := sum_of_rdist_eq_char_2 ![X₁, X₂, X₂', X₁'] h_indep
(fun i => by fin_cases i <;> assumption)
rw [h0, h1, h2, h3] at h
have heq : d[X₂' # X₁'] = k := by
rw [rdist_symm]
apply ProbabilityTheory.IdentDistrib.rdist_eq h₁.symm h₂.symm
rw [heq] at h
convert h.symm using 1
· congr 2 <;> abel
· ring
/-- The distance $d[X_1+\tilde X_2; X_2+\tilde X_1]$ is at least
$$ k - \eta (d[X^0_1; X_1+\tilde X_2] - d[X^0_1; X_1]) - \eta (d[X^0_2; X_2+\tilde X_1] - d[X^0_2; X_2]).$$ -/
| lemma rdist_of_sums_ge :
d[X₁ + X₂' # X₂ + X₁'] ≥
k - p.η * (d[p.X₀₁ # X₁ + X₂'] - d[p.X₀₁ # X₁])
- p.η * (d[p.X₀₂ # X₂ + X₁'] - d[p.X₀₂ # X₂]) | rdist_of_sums_ge | 59160fb 20231116 | f99eb0d 20231123 | pfr/PFR/FirstEstimate.lean | {
"lineInFile": 74,
"tokenPositionInFile": 2747,
"theoremPositionInFile": 3
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "distance_ge_of_min _ h_min (hX₁.add hX₂') (hX₂.add hX₁')",
"proofType": "term",
"proofLengthLines": 1,
"proofLengthTokens": 56
} | pfr |
import PFR.Fibring
import PFR.TauFunctional
/-!
# First estimate
The first estimate on tau-minimizers.
Assumptions:
* $X_1, X_2$ are tau-minimizers
* $X_1, X_2, \tilde X_1, \tilde X_2$ are independent random variables, with $X_1,\tilde X_1$ copies of $X_1$ and $X_2,\tilde X_2$ copies of $X_2$.
* $k := d[X_1;X_2]$
* $I_1 := I [X_1+X_2 : \tilde X_1 + X_2 | X_1+X_2+\tilde X_1+\tilde X_2]$
## Main results
* `first_estimate` : $I_1 ≤ 2 η k$
* `ent_ofsum_le` : $H[X_1+X_2+\tilde X_1+\tilde X_2] \le \tfrac{1}{2} H[X_1]+\tfrac{1}{2} H[X_2] + (2 + \eta) k - I_1.$
-/
open MeasureTheory ProbabilityTheory
variable {G : Type*} [addgroup: AddCommGroup G] [Fintype G] [hG : MeasurableSpace G]
[MeasurableSingletonClass G] [elem: ElementaryAddCommGroup G 2] [MeasurableAdd₂ G]
variable {Ω₀₁ Ω₀₂ : Type*} [MeasureSpace Ω₀₁] [MeasureSpace Ω₀₂]
[IsProbabilityMeasure (ℙ : Measure Ω₀₁)] [IsProbabilityMeasure (ℙ : Measure Ω₀₂)]
variable (p : refPackage Ω₀₁ Ω₀₂ G)
variable {Ω : Type*} [MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)]
variable (X₁ X₂ X₁' X₂' : Ω → G)
(hX₁ : Measurable X₁) (hX₂ : Measurable X₂) (hX₁' : Measurable X₁') (hX₂' : Measurable X₂')
variable (h₁ : IdentDistrib X₁ X₁') (h₂ : IdentDistrib X₂ X₂')
variable (h_indep : iIndepFun (fun _i => hG) ![X₁, X₂, X₂', X₁'])
variable (h_min: tau_minimizes p X₁ X₂)
/-- `k := d[X₁ # X₂]`, the Ruzsa distance `rdist` between X₁ and X₂. -/
local notation3 "k" => d[X₁ # X₂]
/-- `I₁ := I[X₁ + X₂ : X₁' + X₂ | X₁ + X₂ + X₁' + X₂']`, the conditional mutual information
of `X₁ + X₂` and `X₁' + X₂` given the quadruple sum `X₁ + X₂ + X₁' + X₂'`. -/
local notation3 "I₁" => I[X₁ + X₂ : X₁' + X₂ | X₁ + X₂ + X₁' + X₂']
/-- The sum of
$$ d[X_1+\tilde X_2;X_2+\tilde X_1] + d[X_1|X_1+\tilde X_2; X_2|X_2+\tilde X_1] $$
and
$$ I[X_1+ X_2 : \tilde X_1 + X_2 \,|\, X_1 + X_2 + \tilde X_1 + \tilde X_2] $$
is equal to $2k$. -/
lemma rdist_add_rdist_add_condMutual_eq : d[X₁ + X₂' # X₂ + X₁'] + d[X₁ | X₁ + X₂' # X₂ | X₂ + X₁']
+ I[X₁ + X₂ : X₁' + X₂ | X₁ + X₂ + X₁' + X₂'] = 2 * k := by
have h0 : ![X₁, X₂, X₂', X₁'] 0 = X₁ := rfl
have h1 : ![X₁, X₂, X₂', X₁'] 1 = X₂ := rfl
have h2 : ![X₁, X₂, X₂', X₁'] 2 = X₂' := rfl
have h3 : ![X₁, X₂, X₂', X₁'] 3 = X₁' := rfl
have h := sum_of_rdist_eq_char_2 ![X₁, X₂, X₂', X₁'] h_indep
(fun i => by fin_cases i <;> assumption)
rw [h0, h1, h2, h3] at h
have heq : d[X₂' # X₁'] = k := by
rw [rdist_symm]
apply ProbabilityTheory.IdentDistrib.rdist_eq h₁.symm h₂.symm
rw [heq] at h
convert h.symm using 1
· congr 2 <;> abel
· ring
/-- The distance $d[X_1+\tilde X_2; X_2+\tilde X_1]$ is at least
$$ k - \eta (d[X^0_1; X_1+\tilde X_2] - d[X^0_1; X_1]) - \eta (d[X^0_2; X_2+\tilde X_1] - d[X^0_2; X_2]).$$ -/
lemma rdist_of_sums_ge :
d[X₁ + X₂' # X₂ + X₁'] ≥
k - p.η * (d[p.X₀₁ # X₁ + X₂'] - d[p.X₀₁ # X₁])
- p.η * (d[p.X₀₂ # X₂ + X₁'] - d[p.X₀₂ # X₂]) :=
distance_ge_of_min _ h_min (hX₁.add hX₂') (hX₂.add hX₁')
/-- The distance $d[X_1|X_1+\tilde X_2; X_2|X_2+\tilde X_1]$ is at least
$$ k - \eta (d[X^0_1; X_1 | X_1 + \tilde X_2] - d[X^0_1; X_1]) - \eta(d[X^0_2; X_2 | X_2 + \tilde X_1] - d[X^0_2; X_2]).$$
-/
| lemma condRuzsaDist_of_sums_ge :
d[X₁ | X₁ + X₂' # X₂ | X₂ + X₁'] ≥
k - p.η * (d[p.X₀₁ # X₁ | X₁ + X₂'] - d[p.X₀₁ # X₁])
- p.η * (d[p.X₀₂ # X₂ | X₂ + X₁'] - d[p.X₀₂ # X₂]) | condRuzsaDist_of_sums_ge | 59160fb 20231116 | 2e4cc62 20231201 | pfr/PFR/FirstEstimate.lean | {
"lineInFile": 83,
"tokenPositionInFile": 3171,
"theoremPositionInFile": 4
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "condRuzsaDistance_ge_of_min _ h_min hX₁ hX₂ _ _ (by measurability) (by measurability)",
"proofType": "term",
"proofLengthLines": 1,
"proofLengthTokens": 85
} | pfr |
import PFR.Fibring
import PFR.TauFunctional
/-!
# First estimate
The first estimate on tau-minimizers.
Assumptions:
* $X_1, X_2$ are tau-minimizers
* $X_1, X_2, \tilde X_1, \tilde X_2$ are independent random variables, with $X_1,\tilde X_1$ copies of $X_1$ and $X_2,\tilde X_2$ copies of $X_2$.
* $k := d[X_1;X_2]$
* $I_1 := I [X_1+X_2 : \tilde X_1 + X_2 | X_1+X_2+\tilde X_1+\tilde X_2]$
## Main results
* `first_estimate` : $I_1 ≤ 2 η k$
* `ent_ofsum_le` : $H[X_1+X_2+\tilde X_1+\tilde X_2] \le \tfrac{1}{2} H[X_1]+\tfrac{1}{2} H[X_2] + (2 + \eta) k - I_1.$
-/
open MeasureTheory ProbabilityTheory
variable {G : Type*} [addgroup: AddCommGroup G] [Fintype G] [hG : MeasurableSpace G]
[MeasurableSingletonClass G] [elem: ElementaryAddCommGroup G 2] [MeasurableAdd₂ G]
variable {Ω₀₁ Ω₀₂ : Type*} [MeasureSpace Ω₀₁] [MeasureSpace Ω₀₂]
[IsProbabilityMeasure (ℙ : Measure Ω₀₁)] [IsProbabilityMeasure (ℙ : Measure Ω₀₂)]
variable (p : refPackage Ω₀₁ Ω₀₂ G)
variable {Ω : Type*} [MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)]
variable (X₁ X₂ X₁' X₂' : Ω → G)
(hX₁ : Measurable X₁) (hX₂ : Measurable X₂) (hX₁' : Measurable X₁') (hX₂' : Measurable X₂')
variable (h₁ : IdentDistrib X₁ X₁') (h₂ : IdentDistrib X₂ X₂')
variable (h_indep : iIndepFun (fun _i => hG) ![X₁, X₂, X₂', X₁'])
variable (h_min: tau_minimizes p X₁ X₂)
/-- `k := d[X₁ # X₂]`, the Ruzsa distance `rdist` between X₁ and X₂. -/
local notation3 "k" => d[X₁ # X₂]
/-- `I₁ := I[X₁ + X₂ : X₁' + X₂ | X₁ + X₂ + X₁' + X₂']`, the conditional mutual information
of `X₁ + X₂` and `X₁' + X₂` given the quadruple sum `X₁ + X₂ + X₁' + X₂'`. -/
local notation3 "I₁" => I[X₁ + X₂ : X₁' + X₂ | X₁ + X₂ + X₁' + X₂']
/-- The sum of
$$ d[X_1+\tilde X_2;X_2+\tilde X_1] + d[X_1|X_1+\tilde X_2; X_2|X_2+\tilde X_1] $$
and
$$ I[X_1+ X_2 : \tilde X_1 + X_2 \,|\, X_1 + X_2 + \tilde X_1 + \tilde X_2] $$
is equal to $2k$. -/
lemma rdist_add_rdist_add_condMutual_eq : d[X₁ + X₂' # X₂ + X₁'] + d[X₁ | X₁ + X₂' # X₂ | X₂ + X₁']
+ I[X₁ + X₂ : X₁' + X₂ | X₁ + X₂ + X₁' + X₂'] = 2 * k := by
have h0 : ![X₁, X₂, X₂', X₁'] 0 = X₁ := rfl
have h1 : ![X₁, X₂, X₂', X₁'] 1 = X₂ := rfl
have h2 : ![X₁, X₂, X₂', X₁'] 2 = X₂' := rfl
have h3 : ![X₁, X₂, X₂', X₁'] 3 = X₁' := rfl
have h := sum_of_rdist_eq_char_2 ![X₁, X₂, X₂', X₁'] h_indep
(fun i => by fin_cases i <;> assumption)
rw [h0, h1, h2, h3] at h
have heq : d[X₂' # X₁'] = k := by
rw [rdist_symm]
apply ProbabilityTheory.IdentDistrib.rdist_eq h₁.symm h₂.symm
rw [heq] at h
convert h.symm using 1
· congr 2 <;> abel
· ring
/-- The distance $d[X_1+\tilde X_2; X_2+\tilde X_1]$ is at least
$$ k - \eta (d[X^0_1; X_1+\tilde X_2] - d[X^0_1; X_1]) - \eta (d[X^0_2; X_2+\tilde X_1] - d[X^0_2; X_2]).$$ -/
lemma rdist_of_sums_ge :
d[X₁ + X₂' # X₂ + X₁'] ≥
k - p.η * (d[p.X₀₁ # X₁ + X₂'] - d[p.X₀₁ # X₁])
- p.η * (d[p.X₀₂ # X₂ + X₁'] - d[p.X₀₂ # X₂]) :=
distance_ge_of_min _ h_min (hX₁.add hX₂') (hX₂.add hX₁')
/-- The distance $d[X_1|X_1+\tilde X_2; X_2|X_2+\tilde X_1]$ is at least
$$ k - \eta (d[X^0_1; X_1 | X_1 + \tilde X_2] - d[X^0_1; X_1]) - \eta(d[X^0_2; X_2 | X_2 + \tilde X_1] - d[X^0_2; X_2]).$$
-/
lemma condRuzsaDist_of_sums_ge :
d[X₁ | X₁ + X₂' # X₂ | X₂ + X₁'] ≥
k - p.η * (d[p.X₀₁ # X₁ | X₁ + X₂'] - d[p.X₀₁ # X₁])
- p.η * (d[p.X₀₂ # X₂ | X₂ + X₁'] - d[p.X₀₂ # X₂]) :=
condRuzsaDistance_ge_of_min _ h_min hX₁ hX₂ _ _ (by measurability) (by measurability)
/-- $$d[X^0_1; X_1+\tilde X_2] - d[X^0_1; X_1] \leq \tfrac{1}{2} k + \tfrac{1}{4} \bbH[X_2] - \tfrac{1}{4} \bbH[X_1].$$ -/
| lemma diff_rdist_le_1 : d[p.X₀₁ # X₁ + X₂'] - d[p.X₀₁ # X₁] ≤ k/2 + H[X₂]/4 - H[X₁]/4 | diff_rdist_le_1 | 59160fb 20231116 | 41c6859 20231124 | pfr/PFR/FirstEstimate.lean | {
"lineInFile": 90,
"tokenPositionInFile": 3576,
"theoremPositionInFile": 5
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n have h : IndepFun X₁ X₂' := by simpa using h_indep.indepFun (show (0:Fin 4) ≠ 2 by decide)\n convert condRuzsaDist_diff_le' ℙ p.hmeas1 hX₁ hX₂' h using 4\n · exact ProbabilityTheory.IdentDistrib.rdist_eq (IdentDistrib.refl hX₁.aemeasurable) h₂\n · exact h₂.entropy_eq",
"proofType": "tactic",
"proofLengthLines": 5,
"proofLengthTokens": 272
} | pfr |
import PFR.Fibring
import PFR.TauFunctional
/-!
# First estimate
The first estimate on tau-minimizers.
Assumptions:
* $X_1, X_2$ are tau-minimizers
* $X_1, X_2, \tilde X_1, \tilde X_2$ are independent random variables, with $X_1,\tilde X_1$ copies of $X_1$ and $X_2,\tilde X_2$ copies of $X_2$.
* $k := d[X_1;X_2]$
* $I_1 := I [X_1+X_2 : \tilde X_1 + X_2 | X_1+X_2+\tilde X_1+\tilde X_2]$
## Main results
* `first_estimate` : $I_1 ≤ 2 η k$
* `ent_ofsum_le` : $H[X_1+X_2+\tilde X_1+\tilde X_2] \le \tfrac{1}{2} H[X_1]+\tfrac{1}{2} H[X_2] + (2 + \eta) k - I_1.$
-/
open MeasureTheory ProbabilityTheory
variable {G : Type*} [addgroup: AddCommGroup G] [Fintype G] [hG : MeasurableSpace G]
[MeasurableSingletonClass G] [elem: ElementaryAddCommGroup G 2] [MeasurableAdd₂ G]
variable {Ω₀₁ Ω₀₂ : Type*} [MeasureSpace Ω₀₁] [MeasureSpace Ω₀₂]
[IsProbabilityMeasure (ℙ : Measure Ω₀₁)] [IsProbabilityMeasure (ℙ : Measure Ω₀₂)]
variable (p : refPackage Ω₀₁ Ω₀₂ G)
variable {Ω : Type*} [MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)]
variable (X₁ X₂ X₁' X₂' : Ω → G)
(hX₁ : Measurable X₁) (hX₂ : Measurable X₂) (hX₁' : Measurable X₁') (hX₂' : Measurable X₂')
variable (h₁ : IdentDistrib X₁ X₁') (h₂ : IdentDistrib X₂ X₂')
variable (h_indep : iIndepFun (fun _i => hG) ![X₁, X₂, X₂', X₁'])
variable (h_min: tau_minimizes p X₁ X₂)
/-- `k := d[X₁ # X₂]`, the Ruzsa distance `rdist` between X₁ and X₂. -/
local notation3 "k" => d[X₁ # X₂]
/-- `I₁ := I[X₁ + X₂ : X₁' + X₂ | X₁ + X₂ + X₁' + X₂']`, the conditional mutual information
of `X₁ + X₂` and `X₁' + X₂` given the quadruple sum `X₁ + X₂ + X₁' + X₂'`. -/
local notation3 "I₁" => I[X₁ + X₂ : X₁' + X₂ | X₁ + X₂ + X₁' + X₂']
/-- The sum of
$$ d[X_1+\tilde X_2;X_2+\tilde X_1] + d[X_1|X_1+\tilde X_2; X_2|X_2+\tilde X_1] $$
and
$$ I[X_1+ X_2 : \tilde X_1 + X_2 \,|\, X_1 + X_2 + \tilde X_1 + \tilde X_2] $$
is equal to $2k$. -/
lemma rdist_add_rdist_add_condMutual_eq : d[X₁ + X₂' # X₂ + X₁'] + d[X₁ | X₁ + X₂' # X₂ | X₂ + X₁']
+ I[X₁ + X₂ : X₁' + X₂ | X₁ + X₂ + X₁' + X₂'] = 2 * k := by
have h0 : ![X₁, X₂, X₂', X₁'] 0 = X₁ := rfl
have h1 : ![X₁, X₂, X₂', X₁'] 1 = X₂ := rfl
have h2 : ![X₁, X₂, X₂', X₁'] 2 = X₂' := rfl
have h3 : ![X₁, X₂, X₂', X₁'] 3 = X₁' := rfl
have h := sum_of_rdist_eq_char_2 ![X₁, X₂, X₂', X₁'] h_indep
(fun i => by fin_cases i <;> assumption)
rw [h0, h1, h2, h3] at h
have heq : d[X₂' # X₁'] = k := by
rw [rdist_symm]
apply ProbabilityTheory.IdentDistrib.rdist_eq h₁.symm h₂.symm
rw [heq] at h
convert h.symm using 1
· congr 2 <;> abel
· ring
/-- The distance $d[X_1+\tilde X_2; X_2+\tilde X_1]$ is at least
$$ k - \eta (d[X^0_1; X_1+\tilde X_2] - d[X^0_1; X_1]) - \eta (d[X^0_2; X_2+\tilde X_1] - d[X^0_2; X_2]).$$ -/
lemma rdist_of_sums_ge :
d[X₁ + X₂' # X₂ + X₁'] ≥
k - p.η * (d[p.X₀₁ # X₁ + X₂'] - d[p.X₀₁ # X₁])
- p.η * (d[p.X₀₂ # X₂ + X₁'] - d[p.X₀₂ # X₂]) :=
distance_ge_of_min _ h_min (hX₁.add hX₂') (hX₂.add hX₁')
/-- The distance $d[X_1|X_1+\tilde X_2; X_2|X_2+\tilde X_1]$ is at least
$$ k - \eta (d[X^0_1; X_1 | X_1 + \tilde X_2] - d[X^0_1; X_1]) - \eta(d[X^0_2; X_2 | X_2 + \tilde X_1] - d[X^0_2; X_2]).$$
-/
lemma condRuzsaDist_of_sums_ge :
d[X₁ | X₁ + X₂' # X₂ | X₂ + X₁'] ≥
k - p.η * (d[p.X₀₁ # X₁ | X₁ + X₂'] - d[p.X₀₁ # X₁])
- p.η * (d[p.X₀₂ # X₂ | X₂ + X₁'] - d[p.X₀₂ # X₂]) :=
condRuzsaDistance_ge_of_min _ h_min hX₁ hX₂ _ _ (by measurability) (by measurability)
/-- $$d[X^0_1; X_1+\tilde X_2] - d[X^0_1; X_1] \leq \tfrac{1}{2} k + \tfrac{1}{4} \bbH[X_2] - \tfrac{1}{4} \bbH[X_1].$$ -/
lemma diff_rdist_le_1 : d[p.X₀₁ # X₁ + X₂'] - d[p.X₀₁ # X₁] ≤ k/2 + H[X₂]/4 - H[X₁]/4 := by
have h : IndepFun X₁ X₂' := by simpa using h_indep.indepFun (show (0:Fin 4) ≠ 2 by decide)
convert condRuzsaDist_diff_le' ℙ p.hmeas1 hX₁ hX₂' h using 4
· exact ProbabilityTheory.IdentDistrib.rdist_eq (IdentDistrib.refl hX₁.aemeasurable) h₂
· exact h₂.entropy_eq
/-- $$ d[X^0_2;X_2+\tilde X_1] - d[X^0_2; X_2] \leq \tfrac{1}{2} k + \tfrac{1}{4} \mathbb{H}[X_1] - \tfrac{1}{4} \mathbb{H}[X_2].$$ -/
| lemma diff_rdist_le_2 : d[p.X₀₂ # X₂ + X₁'] - d[p.X₀₂ # X₂] ≤ k/2 + H[X₁]/4 - H[X₂]/4 | diff_rdist_le_2 | 59160fb 20231116 | 41c6859 20231124 | pfr/PFR/FirstEstimate.lean | {
"lineInFile": 97,
"tokenPositionInFile": 4074,
"theoremPositionInFile": 6
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n have h : IndepFun X₂ X₁' := by simpa using h_indep.indepFun (show (1:Fin 4) ≠ 3 by decide)\n convert condRuzsaDist_diff_le' ℙ p.hmeas2 hX₂ hX₁' h using 4\n · rw [rdist_symm]\n exact (IdentDistrib.refl hX₂.aemeasurable).rdist_eq h₁\n · exact h₁.entropy_eq",
"proofType": "tactic",
"proofLengthLines": 6,
"proofLengthTokens": 261
} | pfr |
import PFR.Fibring
import PFR.TauFunctional
/-!
# First estimate
The first estimate on tau-minimizers.
Assumptions:
* $X_1, X_2$ are tau-minimizers
* $X_1, X_2, \tilde X_1, \tilde X_2$ are independent random variables, with $X_1,\tilde X_1$ copies of $X_1$ and $X_2,\tilde X_2$ copies of $X_2$.
* $k := d[X_1;X_2]$
* $I_1 := I [X_1+X_2 : \tilde X_1 + X_2 | X_1+X_2+\tilde X_1+\tilde X_2]$
## Main results
* `first_estimate` : $I_1 ≤ 2 η k$
* `ent_ofsum_le` : $H[X_1+X_2+\tilde X_1+\tilde X_2] \le \tfrac{1}{2} H[X_1]+\tfrac{1}{2} H[X_2] + (2 + \eta) k - I_1.$
-/
open MeasureTheory ProbabilityTheory
variable {G : Type*} [addgroup: AddCommGroup G] [Fintype G] [hG : MeasurableSpace G]
[MeasurableSingletonClass G] [elem: ElementaryAddCommGroup G 2] [MeasurableAdd₂ G]
variable {Ω₀₁ Ω₀₂ : Type*} [MeasureSpace Ω₀₁] [MeasureSpace Ω₀₂]
[IsProbabilityMeasure (ℙ : Measure Ω₀₁)] [IsProbabilityMeasure (ℙ : Measure Ω₀₂)]
variable (p : refPackage Ω₀₁ Ω₀₂ G)
variable {Ω : Type*} [MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)]
variable (X₁ X₂ X₁' X₂' : Ω → G)
(hX₁ : Measurable X₁) (hX₂ : Measurable X₂) (hX₁' : Measurable X₁') (hX₂' : Measurable X₂')
variable (h₁ : IdentDistrib X₁ X₁') (h₂ : IdentDistrib X₂ X₂')
variable (h_indep : iIndepFun (fun _i => hG) ![X₁, X₂, X₂', X₁'])
variable (h_min: tau_minimizes p X₁ X₂)
/-- `k := d[X₁ # X₂]`, the Ruzsa distance `rdist` between X₁ and X₂. -/
local notation3 "k" => d[X₁ # X₂]
/-- `I₁ := I[X₁ + X₂ : X₁' + X₂ | X₁ + X₂ + X₁' + X₂']`, the conditional mutual information
of `X₁ + X₂` and `X₁' + X₂` given the quadruple sum `X₁ + X₂ + X₁' + X₂'`. -/
local notation3 "I₁" => I[X₁ + X₂ : X₁' + X₂ | X₁ + X₂ + X₁' + X₂']
/-- The sum of
$$ d[X_1+\tilde X_2;X_2+\tilde X_1] + d[X_1|X_1+\tilde X_2; X_2|X_2+\tilde X_1] $$
and
$$ I[X_1+ X_2 : \tilde X_1 + X_2 \,|\, X_1 + X_2 + \tilde X_1 + \tilde X_2] $$
is equal to $2k$. -/
lemma rdist_add_rdist_add_condMutual_eq : d[X₁ + X₂' # X₂ + X₁'] + d[X₁ | X₁ + X₂' # X₂ | X₂ + X₁']
+ I[X₁ + X₂ : X₁' + X₂ | X₁ + X₂ + X₁' + X₂'] = 2 * k := by
have h0 : ![X₁, X₂, X₂', X₁'] 0 = X₁ := rfl
have h1 : ![X₁, X₂, X₂', X₁'] 1 = X₂ := rfl
have h2 : ![X₁, X₂, X₂', X₁'] 2 = X₂' := rfl
have h3 : ![X₁, X₂, X₂', X₁'] 3 = X₁' := rfl
have h := sum_of_rdist_eq_char_2 ![X₁, X₂, X₂', X₁'] h_indep
(fun i => by fin_cases i <;> assumption)
rw [h0, h1, h2, h3] at h
have heq : d[X₂' # X₁'] = k := by
rw [rdist_symm]
apply ProbabilityTheory.IdentDistrib.rdist_eq h₁.symm h₂.symm
rw [heq] at h
convert h.symm using 1
· congr 2 <;> abel
· ring
/-- The distance $d[X_1+\tilde X_2; X_2+\tilde X_1]$ is at least
$$ k - \eta (d[X^0_1; X_1+\tilde X_2] - d[X^0_1; X_1]) - \eta (d[X^0_2; X_2+\tilde X_1] - d[X^0_2; X_2]).$$ -/
lemma rdist_of_sums_ge :
d[X₁ + X₂' # X₂ + X₁'] ≥
k - p.η * (d[p.X₀₁ # X₁ + X₂'] - d[p.X₀₁ # X₁])
- p.η * (d[p.X₀₂ # X₂ + X₁'] - d[p.X₀₂ # X₂]) :=
distance_ge_of_min _ h_min (hX₁.add hX₂') (hX₂.add hX₁')
/-- The distance $d[X_1|X_1+\tilde X_2; X_2|X_2+\tilde X_1]$ is at least
$$ k - \eta (d[X^0_1; X_1 | X_1 + \tilde X_2] - d[X^0_1; X_1]) - \eta(d[X^0_2; X_2 | X_2 + \tilde X_1] - d[X^0_2; X_2]).$$
-/
lemma condRuzsaDist_of_sums_ge :
d[X₁ | X₁ + X₂' # X₂ | X₂ + X₁'] ≥
k - p.η * (d[p.X₀₁ # X₁ | X₁ + X₂'] - d[p.X₀₁ # X₁])
- p.η * (d[p.X₀₂ # X₂ | X₂ + X₁'] - d[p.X₀₂ # X₂]) :=
condRuzsaDistance_ge_of_min _ h_min hX₁ hX₂ _ _ (by measurability) (by measurability)
/-- $$d[X^0_1; X_1+\tilde X_2] - d[X^0_1; X_1] \leq \tfrac{1}{2} k + \tfrac{1}{4} \bbH[X_2] - \tfrac{1}{4} \bbH[X_1].$$ -/
lemma diff_rdist_le_1 : d[p.X₀₁ # X₁ + X₂'] - d[p.X₀₁ # X₁] ≤ k/2 + H[X₂]/4 - H[X₁]/4 := by
have h : IndepFun X₁ X₂' := by simpa using h_indep.indepFun (show (0:Fin 4) ≠ 2 by decide)
convert condRuzsaDist_diff_le' ℙ p.hmeas1 hX₁ hX₂' h using 4
· exact ProbabilityTheory.IdentDistrib.rdist_eq (IdentDistrib.refl hX₁.aemeasurable) h₂
· exact h₂.entropy_eq
/-- $$ d[X^0_2;X_2+\tilde X_1] - d[X^0_2; X_2] \leq \tfrac{1}{2} k + \tfrac{1}{4} \mathbb{H}[X_1] - \tfrac{1}{4} \mathbb{H}[X_2].$$ -/
lemma diff_rdist_le_2 : d[p.X₀₂ # X₂ + X₁'] - d[p.X₀₂ # X₂] ≤ k/2 + H[X₁]/4 - H[X₂]/4 := by
have h : IndepFun X₂ X₁' := by simpa using h_indep.indepFun (show (1:Fin 4) ≠ 3 by decide)
convert condRuzsaDist_diff_le' ℙ p.hmeas2 hX₂ hX₁' h using 4
· rw [rdist_symm]
exact (IdentDistrib.refl hX₂.aemeasurable).rdist_eq h₁
· exact h₁.entropy_eq
/-- $$ d[X_1^0;X_1|X_1+\tilde X_2] - d[X_1^0;X_1] \leq
\tfrac{1}{2} k + \tfrac{1}{4} \mathbb{H}[X_1] - \tfrac{1}{4} \mathbb{H}[X_2].$$ -/
| lemma diff_rdist_le_3 : d[p.X₀₁ # X₁ | X₁ + X₂'] - d[p.X₀₁ # X₁] ≤ k/2 + H[X₁]/4 - H[X₂]/4 | diff_rdist_le_3 | 59160fb 20231116 | 41c6859 20231124 | pfr/PFR/FirstEstimate.lean | {
"lineInFile": 106,
"tokenPositionInFile": 4568,
"theoremPositionInFile": 7
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n have h : IndepFun X₁ X₂' := by simpa using h_indep.indepFun (show (0:Fin 4) ≠ 2 by decide)\n convert condRuzsaDist_diff_le''' ℙ p.hmeas1 hX₁ hX₂' h using 3\n · rw [(IdentDistrib.refl hX₁.aemeasurable).rdist_eq h₂]\n · apply h₂.entropy_eq",
"proofType": "tactic",
"proofLengthLines": 5,
"proofLengthTokens": 242
} | pfr |
import PFR.Fibring
import PFR.TauFunctional
/-!
# First estimate
The first estimate on tau-minimizers.
Assumptions:
* $X_1, X_2$ are tau-minimizers
* $X_1, X_2, \tilde X_1, \tilde X_2$ are independent random variables, with $X_1,\tilde X_1$ copies of $X_1$ and $X_2,\tilde X_2$ copies of $X_2$.
* $k := d[X_1;X_2]$
* $I_1 := I [X_1+X_2 : \tilde X_1 + X_2 | X_1+X_2+\tilde X_1+\tilde X_2]$
## Main results
* `first_estimate` : $I_1 ≤ 2 η k$
* `ent_ofsum_le` : $H[X_1+X_2+\tilde X_1+\tilde X_2] \le \tfrac{1}{2} H[X_1]+\tfrac{1}{2} H[X_2] + (2 + \eta) k - I_1.$
-/
open MeasureTheory ProbabilityTheory
variable {G : Type*} [addgroup: AddCommGroup G] [Fintype G] [hG : MeasurableSpace G]
[MeasurableSingletonClass G] [elem: ElementaryAddCommGroup G 2] [MeasurableAdd₂ G]
variable {Ω₀₁ Ω₀₂ : Type*} [MeasureSpace Ω₀₁] [MeasureSpace Ω₀₂]
[IsProbabilityMeasure (ℙ : Measure Ω₀₁)] [IsProbabilityMeasure (ℙ : Measure Ω₀₂)]
variable (p : refPackage Ω₀₁ Ω₀₂ G)
variable {Ω : Type*} [MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)]
variable (X₁ X₂ X₁' X₂' : Ω → G)
(hX₁ : Measurable X₁) (hX₂ : Measurable X₂) (hX₁' : Measurable X₁') (hX₂' : Measurable X₂')
variable (h₁ : IdentDistrib X₁ X₁') (h₂ : IdentDistrib X₂ X₂')
variable (h_indep : iIndepFun (fun _i => hG) ![X₁, X₂, X₂', X₁'])
variable (h_min: tau_minimizes p X₁ X₂)
/-- `k := d[X₁ # X₂]`, the Ruzsa distance `rdist` between X₁ and X₂. -/
local notation3 "k" => d[X₁ # X₂]
/-- `I₁ := I[X₁ + X₂ : X₁' + X₂ | X₁ + X₂ + X₁' + X₂']`, the conditional mutual information
of `X₁ + X₂` and `X₁' + X₂` given the quadruple sum `X₁ + X₂ + X₁' + X₂'`. -/
local notation3 "I₁" => I[X₁ + X₂ : X₁' + X₂ | X₁ + X₂ + X₁' + X₂']
/-- The sum of
$$ d[X_1+\tilde X_2;X_2+\tilde X_1] + d[X_1|X_1+\tilde X_2; X_2|X_2+\tilde X_1] $$
and
$$ I[X_1+ X_2 : \tilde X_1 + X_2 \,|\, X_1 + X_2 + \tilde X_1 + \tilde X_2] $$
is equal to $2k$. -/
lemma rdist_add_rdist_add_condMutual_eq : d[X₁ + X₂' # X₂ + X₁'] + d[X₁ | X₁ + X₂' # X₂ | X₂ + X₁']
+ I[X₁ + X₂ : X₁' + X₂ | X₁ + X₂ + X₁' + X₂'] = 2 * k := by
have h0 : ![X₁, X₂, X₂', X₁'] 0 = X₁ := rfl
have h1 : ![X₁, X₂, X₂', X₁'] 1 = X₂ := rfl
have h2 : ![X₁, X₂, X₂', X₁'] 2 = X₂' := rfl
have h3 : ![X₁, X₂, X₂', X₁'] 3 = X₁' := rfl
have h := sum_of_rdist_eq_char_2 ![X₁, X₂, X₂', X₁'] h_indep
(fun i => by fin_cases i <;> assumption)
rw [h0, h1, h2, h3] at h
have heq : d[X₂' # X₁'] = k := by
rw [rdist_symm]
apply ProbabilityTheory.IdentDistrib.rdist_eq h₁.symm h₂.symm
rw [heq] at h
convert h.symm using 1
· congr 2 <;> abel
· ring
/-- The distance $d[X_1+\tilde X_2; X_2+\tilde X_1]$ is at least
$$ k - \eta (d[X^0_1; X_1+\tilde X_2] - d[X^0_1; X_1]) - \eta (d[X^0_2; X_2+\tilde X_1] - d[X^0_2; X_2]).$$ -/
lemma rdist_of_sums_ge :
d[X₁ + X₂' # X₂ + X₁'] ≥
k - p.η * (d[p.X₀₁ # X₁ + X₂'] - d[p.X₀₁ # X₁])
- p.η * (d[p.X₀₂ # X₂ + X₁'] - d[p.X₀₂ # X₂]) :=
distance_ge_of_min _ h_min (hX₁.add hX₂') (hX₂.add hX₁')
/-- The distance $d[X_1|X_1+\tilde X_2; X_2|X_2+\tilde X_1]$ is at least
$$ k - \eta (d[X^0_1; X_1 | X_1 + \tilde X_2] - d[X^0_1; X_1]) - \eta(d[X^0_2; X_2 | X_2 + \tilde X_1] - d[X^0_2; X_2]).$$
-/
lemma condRuzsaDist_of_sums_ge :
d[X₁ | X₁ + X₂' # X₂ | X₂ + X₁'] ≥
k - p.η * (d[p.X₀₁ # X₁ | X₁ + X₂'] - d[p.X₀₁ # X₁])
- p.η * (d[p.X₀₂ # X₂ | X₂ + X₁'] - d[p.X₀₂ # X₂]) :=
condRuzsaDistance_ge_of_min _ h_min hX₁ hX₂ _ _ (by measurability) (by measurability)
/-- $$d[X^0_1; X_1+\tilde X_2] - d[X^0_1; X_1] \leq \tfrac{1}{2} k + \tfrac{1}{4} \bbH[X_2] - \tfrac{1}{4} \bbH[X_1].$$ -/
lemma diff_rdist_le_1 : d[p.X₀₁ # X₁ + X₂'] - d[p.X₀₁ # X₁] ≤ k/2 + H[X₂]/4 - H[X₁]/4 := by
have h : IndepFun X₁ X₂' := by simpa using h_indep.indepFun (show (0:Fin 4) ≠ 2 by decide)
convert condRuzsaDist_diff_le' ℙ p.hmeas1 hX₁ hX₂' h using 4
· exact ProbabilityTheory.IdentDistrib.rdist_eq (IdentDistrib.refl hX₁.aemeasurable) h₂
· exact h₂.entropy_eq
/-- $$ d[X^0_2;X_2+\tilde X_1] - d[X^0_2; X_2] \leq \tfrac{1}{2} k + \tfrac{1}{4} \mathbb{H}[X_1] - \tfrac{1}{4} \mathbb{H}[X_2].$$ -/
lemma diff_rdist_le_2 : d[p.X₀₂ # X₂ + X₁'] - d[p.X₀₂ # X₂] ≤ k/2 + H[X₁]/4 - H[X₂]/4 := by
have h : IndepFun X₂ X₁' := by simpa using h_indep.indepFun (show (1:Fin 4) ≠ 3 by decide)
convert condRuzsaDist_diff_le' ℙ p.hmeas2 hX₂ hX₁' h using 4
· rw [rdist_symm]
exact (IdentDistrib.refl hX₂.aemeasurable).rdist_eq h₁
· exact h₁.entropy_eq
/-- $$ d[X_1^0;X_1|X_1+\tilde X_2] - d[X_1^0;X_1] \leq
\tfrac{1}{2} k + \tfrac{1}{4} \mathbb{H}[X_1] - \tfrac{1}{4} \mathbb{H}[X_2].$$ -/
lemma diff_rdist_le_3 : d[p.X₀₁ # X₁ | X₁ + X₂'] - d[p.X₀₁ # X₁] ≤ k/2 + H[X₁]/4 - H[X₂]/4 := by
have h : IndepFun X₁ X₂' := by simpa using h_indep.indepFun (show (0:Fin 4) ≠ 2 by decide)
convert condRuzsaDist_diff_le''' ℙ p.hmeas1 hX₁ hX₂' h using 3
· rw [(IdentDistrib.refl hX₁.aemeasurable).rdist_eq h₂]
· apply h₂.entropy_eq
/-- $$ d[X_2^0; X_2|X_2+\tilde X_1] - d[X_2^0; X_2] \leq
\tfrac{1}{2}k + \tfrac{1}{4} \mathbb{H}[X_2] - \tfrac{1}{4} \mathbb{H}[X_1].$$ -/
| lemma diff_rdist_le_4 : d[p.X₀₂ # X₂ | X₂ + X₁'] - d[p.X₀₂ # X₂] ≤ k/2 + H[X₂]/4 - H[X₁]/4 | diff_rdist_le_4 | 59160fb 20231116 | 41c6859 20231124 | pfr/PFR/FirstEstimate.lean | {
"lineInFile": 114,
"tokenPositionInFile": 5049,
"theoremPositionInFile": 8
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n have h : IndepFun X₂ X₁' := by simpa using h_indep.indepFun (show (1:Fin 4) ≠ 3 by decide)\n convert condRuzsaDist_diff_le''' ℙ p.hmeas2 hX₂ hX₁' h using 3\n · rw [rdist_symm, (IdentDistrib.refl hX₂.aemeasurable).rdist_eq h₁]\n · apply h₁.entropy_eq",
"proofType": "tactic",
"proofLengthLines": 5,
"proofLengthTokens": 254
} | pfr |
import PFR.Fibring
import PFR.TauFunctional
/-!
# First estimate
The first estimate on tau-minimizers.
Assumptions:
* $X_1, X_2$ are tau-minimizers
* $X_1, X_2, \tilde X_1, \tilde X_2$ are independent random variables, with $X_1,\tilde X_1$ copies of $X_1$ and $X_2,\tilde X_2$ copies of $X_2$.
* $k := d[X_1;X_2]$
* $I_1 := I [X_1+X_2 : \tilde X_1 + X_2 | X_1+X_2+\tilde X_1+\tilde X_2]$
## Main results
* `first_estimate` : $I_1 ≤ 2 η k$
* `ent_ofsum_le` : $H[X_1+X_2+\tilde X_1+\tilde X_2] \le \tfrac{1}{2} H[X_1]+\tfrac{1}{2} H[X_2] + (2 + \eta) k - I_1.$
-/
open MeasureTheory ProbabilityTheory
variable {G : Type*} [addgroup: AddCommGroup G] [Fintype G] [hG : MeasurableSpace G]
[MeasurableSingletonClass G] [elem: ElementaryAddCommGroup G 2] [MeasurableAdd₂ G]
variable {Ω₀₁ Ω₀₂ : Type*} [MeasureSpace Ω₀₁] [MeasureSpace Ω₀₂]
[IsProbabilityMeasure (ℙ : Measure Ω₀₁)] [IsProbabilityMeasure (ℙ : Measure Ω₀₂)]
variable (p : refPackage Ω₀₁ Ω₀₂ G)
variable {Ω : Type*} [MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)]
variable (X₁ X₂ X₁' X₂' : Ω → G)
(hX₁ : Measurable X₁) (hX₂ : Measurable X₂) (hX₁' : Measurable X₁') (hX₂' : Measurable X₂')
variable (h₁ : IdentDistrib X₁ X₁') (h₂ : IdentDistrib X₂ X₂')
variable (h_indep : iIndepFun (fun _i => hG) ![X₁, X₂, X₂', X₁'])
variable (h_min: tau_minimizes p X₁ X₂)
/-- `k := d[X₁ # X₂]`, the Ruzsa distance `rdist` between X₁ and X₂. -/
local notation3 "k" => d[X₁ # X₂]
/-- `I₁ := I[X₁ + X₂ : X₁' + X₂ | X₁ + X₂ + X₁' + X₂']`, the conditional mutual information
of `X₁ + X₂` and `X₁' + X₂` given the quadruple sum `X₁ + X₂ + X₁' + X₂'`. -/
local notation3 "I₁" => I[X₁ + X₂ : X₁' + X₂ | X₁ + X₂ + X₁' + X₂']
/-- The sum of
$$ d[X_1+\tilde X_2;X_2+\tilde X_1] + d[X_1|X_1+\tilde X_2; X_2|X_2+\tilde X_1] $$
and
$$ I[X_1+ X_2 : \tilde X_1 + X_2 \,|\, X_1 + X_2 + \tilde X_1 + \tilde X_2] $$
is equal to $2k$. -/
lemma rdist_add_rdist_add_condMutual_eq : d[X₁ + X₂' # X₂ + X₁'] + d[X₁ | X₁ + X₂' # X₂ | X₂ + X₁']
+ I[X₁ + X₂ : X₁' + X₂ | X₁ + X₂ + X₁' + X₂'] = 2 * k := by
have h0 : ![X₁, X₂, X₂', X₁'] 0 = X₁ := rfl
have h1 : ![X₁, X₂, X₂', X₁'] 1 = X₂ := rfl
have h2 : ![X₁, X₂, X₂', X₁'] 2 = X₂' := rfl
have h3 : ![X₁, X₂, X₂', X₁'] 3 = X₁' := rfl
have h := sum_of_rdist_eq_char_2 ![X₁, X₂, X₂', X₁'] h_indep
(fun i => by fin_cases i <;> assumption)
rw [h0, h1, h2, h3] at h
have heq : d[X₂' # X₁'] = k := by
rw [rdist_symm]
apply ProbabilityTheory.IdentDistrib.rdist_eq h₁.symm h₂.symm
rw [heq] at h
convert h.symm using 1
· congr 2 <;> abel
· ring
/-- The distance $d[X_1+\tilde X_2; X_2+\tilde X_1]$ is at least
$$ k - \eta (d[X^0_1; X_1+\tilde X_2] - d[X^0_1; X_1]) - \eta (d[X^0_2; X_2+\tilde X_1] - d[X^0_2; X_2]).$$ -/
lemma rdist_of_sums_ge :
d[X₁ + X₂' # X₂ + X₁'] ≥
k - p.η * (d[p.X₀₁ # X₁ + X₂'] - d[p.X₀₁ # X₁])
- p.η * (d[p.X₀₂ # X₂ + X₁'] - d[p.X₀₂ # X₂]) :=
distance_ge_of_min _ h_min (hX₁.add hX₂') (hX₂.add hX₁')
/-- The distance $d[X_1|X_1+\tilde X_2; X_2|X_2+\tilde X_1]$ is at least
$$ k - \eta (d[X^0_1; X_1 | X_1 + \tilde X_2] - d[X^0_1; X_1]) - \eta(d[X^0_2; X_2 | X_2 + \tilde X_1] - d[X^0_2; X_2]).$$
-/
lemma condRuzsaDist_of_sums_ge :
d[X₁ | X₁ + X₂' # X₂ | X₂ + X₁'] ≥
k - p.η * (d[p.X₀₁ # X₁ | X₁ + X₂'] - d[p.X₀₁ # X₁])
- p.η * (d[p.X₀₂ # X₂ | X₂ + X₁'] - d[p.X₀₂ # X₂]) :=
condRuzsaDistance_ge_of_min _ h_min hX₁ hX₂ _ _ (by measurability) (by measurability)
/-- $$d[X^0_1; X_1+\tilde X_2] - d[X^0_1; X_1] \leq \tfrac{1}{2} k + \tfrac{1}{4} \bbH[X_2] - \tfrac{1}{4} \bbH[X_1].$$ -/
lemma diff_rdist_le_1 : d[p.X₀₁ # X₁ + X₂'] - d[p.X₀₁ # X₁] ≤ k/2 + H[X₂]/4 - H[X₁]/4 := by
have h : IndepFun X₁ X₂' := by simpa using h_indep.indepFun (show (0:Fin 4) ≠ 2 by decide)
convert condRuzsaDist_diff_le' ℙ p.hmeas1 hX₁ hX₂' h using 4
· exact ProbabilityTheory.IdentDistrib.rdist_eq (IdentDistrib.refl hX₁.aemeasurable) h₂
· exact h₂.entropy_eq
/-- $$ d[X^0_2;X_2+\tilde X_1] - d[X^0_2; X_2] \leq \tfrac{1}{2} k + \tfrac{1}{4} \mathbb{H}[X_1] - \tfrac{1}{4} \mathbb{H}[X_2].$$ -/
lemma diff_rdist_le_2 : d[p.X₀₂ # X₂ + X₁'] - d[p.X₀₂ # X₂] ≤ k/2 + H[X₁]/4 - H[X₂]/4 := by
have h : IndepFun X₂ X₁' := by simpa using h_indep.indepFun (show (1:Fin 4) ≠ 3 by decide)
convert condRuzsaDist_diff_le' ℙ p.hmeas2 hX₂ hX₁' h using 4
· rw [rdist_symm]
exact (IdentDistrib.refl hX₂.aemeasurable).rdist_eq h₁
· exact h₁.entropy_eq
/-- $$ d[X_1^0;X_1|X_1+\tilde X_2] - d[X_1^0;X_1] \leq
\tfrac{1}{2} k + \tfrac{1}{4} \mathbb{H}[X_1] - \tfrac{1}{4} \mathbb{H}[X_2].$$ -/
lemma diff_rdist_le_3 : d[p.X₀₁ # X₁ | X₁ + X₂'] - d[p.X₀₁ # X₁] ≤ k/2 + H[X₁]/4 - H[X₂]/4 := by
have h : IndepFun X₁ X₂' := by simpa using h_indep.indepFun (show (0:Fin 4) ≠ 2 by decide)
convert condRuzsaDist_diff_le''' ℙ p.hmeas1 hX₁ hX₂' h using 3
· rw [(IdentDistrib.refl hX₁.aemeasurable).rdist_eq h₂]
· apply h₂.entropy_eq
/-- $$ d[X_2^0; X_2|X_2+\tilde X_1] - d[X_2^0; X_2] \leq
\tfrac{1}{2}k + \tfrac{1}{4} \mathbb{H}[X_2] - \tfrac{1}{4} \mathbb{H}[X_1].$$ -/
lemma diff_rdist_le_4 : d[p.X₀₂ # X₂ | X₂ + X₁'] - d[p.X₀₂ # X₂] ≤ k/2 + H[X₂]/4 - H[X₁]/4 := by
have h : IndepFun X₂ X₁' := by simpa using h_indep.indepFun (show (1:Fin 4) ≠ 3 by decide)
convert condRuzsaDist_diff_le''' ℙ p.hmeas2 hX₂ hX₁' h using 3
· rw [rdist_symm, (IdentDistrib.refl hX₂.aemeasurable).rdist_eq h₁]
· apply h₁.entropy_eq
/-- We have $I_1 \leq 2 \eta k$ -/
| lemma first_estimate : I₁ ≤ 2 * p.η * k | first_estimate | 59160fb 20231116 | 4f8e0e8 20231124 | pfr/PFR/FirstEstimate.lean | {
"lineInFile": 121,
"tokenPositionInFile": 5434,
"theoremPositionInFile": 9
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n have v1 := rdist_add_rdist_add_condMutual_eq X₁ X₂ X₁' X₂' ‹_› ‹_› ‹_› ‹_› ‹_› ‹_› ‹_›\n have v2 := rdist_of_sums_ge p X₁ X₂ X₁' X₂' ‹_› ‹_› ‹_› ‹_› ‹_›\n have v3 := condRuzsaDist_of_sums_ge p X₁ X₂ X₁' X₂' ‹_› ‹_› ‹_› (by measurability) (by measurability)\n have v4 := (mul_le_mul_left p.hη).2 (diff_rdist_le_1 p X₁ X₂ X₁' X₂' ‹_› ‹_› ‹_› ‹_›)\n have v5 := (mul_le_mul_left p.hη).2 (diff_rdist_le_2 p X₁ X₂ X₁' X₂' ‹_› ‹_› ‹_› ‹_›)\n have v6 := (mul_le_mul_left p.hη).2 (diff_rdist_le_3 p X₁ X₂ X₁' X₂' ‹_› ‹_› ‹_› ‹_›)\n have v7 := (mul_le_mul_left p.hη).2 (diff_rdist_le_4 p X₁ X₂ X₁' X₂' ‹_› ‹_› ‹_› ‹_›)\n simp only [inv_eq_one_div] at *\n linarith [v1, v2, v3, v4, v5, v6, v7]",
"proofType": "tactic",
"proofLengthLines": 10,
"proofLengthTokens": 687
} | pfr |
import PFR.Fibring
import PFR.TauFunctional
/-!
# First estimate
The first estimate on tau-minimizers.
Assumptions:
* $X_1, X_2$ are tau-minimizers
* $X_1, X_2, \tilde X_1, \tilde X_2$ are independent random variables, with $X_1,\tilde X_1$ copies of $X_1$ and $X_2,\tilde X_2$ copies of $X_2$.
* $k := d[X_1;X_2]$
* $I_1 := I [X_1+X_2 : \tilde X_1 + X_2 | X_1+X_2+\tilde X_1+\tilde X_2]$
## Main results
* `first_estimate` : $I_1 ≤ 2 η k$
* `ent_ofsum_le` : $H[X_1+X_2+\tilde X_1+\tilde X_2] \le \tfrac{1}{2} H[X_1]+\tfrac{1}{2} H[X_2] + (2 + \eta) k - I_1.$
-/
open MeasureTheory ProbabilityTheory
variable {G : Type*} [addgroup: AddCommGroup G] [Fintype G] [hG : MeasurableSpace G]
[MeasurableSingletonClass G] [elem: ElementaryAddCommGroup G 2] [MeasurableAdd₂ G]
variable {Ω₀₁ Ω₀₂ : Type*} [MeasureSpace Ω₀₁] [MeasureSpace Ω₀₂]
[IsProbabilityMeasure (ℙ : Measure Ω₀₁)] [IsProbabilityMeasure (ℙ : Measure Ω₀₂)]
variable (p : refPackage Ω₀₁ Ω₀₂ G)
variable {Ω : Type*} [MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)]
variable (X₁ X₂ X₁' X₂' : Ω → G)
(hX₁ : Measurable X₁) (hX₂ : Measurable X₂) (hX₁' : Measurable X₁') (hX₂' : Measurable X₂')
variable (h₁ : IdentDistrib X₁ X₁') (h₂ : IdentDistrib X₂ X₂')
variable (h_indep : iIndepFun (fun _i => hG) ![X₁, X₂, X₂', X₁'])
variable (h_min: tau_minimizes p X₁ X₂)
/-- `k := d[X₁ # X₂]`, the Ruzsa distance `rdist` between X₁ and X₂. -/
local notation3 "k" => d[X₁ # X₂]
/-- `I₁ := I[X₁ + X₂ : X₁' + X₂ | X₁ + X₂ + X₁' + X₂']`, the conditional mutual information
of `X₁ + X₂` and `X₁' + X₂` given the quadruple sum `X₁ + X₂ + X₁' + X₂'`. -/
local notation3 "I₁" => I[X₁ + X₂ : X₁' + X₂ | X₁ + X₂ + X₁' + X₂']
/-- The sum of
$$ d[X_1+\tilde X_2;X_2+\tilde X_1] + d[X_1|X_1+\tilde X_2; X_2|X_2+\tilde X_1] $$
and
$$ I[X_1+ X_2 : \tilde X_1 + X_2 \,|\, X_1 + X_2 + \tilde X_1 + \tilde X_2] $$
is equal to $2k$. -/
lemma rdist_add_rdist_add_condMutual_eq : d[X₁ + X₂' # X₂ + X₁'] + d[X₁ | X₁ + X₂' # X₂ | X₂ + X₁']
+ I[X₁ + X₂ : X₁' + X₂ | X₁ + X₂ + X₁' + X₂'] = 2 * k := by
have h0 : ![X₁, X₂, X₂', X₁'] 0 = X₁ := rfl
have h1 : ![X₁, X₂, X₂', X₁'] 1 = X₂ := rfl
have h2 : ![X₁, X₂, X₂', X₁'] 2 = X₂' := rfl
have h3 : ![X₁, X₂, X₂', X₁'] 3 = X₁' := rfl
have h := sum_of_rdist_eq_char_2 ![X₁, X₂, X₂', X₁'] h_indep
(fun i => by fin_cases i <;> assumption)
rw [h0, h1, h2, h3] at h
have heq : d[X₂' # X₁'] = k := by
rw [rdist_symm]
apply ProbabilityTheory.IdentDistrib.rdist_eq h₁.symm h₂.symm
rw [heq] at h
convert h.symm using 1
· congr 2 <;> abel
· ring
/-- The distance $d[X_1+\tilde X_2; X_2+\tilde X_1]$ is at least
$$ k - \eta (d[X^0_1; X_1+\tilde X_2] - d[X^0_1; X_1]) - \eta (d[X^0_2; X_2+\tilde X_1] - d[X^0_2; X_2]).$$ -/
lemma rdist_of_sums_ge :
d[X₁ + X₂' # X₂ + X₁'] ≥
k - p.η * (d[p.X₀₁ # X₁ + X₂'] - d[p.X₀₁ # X₁])
- p.η * (d[p.X₀₂ # X₂ + X₁'] - d[p.X₀₂ # X₂]) :=
distance_ge_of_min _ h_min (hX₁.add hX₂') (hX₂.add hX₁')
/-- The distance $d[X_1|X_1+\tilde X_2; X_2|X_2+\tilde X_1]$ is at least
$$ k - \eta (d[X^0_1; X_1 | X_1 + \tilde X_2] - d[X^0_1; X_1]) - \eta(d[X^0_2; X_2 | X_2 + \tilde X_1] - d[X^0_2; X_2]).$$
-/
lemma condRuzsaDist_of_sums_ge :
d[X₁ | X₁ + X₂' # X₂ | X₂ + X₁'] ≥
k - p.η * (d[p.X₀₁ # X₁ | X₁ + X₂'] - d[p.X₀₁ # X₁])
- p.η * (d[p.X₀₂ # X₂ | X₂ + X₁'] - d[p.X₀₂ # X₂]) :=
condRuzsaDistance_ge_of_min _ h_min hX₁ hX₂ _ _ (by measurability) (by measurability)
/-- $$d[X^0_1; X_1+\tilde X_2] - d[X^0_1; X_1] \leq \tfrac{1}{2} k + \tfrac{1}{4} \bbH[X_2] - \tfrac{1}{4} \bbH[X_1].$$ -/
lemma diff_rdist_le_1 : d[p.X₀₁ # X₁ + X₂'] - d[p.X₀₁ # X₁] ≤ k/2 + H[X₂]/4 - H[X₁]/4 := by
have h : IndepFun X₁ X₂' := by simpa using h_indep.indepFun (show (0:Fin 4) ≠ 2 by decide)
convert condRuzsaDist_diff_le' ℙ p.hmeas1 hX₁ hX₂' h using 4
· exact ProbabilityTheory.IdentDistrib.rdist_eq (IdentDistrib.refl hX₁.aemeasurable) h₂
· exact h₂.entropy_eq
/-- $$ d[X^0_2;X_2+\tilde X_1] - d[X^0_2; X_2] \leq \tfrac{1}{2} k + \tfrac{1}{4} \mathbb{H}[X_1] - \tfrac{1}{4} \mathbb{H}[X_2].$$ -/
lemma diff_rdist_le_2 : d[p.X₀₂ # X₂ + X₁'] - d[p.X₀₂ # X₂] ≤ k/2 + H[X₁]/4 - H[X₂]/4 := by
have h : IndepFun X₂ X₁' := by simpa using h_indep.indepFun (show (1:Fin 4) ≠ 3 by decide)
convert condRuzsaDist_diff_le' ℙ p.hmeas2 hX₂ hX₁' h using 4
· rw [rdist_symm]
exact (IdentDistrib.refl hX₂.aemeasurable).rdist_eq h₁
· exact h₁.entropy_eq
/-- $$ d[X_1^0;X_1|X_1+\tilde X_2] - d[X_1^0;X_1] \leq
\tfrac{1}{2} k + \tfrac{1}{4} \mathbb{H}[X_1] - \tfrac{1}{4} \mathbb{H}[X_2].$$ -/
lemma diff_rdist_le_3 : d[p.X₀₁ # X₁ | X₁ + X₂'] - d[p.X₀₁ # X₁] ≤ k/2 + H[X₁]/4 - H[X₂]/4 := by
have h : IndepFun X₁ X₂' := by simpa using h_indep.indepFun (show (0:Fin 4) ≠ 2 by decide)
convert condRuzsaDist_diff_le''' ℙ p.hmeas1 hX₁ hX₂' h using 3
· rw [(IdentDistrib.refl hX₁.aemeasurable).rdist_eq h₂]
· apply h₂.entropy_eq
/-- $$ d[X_2^0; X_2|X_2+\tilde X_1] - d[X_2^0; X_2] \leq
\tfrac{1}{2}k + \tfrac{1}{4} \mathbb{H}[X_2] - \tfrac{1}{4} \mathbb{H}[X_1].$$ -/
lemma diff_rdist_le_4 : d[p.X₀₂ # X₂ | X₂ + X₁'] - d[p.X₀₂ # X₂] ≤ k/2 + H[X₂]/4 - H[X₁]/4 := by
have h : IndepFun X₂ X₁' := by simpa using h_indep.indepFun (show (1:Fin 4) ≠ 3 by decide)
convert condRuzsaDist_diff_le''' ℙ p.hmeas2 hX₂ hX₁' h using 3
· rw [rdist_symm, (IdentDistrib.refl hX₂.aemeasurable).rdist_eq h₁]
· apply h₁.entropy_eq
/-- We have $I_1 \leq 2 \eta k$ -/
lemma first_estimate : I₁ ≤ 2 * p.η * k := by
have v1 := rdist_add_rdist_add_condMutual_eq X₁ X₂ X₁' X₂' ‹_› ‹_› ‹_› ‹_› ‹_› ‹_› ‹_›
have v2 := rdist_of_sums_ge p X₁ X₂ X₁' X₂' ‹_› ‹_› ‹_› ‹_› ‹_›
have v3 := condRuzsaDist_of_sums_ge p X₁ X₂ X₁' X₂' ‹_› ‹_› ‹_› (by measurability) (by measurability)
have v4 := (mul_le_mul_left p.hη).2 (diff_rdist_le_1 p X₁ X₂ X₁' X₂' ‹_› ‹_› ‹_› ‹_›)
have v5 := (mul_le_mul_left p.hη).2 (diff_rdist_le_2 p X₁ X₂ X₁' X₂' ‹_› ‹_› ‹_› ‹_›)
have v6 := (mul_le_mul_left p.hη).2 (diff_rdist_le_3 p X₁ X₂ X₁' X₂' ‹_› ‹_› ‹_› ‹_›)
have v7 := (mul_le_mul_left p.hη).2 (diff_rdist_le_4 p X₁ X₂ X₁' X₂' ‹_› ‹_› ‹_› ‹_›)
simp only [inv_eq_one_div] at *
linarith [v1, v2, v3, v4, v5, v6, v7]
/--
$$\mathbb{H}[X_1+X_2+\tilde X_1+\tilde X_2] \le \tfrac{1}{2} \mathbb{H}[X_1]+\tfrac{1}{2} \mathbb{H}[X_2] + (2 + \eta) k - I_1.$$
-/
| lemma ent_ofsum_le : H[X₁ + X₂ + X₁' + X₂'] ≤ H[X₁]/2 + H[X₂]/2 + (2+p.η)*k - I₁ | ent_ofsum_le | 59160fb 20231116 | c7fb2a4 20231125 | pfr/PFR/FirstEstimate.lean | {
"lineInFile": 135,
"tokenPositionInFile": 6303,
"theoremPositionInFile": 10
} | {
"inFilePremises": true,
"repositoryPremises": true
} | {
"hasProof": true,
"proof": "by\n let D := d[X₁ + X₂' # X₂ + X₁']\n let Dcc := d[X₁ | X₁ + X₂' # X₂ | X₂ + X₁']\n let D1 := d[p.X₀₁ # X₁]\n let Dc1 := d[p.X₀₁ # X₁ | X₁ + X₂']\n let D2 := d[p.X₀₂ # X₂]\n let Dc2 := d[p.X₀₂ # X₂ | X₂ + X₁']\n have lem68 : D + Dcc + I₁ = 2 * k :=\n rdist_add_rdist_add_condMutual_eq _ _ _ _ hX₁ hX₂ hX₁' hX₂' h₁ h₂ h_indep\n have lem610 : Dcc ≥ k - p.η * (Dc1 - D1) - p.η * (Dc2 - D2) :=\n condRuzsaDist_of_sums_ge p X₁ X₂ X₁' X₂' hX₁ hX₂ (by measurability) (by measurability) h_min\n have lem611c : Dc1 - D1 ≤ k / 2 + H[X₁] / 4 - H[X₂] / 4 :=\n diff_rdist_le_3 p X₁ X₂ X₁' X₂' hX₁ hX₂' h₂ h_indep\n have lem611d : Dc2 - D2 ≤ k / 2 + H[X₂] / 4 - H[X₁] / 4 :=\n diff_rdist_le_4 p X₁ X₂ X₁' X₂' hX₂ hX₁' h₁ h_indep\n have aux : D + I₁ ≤ (1 + p.η) * k := by\n calc D + I₁\n ≤ k + p.η * (Dc1 - D1) + p.η * (Dc2 - D2) := ?_\n _ ≤ k + p.η * (k / 2 + H[X₁] / 4 - H[X₂] / 4) + p.η * (k / 2 + H[X₂] / 4 - H[X₁] / 4) := ?_\n _ = (1 + p.η) * k := by ring\n · convert add_le_add lem68.le (neg_le_neg lem610) using 1 <;> ring\n · refine add_le_add (add_le_add (le_refl _) ?_) ?_\n · apply (mul_le_mul_left p.hη).mpr lem611c\n · apply (mul_le_mul_left p.hη).mpr lem611d\n have ent_sub_eq_ent_add : H[X₁ + X₂' - (X₂ + X₁')] = H[X₁ + X₂' + (X₂ + X₁')] := by simp\n have rw₁ : X₁ + X₂' + (X₂ + X₁') = X₁ + X₂ + X₁' + X₂' := by abel\n have ind_aux : IndepFun (X₁ + X₂') (X₂ + X₁') := by\n exact iIndepFun.indepFun_add_add h_indep (fun i ↦ by fin_cases i <;> assumption) 0 2 1 3\n (by decide) (by decide) (by decide) (by decide)\n have ind : D = H[X₁ + X₂' - (X₂ + X₁')] - H[X₁ + X₂'] / 2 - H[X₂ + X₁'] / 2 :=\n @IndepFun.rdist_eq Ω G _ ℙ _ _ _ (X₁ + X₂') _ (X₂ + X₁') ind_aux (by measurability) (by measurability)\n rw [ind, ent_sub_eq_ent_add, rw₁] at aux\n have obs : H[X₁ + X₂ + X₁' + X₂'] ≤ H[X₁ + X₂'] / 2 + H[X₂ + X₁'] / 2 + (1 + p.η) * k - I₁ := by\n linarith\n have rw₂ : H[X₁ + X₂'] = k + H[X₁]/2 + H[X₂]/2 := by\n have HX₂_eq : H[X₂] = H[X₂'] :=\n congr_arg (fun (μ : Measure G) ↦ measureEntropy (μ := μ)) h₂.map_eq\n have k_eq : k = H[X₁ - X₂'] - H[X₁] / 2 - H[X₂'] / 2 := by\n have k_eq_aux : k = d[X₁ # X₂'] := (IdentDistrib.refl hX₁.aemeasurable).rdist_eq h₂\n rw [k_eq_aux]\n exact (h_indep.indepFun (show (0 : Fin 4) ≠ 2 by decide)).rdist_eq hX₁ hX₂'\n rw [k_eq, ← ElementaryAddCommGroup.sub_eq_add, ← HX₂_eq]\n ring\n have rw₃ : H[X₂ + X₁'] = k + H[X₁]/2 + H[X₂]/2 := by\n have HX₁_eq : H[X₁] = H[X₁'] :=\n congr_arg (fun (μ : Measure G) ↦ measureEntropy (μ := μ)) h₁.map_eq\n have k_eq' : k = H[X₁' - X₂] - H[X₁'] / 2 - H[X₂] / 2 := by\n have k_eq_aux : k = d[X₁' # X₂] :=\n IdentDistrib.rdist_eq h₁ (IdentDistrib.refl hX₂.aemeasurable)\n rw [k_eq_aux]\n exact IndepFun.rdist_eq (h_indep.indepFun (show (3 : Fin 4) ≠ 1 by decide)) hX₁' hX₂\n rw [add_comm X₂ X₁', k_eq', ← ElementaryAddCommGroup.sub_eq_add, ← HX₁_eq]\n ring\n calc H[X₁ + X₂ + X₁' + X₂']\n ≤ H[X₁ + X₂'] / 2 + H[X₂ + X₁'] / 2 + (1 + p.η) * k - I₁ := obs\n _ = (k + H[X₁] / 2 + H[X₂] / 2) / 2\n + (k + H[X₁] / 2 + H[X₂] / 2) / 2 + (1 + p.η) * k - I₁ := by rw [rw₂, rw₃]\n _ = H[X₁] / 2 + H[X₂] / 2 + (2 + p.η) * k - I₁ := by ring",
"proofType": "tactic",
"proofLengthLines": 58,
"proofLengthTokens": 3337
} | pfr |