import Mathlib import OAI.Probability.CriticalPercolation.ProductMeasure.TailProduct namespace OAI section section noncomputable section open Set MeasureTheory ProbabilityTheory open scoped Classical namespace CriticalPercolation.BernoulliProduct variable {E : Type*} lemma law_coordinate (q : E → unitInterval) (e : E) (b : Prop) : law q {ω : Set E | (e ∈ ω) = b} = bitMeasure (q e) {b} := by rw [law_eq_infinitePi] have h := congrArg (fun μ : Measure Prop => μ {b}) (Measure.infinitePi_map_eval (fun e => bitMeasure (q e)) e) rw [Measure.map_apply (measurable_pi_apply e) (MeasurableSet.singleton b)] at h exact h lemma force_singleton_preimage_null (q : E → unitInterval) (e : E) (σ : Set E) (hb : bitMeasure (q e) {e ∈ σ} ≠ 0) (A : Set (Set E)) (hA : MeasurableSet A) (hnull : law q A = 0) : law q (forceOn {e} σ ⁻¹' A) = 0 := by let B := forceOn {e} σ ⁻¹' A let C := {ω : Set E | (e ∈ ω) = (e ∈ σ)} have hmC : MeasurableSet[blockSigma {e}] C := by have hc : MeasurableSet[coordinateSigma e] C := ⟨{e ∈ σ}, MeasurableSet.singleton _, rfl⟩ exact (le_iSup_of_le e (le_iSup_of_le (Set.mem_singleton e) le_rfl) : coordinateSigma e ≤ blockSigma {e}) _ hc have hmB : MeasurableSet[blockSigma ({e} : Set E)ᶜ] B := hA.preimage (measurable_forceOn_block {e} σ) have hmul := ((independent_blocks q {e}).indepSet_of_measurableSet hmC hmB).measure_inter_eq_mul have hsub : C ∩ B ⊆ A := by intro ω hω have heq : forceOn {e} σ ω = ω := by ext f change (if f ∈ ({e} : Set E) then f ∈ σ else f ∈ ω) ↔ f ∈ ω by_cases hf : f = e · subst f simpa only [Set.mem_singleton_iff, ↓reduceIte] using (Iff.of_eq hω.1.symm) · simp only [Set.mem_singleton_iff, ite_eq_right hf] have hh : forceOn {e} σ ω ∈ A := hω.2 rwa [heq] at hh have hz : law q (C ∩ B) = 0 := measure_mono_null hsub hnull rw [hz, law_coordinate] at hmul exact (mul_eq_zero.mp hmul.symm).resolve_left hb lemma bitMeasure_true_ne_zero (p : unitInterval) (hp : (0:ℝ) < p) : bitMeasure p {True} ≠ 0 := by have hh := bitMeasure_real_singleton p True simp only [bitWeight, ite_true] at hh intro hz have : (bitMeasure p).real {True} = 0 := by simp only [measureReal_def,hz,ENNReal.toReal_zero] rw [hh] at this exact (ne_of_gt hp) this lemma insert_preimage_null (q : E → unitInterval) (hq : ∀ e, (0:ℝ) < q e) (e : E) (A : Set (Set E)) (hA : MeasurableSet A) (hnull : law q A = 0) : law q ((fun ω => insert e ω) ⁻¹' A) = 0 := by have hh := force_singleton_preimage_null q e Set.univ (bitMeasure_true_ne_zero (q e) (hq e)) A hA hnull have heq : forceOn {e} Set.univ = (fun ω : Set E => insert e ω) := by funext ω ext f change (if f ∈ ({e} : Set E) then True else f ∈ ω) ↔ (f = e ∨ f ∈ ω) simp only [Set.mem_singleton_iff] split_ifs <;> tauto rwa [heq] at hh lemma measurable_union_left (S : Set E) : Measurable (fun ω : Set E => S ∪ ω) := Measurable.of_eval (fun edge => measurable_const.or (measurable_set_mem edge)) lemma finite_union_preimage_null (q : E → unitInterval) (hq : ∀ e, (0:ℝ) < q e) (S : Set E) (hS : S.Finite) (A : Set (Set E)) (hA : MeasurableSet A) (hnull : law q A = 0) : law q ((fun ω => S ∪ ω) ⁻¹' A) = 0 := by induction S,hS using Set.Finite.induction_on generalizing A with | empty => have hh : (fun ω : Set E => (∅ : Set E) ∪ ω) = id := funext (fun _ => Set.empty_union _) rw [hh,Set.preimage_id_eq] exact hnull | @insert e S he hS ih => have hi := insert_preimage_null q hq e A hA hnull have hm : Measurable (fun ω : Set E => insert e ω) := by simpa only [Set.singleton_union] using measurable_union_left ({e} : Set E) have hh := ih ((fun ω => insert e ω) ⁻¹' A) (hA.preimage hm) hi simpa only [Set.preimage_preimage,Function.comp_def,Set.insert_union] using hh end CriticalPercolation.BernoulliProduct end end end end OAI